summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorAndreas Baumann <abaumann@yahoo.com>2008-12-18 21:10:06 +0100
committerAndreas Baumann <abaumann@yahoo.com>2008-12-18 21:10:06 +0100
commit1781c7f60ce7c369ac6abe28766e45b056b2303c (patch)
tree8e8240ccbeb9efdfea945d58081a45db46e2557e /src
parentf91079ba8a25167d279af0a21fbd50610d267894 (diff)
downloadwolfbones-1781c7f60ce7c369ac6abe28766e45b056b2303c.tar.gz
wolfbones-1781c7f60ce7c369ac6abe28766e45b056b2303c.tar.bz2
robuster logger for files
Diffstat (limited to 'src')
-rw-r--r--src/log.c14
1 files changed, 9 insertions, 5 deletions
diff --git a/src/log.c b/src/log.c
index ad6080f..a004e79 100644
--- a/src/log.c
+++ b/src/log.c
@@ -1,9 +1,10 @@
#include "log.h"
#include "port/stdio.h" /* for vsnprintf */
-#include "port/string.h" /* for strcmp */
+#include "port/string.h" /* for strcmp, strerror_r */
#include <stdarg.h> /* for variable arguments */
+#include <errno.h> /* for errno */
const char *log_syslog_facility_to_str( int facility ) {
switch( facility ) {
@@ -94,12 +95,9 @@ static int syslog_facility;
static int syslog_level;
void openlogtofile( const char *filename, int level ) {
- if( log_file != NULL ) {
- fclose( log_file );
- }
- log_file = fopen( filename, "a" );
log_logfile_filename = filename;
log_logfile_level = level;
+ reopenlogtofile( );
}
void openlogtosyslog( const char *ident, int facility, int level ) {
@@ -134,6 +132,12 @@ void reopenlogtofile( void ) {
fclose( log_file );
}
log_file = fopen( log_logfile_filename, "a" );
+ if( log_file == NULL ) {
+ char errmsg[255];
+ strerror_r( errno, errmsg, 255 );
+ fprintf( stderr, "ERR: Unable to logfile '%s': %s\n",
+ log_logfile_filename, errmsg );
+ }
}
void reopenlogtosyslog( void ) {