Dumb-ways-to-memorize
2D game
Main Page
Related Pages
Data Structures
Files
File List
Globals
dumb-ways-to-memorize
External_Libs
simple_logger.c
Go to the documentation of this file.
1
#include "
simple_logger.h
"
2
#include <stdarg.h>
3
#include <stdio.h>
4
#include <stdlib.h>
5
6
FILE *
__log_file
= NULL;
7
8
void
close_logger
()
9
{
10
if
(
__log_file
!= NULL)
11
{
12
fclose(
__log_file
);
13
__log_file
= NULL;
14
}
15
}
16
17
void
init_logger
(
const
char
*log_file_path)
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
}
29
30
void
_slog
(
char
*f,
int
l,
char
*msg,...)
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
}
49
50
51
/*eol@eof*/
close_logger
void close_logger()
Definition:
simple_logger.c:8
simple_logger.h
init_logger
void init_logger(const char *log_file_path)
initializes the simple logger. Will automatically cleanup at program exit.
Definition:
simple_logger.c:17
__log_file
FILE * __log_file
Definition:
simple_logger.c:6
_slog
void _slog(char *f, int l, char *msg,...)
Definition:
simple_logger.c:30
Generated by
1.8.11