ulogger
athreadsafeloggerwithcoloredoutput
|
a thread safe logger with optional printf style logging More...
#include "logger.h"
#include <fcntl.h>
#include <pthread.h>
#include <stdarg.h>
#include <stdbool.h>
#include <stdio.h>
#include <stdlib.h>
#include <sys/stat.h>
#include <sys/types.h>
#include <unistd.h>
Go to the source code of this file.
Functions | |
thread_logger * | new_thread_logger (bool with_debug) |
returns a new thread safe logger if with_debug is false, then all debug_log calls will be ignored More... | |
file_logger * | new_file_logger (char *output_file, bool with_debug) |
returns a new file_logger Calls new_thread_logger internally More... | |
int | write_file_log (int file_descriptor, char *message) |
used to write a log message to file although this really means a file descriptor More... | |
void | logf_func (thread_logger *thl, int file_descriptor, LOG_LEVELS level, char *file, int line, char *message,...) |
like log_func but for formatted logs More... | |
void | log_func (thread_logger *thl, int file_descriptor, char *message, LOG_LEVELS level, char *file, int line) |
main function you should call, which will delegate to the appopriate *_log function More... | |
void | info_log (thread_logger *thl, int file_descriptor, char *message) |
logs an info styled message - called by log_fn More... | |
void | warn_log (thread_logger *thl, int file_descriptor, char *message) |
logs a warned styled message - called by log_fn More... | |
void | error_log (thread_logger *thl, int file_descriptor, char *message) |
logs an error styled message - called by log_fn More... | |
void | debug_log (thread_logger *thl, int file_descriptor, char *message) |
logs a debug styled message - called by log_fn More... | |
void | clear_thread_logger (thread_logger *thl) |
free resources for the threaded logger More... | |
void | clear_file_logger (file_logger *fhl) |
free resources for the file ogger More... | |
void | get_time_string (char *date_buffer, size_t date_buffer_len) |
returns a timestamp of format Jul 06 10:12:20 PM More... | |
a thread safe logger with optional printf style logging
allows writing color coded logs to stdout, with optional file output as well. timestamps all logs, and provides optional printf style logging
ss
format:Definition in file logger.c.
void clear_file_logger | ( | file_logger * | fhl | ) |
free resources for the file ogger
fhl | the file_logger instance to free memory for. also frees memory for the embedded thread_logger and closes the open file |
Definition at line 333 of file logger.c.
void clear_thread_logger | ( | thread_logger * | thl | ) |
free resources for the threaded logger
thl | the thread_logger instance to free memory for |
Definition at line 322 of file logger.c.
void debug_log | ( | thread_logger * | thl, |
int | file_descriptor, | ||
char * | message | ||
) |
logs a debug styled message - called by log_fn
thl | pointer to an instance of thread_logger |
file_descriptor | file descriptor to write log messages to in addition to stdout logging. if 0 only stdout is used |
message | the actuall message to log |
Definition at line 294 of file logger.c.
void error_log | ( | thread_logger * | thl, |
int | file_descriptor, | ||
char * | message | ||
) |
logs an error styled message - called by log_fn
thl | pointer to an instance of thread_logger |
file_descriptor | file descriptor to write log messages to in addition to stdout logging. if 0 only stdout is used |
message | the actuall message to log |
Definition at line 267 of file logger.c.
void get_time_string | ( | char * | date_buffer, |
size_t | date_buffer_len | ||
) |
returns a timestamp of format Jul 06 10:12:20 PM
date_buffer | the buffer to write the timestamp into |
date_buffer_len | the size of the buffer |
Definition at line 346 of file logger.c.
void info_log | ( | thread_logger * | thl, |
int | file_descriptor, | ||
char * | message | ||
) |
logs an info styled message - called by log_fn
thl | pointer to an instance of thread_logger |
file_descriptor | file descriptor to write log messages to in addition to stdout logging. if 0 only stdout is used |
message | the actuall message to log |
Definition at line 213 of file logger.c.
void log_func | ( | thread_logger * | thl, |
int | file_descriptor, | ||
char * | message, | ||
LOG_LEVELS | level, | ||
char * | file, | ||
int | line | ||
) |
main function you should call, which will delegate to the appopriate *_log function
thl | pointer to an instance of thread_logger |
file_descriptor | file descriptor to write log messages to, if 0 then only stdout is used |
message | the actual message we want to log |
level | the log level to use (effects color used) |
Definition at line 168 of file logger.c.
void logf_func | ( | thread_logger * | thl, |
int | file_descriptor, | ||
LOG_LEVELS | level, | ||
char * | file, | ||
int | line, | ||
char * | message, | ||
... | |||
) |
like log_func but for formatted logs
thl | pointer to an instance of thread_logger |
file_descriptor | file descriptor to write log messages to, if 0 then only stdout is used |
level | the log level to use (effects color used) |
message | format string like <percent-sign>sFOO<percent-sign>sBAR |
... | values to supply to message |
Definition at line 142 of file logger.c.
file_logger* new_file_logger | ( | char * | output_file, |
bool | with_debug | ||
) |
returns a new file_logger Calls new_thread_logger internally
output_file | the file we will dump logs to. created if not exists and is appended to |
Definition at line 70 of file logger.c.
thread_logger* new_thread_logger | ( | bool | with_debug | ) |
returns a new thread safe logger if with_debug is false, then all debug_log calls will be ignored
with_debug | whether to enable debug logging, if false debug log calls will be ignored |
Definition at line 47 of file logger.c.
void warn_log | ( | thread_logger * | thl, |
int | file_descriptor, | ||
char * | message | ||
) |
logs a warned styled message - called by log_fn
thl | pointer to an instance of thread_logger |
file_descriptor | file descriptor to write log messages to in addition to stdout logging. if 0 only stdout is used |
message | the actuall message to log |
Definition at line 240 of file logger.c.
int write_file_log | ( | int | file_descriptor, |
char * | message | ||
) |
used to write a log message to file although this really means a file descriptor
thl | pointer to an instance of thread_logger |
file_descriptor | file descriptor to write log messages to in addition to stdout logging. if 0 only stdout is used |
message | the actuall message to log |
Definition at line 112 of file logger.c.