39 #ifdef HAVE_SYS_TIME_H
52 static char *timestamp_str(
char *buf,
const size_t len)
62 if((tm = localtime(&t)) == NULL)
return buf;
64 ms = tv.tv_usec / 1000;
65 snprintf(buf, len,
"[%02d:%02d:%02d:%03d] ",
66 tm->tm_hour, tm->tm_min, tm->tm_sec, ms);
71 void generic_log(
const char *func,
corsaro_file_t *logfile,
const char *format,
78 assert(format != NULL);
80 vsnprintf(message,
sizeof(message), format, ap);
82 timestamp_str(ts,
sizeof(ts));
84 if(func != NULL) snprintf(fs,
sizeof(fs),
"%s: ", func);
89 fprintf(stderr,
"%s%s%s\n", ts, fs, message);
100 fprintf(stderr,
"%s%s%s\n", ts, fs, message);
107 const char *format, va_list args)
110 generic_log(func, lf, format, args);
116 va_start(ap, format);
122 const char *format, ...)
126 va_start(ap, format);
127 generic_log(func, NULL, format, ap);
133 const char *format, ...)
136 va_start(ap, format);
137 generic_log(func, logfile, format, ap);
148 0, O_CREAT)) == NULL)
150 fprintf(stderr,
"could not open log for writing\n");
Header file dealing with the corsaro logging sub-system.
An opaque structure defining an corsaro output file.
off_t corsaro_file_printf(struct corsaro *corsaro, corsaro_file_t *file, const char *format,...)
Print a string to an corsaro file.
void corsaro_log_va(const char *func, corsaro_t *corsaro, const char *format, va_list args)
Write a formatted string to the logfile associated with an corsaro object.
corsaro_file_t * corsaro_io_prepare_file_full(corsaro_t *corsaro, const char *plugin_name, corsaro_interval_t *interval, corsaro_file_mode_t mode, corsaro_file_compress_t compress, int compress_level, int flags)
Uses the given settings to open an corsaro file for the given plugin.
void corsaro_file_close(struct corsaro *corsaro, corsaro_file_t *file)
Closes an corsaro output file and frees the writer structure.
Header file for common utility functions.
#define CORSARO_IO_LOG_NAME
The name to use for the log 'plugin' file.
void corsaro_log_close(corsaro_t *corsaro)
Close the log file for an corsaro output object.
void corsaro_file_flush(struct corsaro *corsaro, corsaro_file_t *file)
Force all buffered data for the file to be written out.
Header file dealing with the low-level file IO.
void corsaro_log_in(const char *func, corsaro_in_t *corsaro, const char *format,...)
Write a formatted string to the logfile associated with an corsaro input object.
int corsaro_log_init(corsaro_t *corsaro)
Initialize the logging sub-system for an corsaro output object.
corsaro_interval_t interval_start
State for the current interval.
void corsaro_log_in_close(corsaro_in_t *corsaro)
Close the log file for an corsaro input object.
void corsaro_log_file(const char *func, corsaro_file_t *logfile, const char *format,...)
Write a formatted string to a generic log file.
Header file dealing with the corsaro file IO.
corsaro_file_t * logfile
The file to write log output to.
void gettimeofday_wrap(struct timeval *tv)
Convenience function to get the current time of day.
int corsaro_log_in_init(corsaro_in_t *corsaro)
Initialize the logging sub-system for an corsaro input object.
void corsaro_log(const char *func, corsaro_t *corsaro, const char *format,...)
Write a formatted string to the logfile associated with an corsaro object.
Header file dealing with the internal corsaro functions.