Mit syslog in log Datei schreiben.

knooby

unregistriert
Thread Starter
Dabei seit
07.12.2004
Beiträge
842
Reaktionspunkte
10
Hi ich würde gerne unter Leopard in mit hilfe von syslog in eine log datei schreiben aber leider klappt das nicht so ganz. Vielleicht hab ich ja einen entscheidenen fehler gemacht.

Hier mein quellcode

Code:
#include <iostream>
#include <syslog.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include "socket.h" 


int daemonisieren() {
    pid_t   pid;
    
    if ( (pid = fork()) < 0)
        return -1;
    else if (pid != 0)
        exit (0); /* Elternprozess beendet sich */
    
    /* Ab hier wird nur vom Kindprozess ausgeführt */
    setsid();       /* Kind wird Sessionführer */
    
    chdir("/");     /* Ins Root Directory wechseln */
    
    umask(0);       /* Dateikreierungsmaske loeschen */
    
    return 0;
}

int main() {
           openlog("main.ccp", LOG_CONS,LOG_LOCAL3);
	    if (daemonisieren() != 0) {
	syslog(LOG_DEBUG,"Fehler: Daemonisierung nicht moeglich.");    }
        
    syslog(LOG_DEBUG,"Start des Daemons: Webserver auf Port 4711");	
	  WebServer *server = new WebServer(4711); 
server->Loop(); 
    closelog();
  
    return 1;
}
 
syslog schreibt meistens nur in die system.log
es sei denn du definierst für den syslogd extra ein file für deine app...
openlog ist nicht dafür da ein file anzugeben, wo syslog() dann reinschreibt...

The openlog() function provides for more specialized processing of the messages sent by syslog() and vsyslog(). The parameter ident is a string that will be prepended to every message. The logopt argument is a bit field specifying logging options, which is formed by OR’ing one or more of the following values:
 
Zuletzt bearbeitet:
Ja habs schon mit LOG_INFO probiert. Aber kommt auch nix. Könnte natürlich sein
Code:
syslog(LOG_DEBUG,"Fehler: Daemonisierung nicht moeglich.");    }
nicht geht. Hab den befehl so auf ner linux seite gefunden. Vielleicht ist der syntax bei mac os anders...
 
Für Leopard solltest Du asl(3) benutzen. NEIN, VERDAMMT, das heisst nicht "Age/Sex/Location" :motz:

DESCRIPTION
These routines provide an interface to the Apple system log facility.
They are intended to be a replacement for the syslog(3) API, which will
continue to be supported for backwards compatibility.

Alex
 
asl_log(NULL, NULL, ASL_LEVEL_NOTICE, "Daemon erfolgreich gestartet");

Danke hier mit ging es ganz einfach.
 
Zurück
Oben Unten