Dumb-ways-to-memorize
2D game
Functions | Variables
simple_logger.c File Reference
#include "simple_logger.h"
#include <stdarg.h>
#include <stdio.h>
#include <stdlib.h>
+ Include dependency graph for simple_logger.c:

Go to the source code of this file.

Functions

void close_logger ()
 
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,...)
 

Variables

FILE * __log_file = NULL
 

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 close_logger ( )

Definition at line 8 of file simple_logger.c.

References __log_file.

Referenced by init_logger().

9 {
10  if (__log_file != NULL)
11  {
12  fclose(__log_file);
13  __log_file = NULL;
14  }
15 }
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

Variable Documentation

FILE* __log_file = NULL

Definition at line 6 of file simple_logger.c.

Referenced by _slog(), close_logger(), and init_logger().