Hello.
My context was that the facilities was to be used on your local developer/test machine, not spreading out to users, I do understand the necessity of sending crash reports, when programs urge you to, since this is a very complex world, and the action of sending in logfiles, makes the stuff I use better.
It was also about using the tools you have available, when there is a point in using them. The account facility for instance, though awkward to use, because of how the metrics are gathered, are still usable, if you are making something that are running all the time.
Well, It suddenly struck me, that I could just do like below, and forget all about the logfile, with routines that opens a logfile, “the usual place”, no need for filehandle 3 nor syslog.
You are supposed to make your own header file, write formatted strings with fprintf, using this handle,
and close the file when it is necessary. The file is opened for appending text to it.
[code]/***********************************************************************
Name: logerror_file.c
Created: 04-25-2013
Author: McUsr with thanks to DJ Bazzie Wazzie.
Usage:
Return a FILE *handle to a logfile residing in ~/Library/Logs.
The log file should end with a .log suffix. So that it will
be opened in Console.app. Mac Os X.
NB! You have to flush, and use write to write unbuffered
in connection with signals.
DISCLAIMER
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
***********************************************************************/
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
FILE *lfile = NULL ;
static char logfname[FILENAME_MAX] ;
FILE *init_logfile(const char *logfname) ;
FILE *reopen_logfile(void) ;
int main( int argc, char *argv[] )
{
lfile=init_logfile(“logwritertester.log”) ;
if (lfile != NULL ) {
printf(“success\n”) ;
}
return 0;
}
FILE *reopen_logfile(void) {
if ( logfname[0] == '\0' ) {
fprintf(stderr,"%s: Missing logfilename\n",__PRETTY_FUNCTION__);
exit(2);
}
if ((lfile=fopen(logfname,"a") )!= NULL ) {
return lfile ;
} else
perror("reopen_logfile: Couldn't reopen logfile: ");
return lfile ;
}
FILE *init_logfile(const char *logname)
{
strcat(logfname,“/Users/”) ;
strcat(logfname,getlogin()) ;
strcat(logfname,“/Library/Logs/”) ;
strcat(logfname,logname) ;
if ((lfile=fopen(logfname,"a") )!= NULL ) {
return lfile ;
} else {
perror("init_logfile: Couldn't open logfile: ");
}
return NULL ;
}[/code]