Initial commit
[fillmore] / src / marina / Logging.vala
1 /* Copyright 2009 Yorba Foundation
2  *
3  * This software is licensed under the GNU Lesser General Public License
4  * (version 2.1 or later).  See the COPYING file in this distribution. 
5  */
6 namespace Logging {
7
8 public enum Facility {
9     SIGNAL_HANDLERS,
10     DEVELOPER_WARNINGS,
11     GRAPH,
12     LOADING,
13     IMPORT,
14     SINGLEDECODEBIN
15 }
16
17 public enum Level {
18     CRITICAL,
19     HIGH,
20     MEDIUM,
21     LOW,
22     INFO,
23     VERBOSE
24 }
25
26 const Level active_facility[] = {
27     Level.CRITICAL, // SIGNAL_HANDLERS
28     Level.CRITICAL, // DEVELOPER_WARNINGS
29     Level.CRITICAL, // GRAPH
30     Level.CRITICAL, //LOADING
31     Level.CRITICAL, //IMPORT
32     Level.CRITICAL  //SINGLEDECODEBIN
33 };
34
35 const string facility_names[] = {
36     "SIGNAL_HANDLERS",
37     "DEVELOPER_WARNINGS",
38     "GRAPH",
39     "LOADING",
40     "IMPORT",
41     "SINGLEDECODEBIN"
42 };
43
44 Level current_level = Level.HIGH;
45
46 public void set_logging_level(Level new_level) {
47     if (new_level <= Level.VERBOSE && new_level >= Level.CRITICAL) {
48         current_level = new_level;
49     }
50 }
51
52 public void emit(Object object, Facility facility, Level level, string message) {
53     if (level <= current_level || level <= active_facility[facility]) {
54         stderr.printf("%s(%s): %s\n", object.get_type().name(), facility_names[facility], message);
55     }
56 }
57 }