15 // ----------------------------------------------------------------------------
18 const char *program_name = "";
19 unsigned long long debug_flags = DEBUG;
24 FILE *stdaccess = NULL;
26 int access_log_syslog = 1;
27 int error_log_syslog = 1;
28 int output_log_syslog = 1; // debug log
31 void log_date(FILE *out)
35 struct tm *tmp, tmbuf;
38 tmp = localtime_r(&t, &tmbuf);
40 if (tmp == NULL) return;
41 if (strftime(outstr, sizeof(outstr), "%y-%m-%d %H:%M:%S", tmp) == 0) return;
43 fprintf(out, "%s: ", outstr);
46 void debug_int( const char *file, const char *function, const unsigned long line, const char *fmt, ... )
51 va_start( args, fmt );
52 fprintf(stdout, "DEBUG (%04lu@%-10.10s:%-15.15s): %s: ", line, file, function, program_name);
53 vfprintf( stdout, fmt, args );
55 fprintf(stdout, "\n");
57 if(output_log_syslog) {
58 va_start( args, fmt );
59 vsyslog(LOG_ERR, fmt, args );
64 void info_int( const char *file, const char *function, const unsigned long line, const char *fmt, ... )
70 va_start( args, fmt );
71 if(debug_flags) fprintf(stderr, "INFO (%04lu@%-10.10s:%-15.15s): %s: ", line, file, function, program_name);
72 else fprintf(stderr, "INFO: %s: ", program_name);
73 vfprintf( stderr, fmt, args );
76 fprintf(stderr, "\n");
78 if(error_log_syslog) {
79 va_start( args, fmt );
80 vsyslog(LOG_INFO, fmt, args );
85 void error_int( const char *prefix, const char *file, const char *function, const unsigned long line, const char *fmt, ... )
91 va_start( args, fmt );
92 if(debug_flags) fprintf(stderr, "%s (%04lu@%-10.10s:%-15.15s): %s: ", prefix, line, file, function, program_name);
93 else fprintf(stderr, "%s: %s: ", prefix, program_name);
94 vfprintf( stderr, fmt, args );
99 char *s = strerror_r(errno, buf, 200);
100 fprintf(stderr, " (errno %d, %s)\n", errno, s);
103 else fprintf(stderr, "\n");
105 if(error_log_syslog) {
106 va_start( args, fmt );
107 vsyslog(LOG_ERR, fmt, args );
112 void fatal_int( const char *file, const char *function, const unsigned long line, const char *fmt, ... )
118 va_start( args, fmt );
119 if(debug_flags) fprintf(stderr, "FATAL (%04lu@%-10.10s:%-15.15s): %s: ", line, file, function, program_name);
120 else fprintf(stderr, "FATAL: %s: ", program_name);
121 vfprintf( stderr, fmt, args );
125 fprintf(stderr, "\n");
127 if(error_log_syslog) {
128 va_start( args, fmt );
129 vsyslog(LOG_CRIT, fmt, args );
136 void log_access( const char *fmt, ... )
143 va_start( args, fmt );
144 vfprintf( stdaccess, fmt, args );
146 fprintf( stdaccess, "\n");
147 #ifdef NETDATA_INTERNAL_CHECKS
152 if(access_log_syslog) {
153 va_start( args, fmt );
154 vsyslog(LOG_INFO, fmt, args );