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
43
44
45
46
47
48
49
50
51
52
|
using Posix;
/*
* Public Domain.
*/
namespace Vee {
/**
* This is a cheap logger, do not use for production code,
* it is only for targets where GLib is not available.
*
* Use GLib's logging capabilities instead.
*/
public class Logger {
private const string STR_ERROR = "[ERROR]: ";
private const string STR_INFO = "[INFO]: ";
private unowned FILE out_file;
private static Logger logger = null;
public Logger (FILE out_file) {
this.out_file = out_file;
}
public static Logger get_default () {
if (logger == null) {
Logger.logger = new Logger (Posix.stdout);
}
return logger;
}
public static void set_default (Logger logger) {
Logger.logger = logger;
}
public void error (string str, ...) {
out_file.printf (STR_ERROR);
out_file.printf (str, va_list());
}
public void info (string str, ...) {
out_file.printf (STR_INFO);
out_file.printf (str, va_list());
}
public static void free_default () {
Posix.free(Logger.logger);
}
}
}
|