blob: 5ee5bd4beaaf841ce662090e9c208c02fe89fb19 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
|
/**
* General purpose logger class.
*
* Copyright (C) 2013 Tobias Klauser <tklauser@distanz.ch>
*
* This file is subject to the terms and conditions of the GNU General
* Public License, version 2.
*/
#ifndef LOGGER_H_
#define LOGGER_H_
#include <stdarg.h>
#include <stdio.h>
/* TODO: Make singleton */
class Logger {
public:
static Logger& getInstance()
{
// instantiated on first use, guaranteed to be destroyed
static Logger instance;
return instance;
}
int log(const char *fmt, ...);
int err(const char *fmt, ...);
private:
Logger() : _f_out(stdout), _f_err(stderr) { }
~Logger() { }
// Declare copy constructer to prevent the compiler from generating one
Logger(Logger const&);
void operator=(Logger const&);
FILE *_f_out, *_f_err;
static const char *_LOGGER_DATE_FMT;
int _log_vfprintf(FILE *f, const char *prefix, const char *fmt, va_list ap);
};
#endif /* LOGGER_H_ */
|