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
30 void log_date(FILE *out)
34 struct tm *tmp, tmbuf;
37 tmp = localtime_r(&t, &tmbuf);
39 if (tmp == NULL) return;
40 if (strftime(outstr, sizeof(outstr), "%y-%m-%d %H:%M:%S", tmp) == 0) return;
42 fprintf(out, "%s: ", outstr);
45 void debug_int( const char *file, const char *function, const unsigned long line, const char *fmt, ... )
50 va_start( args, fmt );
51 fprintf(stdout, "DEBUG (%04lu@%-10.10s:%-15.15s): %s: ", line, file, function, program_name);
52 vfprintf( stdout, fmt, args );
54 fprintf(stdout, "\n");
56 if(output_log_syslog) {
57 va_start( args, fmt );
58 vsyslog(LOG_ERR, fmt, args );
63 void info_int( const char *file, const char *function, const unsigned long line, const char *fmt, ... )
69 va_start( args, fmt );
70 if(debug_flags) fprintf(stderr, "INFO (%04lu@%-10.10s:%-15.15s): %s: ", line, file, function, program_name);
71 else fprintf(stderr, "INFO: %s: ", program_name);
72 vfprintf( stderr, fmt, args );
75 fprintf(stderr, "\n");
77 if(error_log_syslog) {
78 va_start( args, fmt );
79 vsyslog(LOG_INFO, fmt, args );
84 void error_int( const char *prefix, const char *file, const char *function, const unsigned long line, const char *fmt, ... )
90 va_start( args, fmt );
91 if(debug_flags) fprintf(stderr, "%s (%04lu@%-10.10s:%-15.15s): %s: ", prefix, line, file, function, program_name);
92 else fprintf(stderr, "%s: %s: ", prefix, program_name);
93 vfprintf( stderr, fmt, args );
98 char *s = strerror_r(errno, buf, 200);
99 fprintf(stderr, " (errno %d, %s)\n", errno, s);
102 else fprintf(stderr, "\n");
104 if(error_log_syslog) {
105 va_start( args, fmt );
106 vsyslog(LOG_ERR, fmt, args );
111 void fatal_int( const char *file, const char *function, const unsigned long line, const char *fmt, ... )
117 va_start( args, fmt );
118 if(debug_flags) fprintf(stderr, "FATAL (%04lu@%-10.10s:%-15.15s): %s: ", line, file, function, program_name);
119 else fprintf(stderr, "FATAL: %s: ", program_name);
120 vfprintf( stderr, fmt, args );
124 fprintf(stderr, "\n");
126 if(error_log_syslog) {
127 va_start( args, fmt );
128 vsyslog(LOG_CRIT, fmt, args );
135 void log_access( const char *fmt, ... )
142 va_start( args, fmt );
143 vfprintf( stdaccess, fmt, args );
145 fprintf( stdaccess, "\n");
146 #ifdef NETDATA_INTERNAL_CHECKS
151 if(access_log_syslog) {
152 va_start( args, fmt );
153 vsyslog(LOG_INFO, fmt, args );