Dumb-ways-to-memorize
2D game
Macros | Functions
simple_logger.h File Reference
+ This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Macros

#define slog(...)   _slog(__FILE__,__LINE__,__VA_ARGS__)
 logs a message to stdout and to the configured log file More...
 

Functions

void init_logger (const char *log_file_path)
 initializes the simple logger. Will automatically cleanup at program exit. More...
 
void _slog (char *f, int l, char *msg,...)
 

Macro Definition Documentation

#define slog (   ...)    _slog(__FILE__,__LINE__,__VA_ARGS__)

logs a message to stdout and to the configured log file

Parameters
msga string with tokens
...variables to be put into the tokens.

Definition at line 36 of file simple_logger.h.

Function Documentation

void _slog ( char *  f,
int  l,
char *  msg,
  ... 
)

Definition at line 30 of file simple_logger.c.

References __log_file.

31 {
32  va_list ap;
33  /*echo all logging to stdout*/
34  va_start(ap,msg);
35  fprintf(stdout,"%s:%i: ",f,l);
36  vfprintf(stdout,msg,ap);
37  fprintf(stdout,"\n");
38  va_end(ap);
39  fprintf(stdout,"\n");
40  if (__log_file != NULL)
41  {
42  va_start(ap,msg);
43  fprintf(__log_file,"%s:%i: ",f,l);
44  vfprintf(__log_file,msg,ap);
45  fprintf(__log_file,"\n");
46  va_end(ap);
47  }
48 }
FILE * __log_file
Definition: simple_logger.c:6
void init_logger ( const char *  log_file_path)

initializes the simple logger. Will automatically cleanup at program exit.

simple_logger The MIT License (MIT)

Parameters
log_file_paththe file to log to

Definition at line 17 of file simple_logger.c.

References __log_file, and close_logger().

18 {
19  if (log_file_path == NULL)
20  {
21  __log_file = fopen("output.log","a");
22  }
23  else
24  {
25  __log_file = fopen(log_file_path,"a");
26  }
27  atexit(close_logger);
28 }
void close_logger()
Definition: simple_logger.c:8
FILE * __log_file
Definition: simple_logger.c:6