2011-12-13 23 views
6
#include<syslog.h> 
syslog(LOG_INFO, "Start logging"); 

El comando syslog anterior no está iniciando sesión en el registro del sistema. Así que he intentado,comando syslog en el código C

openlog("Logs", "", LOG_USER); 
syslog(LOG_INFO, "Start logging"); 
closelog(); 

Esto no puede registrar cualquier cosa y me sale el siguiente error:

syslog: unknown facility/priority: 8049584 
+1

consulte http://www.linuxselfhelp.com/gnu/glibc/html_chapter/libc_18.html –

Respuesta

7

realmente se debe compilar con todas las advertencias habilitados y depuración, es decir gcc -Wall -g.

Lea nuevamente el openlog man page. Se declara como:

void openlog(const char *ident, int option, int facility); 

por lo que pasa "" como el segundo argumento es erróneo (y el compilador hizo advertirle sobre eso). Debe ser, p. LOG_PERROR|LOG_PID o algunas otras banderas.

14

Esta línea está mal:

openlog("vyatta-conntrack", "", LOG_USER); 

El "" debería han sido un número entero:

void openlog(const char *ident, int option, int facility); 

El número entero debería ser cualquiera de estas constantes ORED juntos:

LOG_CONS  Write directly to system console if there is 
        an error while sending to system logger. 

    LOG_NDELAY  Open the connection immediately (normally, the 
        connection is opened when the first message is 
        logged). 

    LOG_NOWAIT  Don't wait for child processes that may have 
        been created while logging the message. (The 
        GNU C library does not create a child process, 
        so this option has no effect on Linux.) 

    LOG_ODELAY  The converse of LOG_NDELAY; opening of the 
        connection is delayed until syslog() is 
        called. (This is the default, and need not be 
        specified.) 

    LOG_PERROR  (Not in POSIX.1-2001.) Print to stderr as 
        well. 

    LOG_PID  Include PID with each message. 

Inténtalo de nuevo con algo más como:

openlog("vyatta-conntrack", LOG_PID, LOG_USER); 

Tenga en cuenta que la configuración de syslogd podría no estar configurado para mantener los mensajes de nivel de registro LOG_INFO. Pruebe LOG_ALERT o algo para depurar este problema; si funciona, vuelva al LOG_INFO y configure su syslogd para mantener los mensajes de registro que desea conservar. Añadiendo una línea como:

*.* /var/log/all_messages.log 

hará el trabajo para rsyslogd(8). Asegúrese de leer la página del manual rsyslog.conf(5) si su sistema usa rsyslogd(8). Si su sistema utiliza un daemon syslog diferente, consulte las páginas de manual de su sistema para obtener más detalles.

Cuestiones relacionadas