core/loggingmanager.lua

Sun, 27 Sep 2009 12:10:50 +0100

author
Matthew Wild <mwild1@gmail.com>
date
Sun, 27 Sep 2009 12:10:50 +0100
changeset 1832
5ae3209fefa2
parent 1613
ebf0813a81f6
child 1892
adc0c80413ee
permissions
-rw-r--r--

Merge with waqas

1522
569d58d21612 Add copyright header to those files missing one
Matthew Wild <mwild1@gmail.com>
parents: 1344
diff changeset
1 -- Prosody IM
569d58d21612 Add copyright header to those files missing one
Matthew Wild <mwild1@gmail.com>
parents: 1344
diff changeset
2 -- Copyright (C) 2008-2009 Matthew Wild
569d58d21612 Add copyright header to those files missing one
Matthew Wild <mwild1@gmail.com>
parents: 1344
diff changeset
3 -- Copyright (C) 2008-2009 Waqas Hussain
569d58d21612 Add copyright header to those files missing one
Matthew Wild <mwild1@gmail.com>
parents: 1344
diff changeset
4 --
569d58d21612 Add copyright header to those files missing one
Matthew Wild <mwild1@gmail.com>
parents: 1344
diff changeset
5 -- This project is MIT/X11 licensed. Please see the
569d58d21612 Add copyright header to those files missing one
Matthew Wild <mwild1@gmail.com>
parents: 1344
diff changeset
6 -- COPYING file in the source package for more information.
569d58d21612 Add copyright header to those files missing one
Matthew Wild <mwild1@gmail.com>
parents: 1344
diff changeset
7 --
569d58d21612 Add copyright header to those files missing one
Matthew Wild <mwild1@gmail.com>
parents: 1344
diff changeset
8
1016
73afe3e30e97 core.loggingmanager: A new manager (yay!) to manage log output
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
9
73afe3e30e97 core.loggingmanager: A new manager (yay!) to manage log output
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
10 local format, rep = string.format, string.rep;
73afe3e30e97 core.loggingmanager: A new manager (yay!) to manage log output
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
11 local pcall = pcall;
73afe3e30e97 core.loggingmanager: A new manager (yay!) to manage log output
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
12 local debug = debug;
1031
ec013f93de81 core.loggingmanager: Refactoring, converted to a module. Now possible to register additional sink types (think syslog) from other modules
Matthew Wild <mwild1@gmail.com>
parents: 1024
diff changeset
13 local tostring, setmetatable, rawset, pairs, ipairs, type =
ec013f93de81 core.loggingmanager: Refactoring, converted to a module. Now possible to register additional sink types (think syslog) from other modules
Matthew Wild <mwild1@gmail.com>
parents: 1024
diff changeset
14 tostring, setmetatable, rawset, pairs, ipairs, type;
ec013f93de81 core.loggingmanager: Refactoring, converted to a module. Now possible to register additional sink types (think syslog) from other modules
Matthew Wild <mwild1@gmail.com>
parents: 1024
diff changeset
15 local io_open, io_write = io.open, io.write;
ec013f93de81 core.loggingmanager: Refactoring, converted to a module. Now possible to register additional sink types (think syslog) from other modules
Matthew Wild <mwild1@gmail.com>
parents: 1024
diff changeset
16 local math_max, rep = math.max, string.rep;
1078
24c9ee99d900 loggingmanager: Support prepending timestamps in file/console/stdout log sinks
Matthew Wild <mwild1@gmail.com>
parents: 1067
diff changeset
17 local os_date, os_getenv = os.date, os.getenv;
1031
ec013f93de81 core.loggingmanager: Refactoring, converted to a module. Now possible to register additional sink types (think syslog) from other modules
Matthew Wild <mwild1@gmail.com>
parents: 1024
diff changeset
18 local getstyle, getstring = require "util.termcolours".getstyle, require "util.termcolours".getstring;
ec013f93de81 core.loggingmanager: Refactoring, converted to a module. Now possible to register additional sink types (think syslog) from other modules
Matthew Wild <mwild1@gmail.com>
parents: 1024
diff changeset
19
ec013f93de81 core.loggingmanager: Refactoring, converted to a module. Now possible to register additional sink types (think syslog) from other modules
Matthew Wild <mwild1@gmail.com>
parents: 1024
diff changeset
20 local config = require "core.configmanager";
1117
360ec48ea780 loggingmanager: File log sinks react to reopen-log-files event
Matthew Wild <mwild1@gmail.com>
parents: 1101
diff changeset
21 local eventmanager = require "core.eventmanager";
1016
73afe3e30e97 core.loggingmanager: A new manager (yay!) to manage log output
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
22 local logger = require "util.logger";
1343
a0bee511d144 loggingmanager: Enable debug level for default file logging when 'debug' mode is enabled in the config
Matthew Wild <mwild1@gmail.com>
parents: 1117
diff changeset
23 local debug_mode = config.get("*", "core", "debug");
1016
73afe3e30e97 core.loggingmanager: A new manager (yay!) to manage log output
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
24
1046
6fef969ff307 core.loggingmanager: Reinstating global log() function
Matthew Wild <mwild1@gmail.com>
parents: 1031
diff changeset
25 _G.log = logger.init("general");
6fef969ff307 core.loggingmanager: Reinstating global log() function
Matthew Wild <mwild1@gmail.com>
parents: 1031
diff changeset
26
1031
ec013f93de81 core.loggingmanager: Refactoring, converted to a module. Now possible to register additional sink types (think syslog) from other modules
Matthew Wild <mwild1@gmail.com>
parents: 1024
diff changeset
27 module "loggingmanager"
ec013f93de81 core.loggingmanager: Refactoring, converted to a module. Now possible to register additional sink types (think syslog) from other modules
Matthew Wild <mwild1@gmail.com>
parents: 1024
diff changeset
28
ec013f93de81 core.loggingmanager: Refactoring, converted to a module. Now possible to register additional sink types (think syslog) from other modules
Matthew Wild <mwild1@gmail.com>
parents: 1024
diff changeset
29 -- The log config used if none specified in the config file
1024
1bcc8ca57a7c core.loggingmanager: Add default logging settings (to console) and fill out code for adding sinks which catch all sources
Matthew Wild <mwild1@gmail.com>
parents: 1021
diff changeset
30 local default_logging = { { to = "console" } };
1344
ca74a6a38dfb loggingmanager: Log timestamps when using default file logging
Matthew Wild <mwild1@gmail.com>
parents: 1343
diff changeset
31 local default_file_logging = { { to = "file", levels = { min = (debug_mode and "debug") or "info" }, timestamps = true } };
1078
24c9ee99d900 loggingmanager: Support prepending timestamps in file/console/stdout log sinks
Matthew Wild <mwild1@gmail.com>
parents: 1067
diff changeset
32 local default_timestamp = "%b %d %T";
1031
ec013f93de81 core.loggingmanager: Refactoring, converted to a module. Now possible to register additional sink types (think syslog) from other modules
Matthew Wild <mwild1@gmail.com>
parents: 1024
diff changeset
33 -- The actual config loggingmanager is using
ec013f93de81 core.loggingmanager: Refactoring, converted to a module. Now possible to register additional sink types (think syslog) from other modules
Matthew Wild <mwild1@gmail.com>
parents: 1024
diff changeset
34 local logging_config = config.get("*", "core", "log") or default_logging;
1016
73afe3e30e97 core.loggingmanager: A new manager (yay!) to manage log output
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
35
1031
ec013f93de81 core.loggingmanager: Refactoring, converted to a module. Now possible to register additional sink types (think syslog) from other modules
Matthew Wild <mwild1@gmail.com>
parents: 1024
diff changeset
36 local apply_sink_rules;
ec013f93de81 core.loggingmanager: Refactoring, converted to a module. Now possible to register additional sink types (think syslog) from other modules
Matthew Wild <mwild1@gmail.com>
parents: 1024
diff changeset
37 local log_sink_types = setmetatable({}, { __newindex = function (t, k, v) rawset(t, k, v); apply_sink_rules(k); end; });
1021
f9122efeaadd core.loggingmanager: Filled out most code, and cleaned up
Matthew Wild <mwild1@gmail.com>
parents: 1016
diff changeset
38 local get_levels;
1024
1bcc8ca57a7c core.loggingmanager: Add default logging settings (to console) and fill out code for adding sinks which catch all sources
Matthew Wild <mwild1@gmail.com>
parents: 1021
diff changeset
39 local logging_levels = { "debug", "info", "warn", "error", "critical" }
1016
73afe3e30e97 core.loggingmanager: A new manager (yay!) to manage log output
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
40
1067
21f41b06f1d2 loggingmanager: Add ability to set 'log' config option to a filename, which causes all levels >= info to be logged to that file
Matthew Wild <mwild1@gmail.com>
parents: 1046
diff changeset
41 -- Put a rule into action. Requires that the sink type has already been registered.
21f41b06f1d2 loggingmanager: Add ability to set 'log' config option to a filename, which causes all levels >= info to be logged to that file
Matthew Wild <mwild1@gmail.com>
parents: 1046
diff changeset
42 -- This function is called automatically when a new sink type is added [see apply_sink_rules()]
1031
ec013f93de81 core.loggingmanager: Refactoring, converted to a module. Now possible to register additional sink types (think syslog) from other modules
Matthew Wild <mwild1@gmail.com>
parents: 1024
diff changeset
43 local function add_rule(sink_config)
ec013f93de81 core.loggingmanager: Refactoring, converted to a module. Now possible to register additional sink types (think syslog) from other modules
Matthew Wild <mwild1@gmail.com>
parents: 1024
diff changeset
44 local sink_maker = log_sink_types[sink_config.to];
ec013f93de81 core.loggingmanager: Refactoring, converted to a module. Now possible to register additional sink types (think syslog) from other modules
Matthew Wild <mwild1@gmail.com>
parents: 1024
diff changeset
45 if sink_maker then
ec013f93de81 core.loggingmanager: Refactoring, converted to a module. Now possible to register additional sink types (think syslog) from other modules
Matthew Wild <mwild1@gmail.com>
parents: 1024
diff changeset
46 if sink_config.levels and not sink_config.source then
ec013f93de81 core.loggingmanager: Refactoring, converted to a module. Now possible to register additional sink types (think syslog) from other modules
Matthew Wild <mwild1@gmail.com>
parents: 1024
diff changeset
47 -- Create sink
ec013f93de81 core.loggingmanager: Refactoring, converted to a module. Now possible to register additional sink types (think syslog) from other modules
Matthew Wild <mwild1@gmail.com>
parents: 1024
diff changeset
48 local sink = sink_maker(sink_config);
ec013f93de81 core.loggingmanager: Refactoring, converted to a module. Now possible to register additional sink types (think syslog) from other modules
Matthew Wild <mwild1@gmail.com>
parents: 1024
diff changeset
49
ec013f93de81 core.loggingmanager: Refactoring, converted to a module. Now possible to register additional sink types (think syslog) from other modules
Matthew Wild <mwild1@gmail.com>
parents: 1024
diff changeset
50 -- Set sink for all chosen levels
ec013f93de81 core.loggingmanager: Refactoring, converted to a module. Now possible to register additional sink types (think syslog) from other modules
Matthew Wild <mwild1@gmail.com>
parents: 1024
diff changeset
51 for level in pairs(get_levels(sink_config.levels)) do
ec013f93de81 core.loggingmanager: Refactoring, converted to a module. Now possible to register additional sink types (think syslog) from other modules
Matthew Wild <mwild1@gmail.com>
parents: 1024
diff changeset
52 logger.add_level_sink(level, sink);
ec013f93de81 core.loggingmanager: Refactoring, converted to a module. Now possible to register additional sink types (think syslog) from other modules
Matthew Wild <mwild1@gmail.com>
parents: 1024
diff changeset
53 end
ec013f93de81 core.loggingmanager: Refactoring, converted to a module. Now possible to register additional sink types (think syslog) from other modules
Matthew Wild <mwild1@gmail.com>
parents: 1024
diff changeset
54 elseif sink_config.source and not sink_config.levels then
ec013f93de81 core.loggingmanager: Refactoring, converted to a module. Now possible to register additional sink types (think syslog) from other modules
Matthew Wild <mwild1@gmail.com>
parents: 1024
diff changeset
55 logger.add_name_sink(sink_config.source, sink_maker(sink_config));
ec013f93de81 core.loggingmanager: Refactoring, converted to a module. Now possible to register additional sink types (think syslog) from other modules
Matthew Wild <mwild1@gmail.com>
parents: 1024
diff changeset
56 elseif sink_config.source and sink_config.levels then
ec013f93de81 core.loggingmanager: Refactoring, converted to a module. Now possible to register additional sink types (think syslog) from other modules
Matthew Wild <mwild1@gmail.com>
parents: 1024
diff changeset
57 local levels = get_levels(sink_config.levels);
ec013f93de81 core.loggingmanager: Refactoring, converted to a module. Now possible to register additional sink types (think syslog) from other modules
Matthew Wild <mwild1@gmail.com>
parents: 1024
diff changeset
58 local sink = sink_maker(sink_config);
ec013f93de81 core.loggingmanager: Refactoring, converted to a module. Now possible to register additional sink types (think syslog) from other modules
Matthew Wild <mwild1@gmail.com>
parents: 1024
diff changeset
59 logger.add_name_sink(sink_config.source,
ec013f93de81 core.loggingmanager: Refactoring, converted to a module. Now possible to register additional sink types (think syslog) from other modules
Matthew Wild <mwild1@gmail.com>
parents: 1024
diff changeset
60 function (name, level, ...)
ec013f93de81 core.loggingmanager: Refactoring, converted to a module. Now possible to register additional sink types (think syslog) from other modules
Matthew Wild <mwild1@gmail.com>
parents: 1024
diff changeset
61 if levels[level] then
ec013f93de81 core.loggingmanager: Refactoring, converted to a module. Now possible to register additional sink types (think syslog) from other modules
Matthew Wild <mwild1@gmail.com>
parents: 1024
diff changeset
62 return sink(name, level, ...);
1021
f9122efeaadd core.loggingmanager: Filled out most code, and cleaned up
Matthew Wild <mwild1@gmail.com>
parents: 1016
diff changeset
63 end
1031
ec013f93de81 core.loggingmanager: Refactoring, converted to a module. Now possible to register additional sink types (think syslog) from other modules
Matthew Wild <mwild1@gmail.com>
parents: 1024
diff changeset
64 end);
ec013f93de81 core.loggingmanager: Refactoring, converted to a module. Now possible to register additional sink types (think syslog) from other modules
Matthew Wild <mwild1@gmail.com>
parents: 1024
diff changeset
65 else
ec013f93de81 core.loggingmanager: Refactoring, converted to a module. Now possible to register additional sink types (think syslog) from other modules
Matthew Wild <mwild1@gmail.com>
parents: 1024
diff changeset
66 -- All sources
ec013f93de81 core.loggingmanager: Refactoring, converted to a module. Now possible to register additional sink types (think syslog) from other modules
Matthew Wild <mwild1@gmail.com>
parents: 1024
diff changeset
67 -- Create sink
ec013f93de81 core.loggingmanager: Refactoring, converted to a module. Now possible to register additional sink types (think syslog) from other modules
Matthew Wild <mwild1@gmail.com>
parents: 1024
diff changeset
68 local sink = sink_maker(sink_config);
ec013f93de81 core.loggingmanager: Refactoring, converted to a module. Now possible to register additional sink types (think syslog) from other modules
Matthew Wild <mwild1@gmail.com>
parents: 1024
diff changeset
69
ec013f93de81 core.loggingmanager: Refactoring, converted to a module. Now possible to register additional sink types (think syslog) from other modules
Matthew Wild <mwild1@gmail.com>
parents: 1024
diff changeset
70 -- Set sink for all levels
ec013f93de81 core.loggingmanager: Refactoring, converted to a module. Now possible to register additional sink types (think syslog) from other modules
Matthew Wild <mwild1@gmail.com>
parents: 1024
diff changeset
71 for _, level in pairs(logging_levels) do
ec013f93de81 core.loggingmanager: Refactoring, converted to a module. Now possible to register additional sink types (think syslog) from other modules
Matthew Wild <mwild1@gmail.com>
parents: 1024
diff changeset
72 logger.add_level_sink(level, sink);
1021
f9122efeaadd core.loggingmanager: Filled out most code, and cleaned up
Matthew Wild <mwild1@gmail.com>
parents: 1016
diff changeset
73 end
1016
73afe3e30e97 core.loggingmanager: A new manager (yay!) to manage log output
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
74 end
1031
ec013f93de81 core.loggingmanager: Refactoring, converted to a module. Now possible to register additional sink types (think syslog) from other modules
Matthew Wild <mwild1@gmail.com>
parents: 1024
diff changeset
75 else
ec013f93de81 core.loggingmanager: Refactoring, converted to a module. Now possible to register additional sink types (think syslog) from other modules
Matthew Wild <mwild1@gmail.com>
parents: 1024
diff changeset
76 -- No such sink type
1016
73afe3e30e97 core.loggingmanager: A new manager (yay!) to manage log output
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
77 end
73afe3e30e97 core.loggingmanager: A new manager (yay!) to manage log output
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
78 end
73afe3e30e97 core.loggingmanager: A new manager (yay!) to manage log output
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
79
1067
21f41b06f1d2 loggingmanager: Add ability to set 'log' config option to a filename, which causes all levels >= info to be logged to that file
Matthew Wild <mwild1@gmail.com>
parents: 1046
diff changeset
80 -- Search for all rules using a particular sink type, and apply
21f41b06f1d2 loggingmanager: Add ability to set 'log' config option to a filename, which causes all levels >= info to be logged to that file
Matthew Wild <mwild1@gmail.com>
parents: 1046
diff changeset
81 -- them. Called automatically when a new sink type is added to
21f41b06f1d2 loggingmanager: Add ability to set 'log' config option to a filename, which causes all levels >= info to be logged to that file
Matthew Wild <mwild1@gmail.com>
parents: 1046
diff changeset
82 -- the log_sink_types table.
1031
ec013f93de81 core.loggingmanager: Refactoring, converted to a module. Now possible to register additional sink types (think syslog) from other modules
Matthew Wild <mwild1@gmail.com>
parents: 1024
diff changeset
83 function apply_sink_rules(sink_type)
ec013f93de81 core.loggingmanager: Refactoring, converted to a module. Now possible to register additional sink types (think syslog) from other modules
Matthew Wild <mwild1@gmail.com>
parents: 1024
diff changeset
84 if type(logging_config) == "table" then
ec013f93de81 core.loggingmanager: Refactoring, converted to a module. Now possible to register additional sink types (think syslog) from other modules
Matthew Wild <mwild1@gmail.com>
parents: 1024
diff changeset
85 for _, sink_config in pairs(logging_config) do
ec013f93de81 core.loggingmanager: Refactoring, converted to a module. Now possible to register additional sink types (think syslog) from other modules
Matthew Wild <mwild1@gmail.com>
parents: 1024
diff changeset
86 if sink_config.to == sink_type then
ec013f93de81 core.loggingmanager: Refactoring, converted to a module. Now possible to register additional sink types (think syslog) from other modules
Matthew Wild <mwild1@gmail.com>
parents: 1024
diff changeset
87 add_rule(sink_config);
1021
f9122efeaadd core.loggingmanager: Filled out most code, and cleaned up
Matthew Wild <mwild1@gmail.com>
parents: 1016
diff changeset
88 end
f9122efeaadd core.loggingmanager: Filled out most code, and cleaned up
Matthew Wild <mwild1@gmail.com>
parents: 1016
diff changeset
89 end
1067
21f41b06f1d2 loggingmanager: Add ability to set 'log' config option to a filename, which causes all levels >= info to be logged to that file
Matthew Wild <mwild1@gmail.com>
parents: 1046
diff changeset
90 elseif type(logging_config) == "string" and (not logging_config:match("^%*")) and sink_type == "file" then
1031
ec013f93de81 core.loggingmanager: Refactoring, converted to a module. Now possible to register additional sink types (think syslog) from other modules
Matthew Wild <mwild1@gmail.com>
parents: 1024
diff changeset
91 -- User specified simply a filename, and the "file" sink type
ec013f93de81 core.loggingmanager: Refactoring, converted to a module. Now possible to register additional sink types (think syslog) from other modules
Matthew Wild <mwild1@gmail.com>
parents: 1024
diff changeset
92 -- was just added
1067
21f41b06f1d2 loggingmanager: Add ability to set 'log' config option to a filename, which causes all levels >= info to be logged to that file
Matthew Wild <mwild1@gmail.com>
parents: 1046
diff changeset
93 for _, sink_config in pairs(default_file_logging) do
21f41b06f1d2 loggingmanager: Add ability to set 'log' config option to a filename, which causes all levels >= info to be logged to that file
Matthew Wild <mwild1@gmail.com>
parents: 1046
diff changeset
94 sink_config.filename = logging_config;
21f41b06f1d2 loggingmanager: Add ability to set 'log' config option to a filename, which causes all levels >= info to be logged to that file
Matthew Wild <mwild1@gmail.com>
parents: 1046
diff changeset
95 add_rule(sink_config);
21f41b06f1d2 loggingmanager: Add ability to set 'log' config option to a filename, which causes all levels >= info to be logged to that file
Matthew Wild <mwild1@gmail.com>
parents: 1046
diff changeset
96 sink_config.filename = nil;
21f41b06f1d2 loggingmanager: Add ability to set 'log' config option to a filename, which causes all levels >= info to be logged to that file
Matthew Wild <mwild1@gmail.com>
parents: 1046
diff changeset
97 end
1101
fb096ca4b296 loggingmanager: Support for specifying a single sink with *sinkname (*syslog should now work)
Matthew Wild <mwild1@gmail.com>
parents: 1080
diff changeset
98 elseif type(logging_config) == "string" and logging_config:match("^%*(.+)") == sink_type then
fb096ca4b296 loggingmanager: Support for specifying a single sink with *sinkname (*syslog should now work)
Matthew Wild <mwild1@gmail.com>
parents: 1080
diff changeset
99 -- Log all levels (debug+) to this sink
fb096ca4b296 loggingmanager: Support for specifying a single sink with *sinkname (*syslog should now work)
Matthew Wild <mwild1@gmail.com>
parents: 1080
diff changeset
100 add_rule({ levels = { min = "debug" }, to = sink_type });
1021
f9122efeaadd core.loggingmanager: Filled out most code, and cleaned up
Matthew Wild <mwild1@gmail.com>
parents: 1016
diff changeset
101 end
f9122efeaadd core.loggingmanager: Filled out most code, and cleaned up
Matthew Wild <mwild1@gmail.com>
parents: 1016
diff changeset
102 end
1016
73afe3e30e97 core.loggingmanager: A new manager (yay!) to manage log output
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
103
1021
f9122efeaadd core.loggingmanager: Filled out most code, and cleaned up
Matthew Wild <mwild1@gmail.com>
parents: 1016
diff changeset
104
f9122efeaadd core.loggingmanager: Filled out most code, and cleaned up
Matthew Wild <mwild1@gmail.com>
parents: 1016
diff changeset
105
f9122efeaadd core.loggingmanager: Filled out most code, and cleaned up
Matthew Wild <mwild1@gmail.com>
parents: 1016
diff changeset
106 --- Helper function to get a set of levels given a "criteria" table
f9122efeaadd core.loggingmanager: Filled out most code, and cleaned up
Matthew Wild <mwild1@gmail.com>
parents: 1016
diff changeset
107 function get_levels(criteria, set)
f9122efeaadd core.loggingmanager: Filled out most code, and cleaned up
Matthew Wild <mwild1@gmail.com>
parents: 1016
diff changeset
108 set = set or {};
f9122efeaadd core.loggingmanager: Filled out most code, and cleaned up
Matthew Wild <mwild1@gmail.com>
parents: 1016
diff changeset
109 if type(criteria) == "string" then
f9122efeaadd core.loggingmanager: Filled out most code, and cleaned up
Matthew Wild <mwild1@gmail.com>
parents: 1016
diff changeset
110 set[criteria] = true;
f9122efeaadd core.loggingmanager: Filled out most code, and cleaned up
Matthew Wild <mwild1@gmail.com>
parents: 1016
diff changeset
111 return set;
f9122efeaadd core.loggingmanager: Filled out most code, and cleaned up
Matthew Wild <mwild1@gmail.com>
parents: 1016
diff changeset
112 end
f9122efeaadd core.loggingmanager: Filled out most code, and cleaned up
Matthew Wild <mwild1@gmail.com>
parents: 1016
diff changeset
113 local min, max = criteria.min, criteria.max;
f9122efeaadd core.loggingmanager: Filled out most code, and cleaned up
Matthew Wild <mwild1@gmail.com>
parents: 1016
diff changeset
114 if min or max then
f9122efeaadd core.loggingmanager: Filled out most code, and cleaned up
Matthew Wild <mwild1@gmail.com>
parents: 1016
diff changeset
115 local in_range;
f9122efeaadd core.loggingmanager: Filled out most code, and cleaned up
Matthew Wild <mwild1@gmail.com>
parents: 1016
diff changeset
116 for _, level in ipairs(logging_levels) do
f9122efeaadd core.loggingmanager: Filled out most code, and cleaned up
Matthew Wild <mwild1@gmail.com>
parents: 1016
diff changeset
117 if min == level then
f9122efeaadd core.loggingmanager: Filled out most code, and cleaned up
Matthew Wild <mwild1@gmail.com>
parents: 1016
diff changeset
118 set[level] = true;
f9122efeaadd core.loggingmanager: Filled out most code, and cleaned up
Matthew Wild <mwild1@gmail.com>
parents: 1016
diff changeset
119 in_range = true;
f9122efeaadd core.loggingmanager: Filled out most code, and cleaned up
Matthew Wild <mwild1@gmail.com>
parents: 1016
diff changeset
120 elseif max == level then
f9122efeaadd core.loggingmanager: Filled out most code, and cleaned up
Matthew Wild <mwild1@gmail.com>
parents: 1016
diff changeset
121 set[level] = true;
f9122efeaadd core.loggingmanager: Filled out most code, and cleaned up
Matthew Wild <mwild1@gmail.com>
parents: 1016
diff changeset
122 return set;
f9122efeaadd core.loggingmanager: Filled out most code, and cleaned up
Matthew Wild <mwild1@gmail.com>
parents: 1016
diff changeset
123 elseif in_range then
f9122efeaadd core.loggingmanager: Filled out most code, and cleaned up
Matthew Wild <mwild1@gmail.com>
parents: 1016
diff changeset
124 set[level] = true;
f9122efeaadd core.loggingmanager: Filled out most code, and cleaned up
Matthew Wild <mwild1@gmail.com>
parents: 1016
diff changeset
125 end
f9122efeaadd core.loggingmanager: Filled out most code, and cleaned up
Matthew Wild <mwild1@gmail.com>
parents: 1016
diff changeset
126 end
f9122efeaadd core.loggingmanager: Filled out most code, and cleaned up
Matthew Wild <mwild1@gmail.com>
parents: 1016
diff changeset
127 end
f9122efeaadd core.loggingmanager: Filled out most code, and cleaned up
Matthew Wild <mwild1@gmail.com>
parents: 1016
diff changeset
128
f9122efeaadd core.loggingmanager: Filled out most code, and cleaned up
Matthew Wild <mwild1@gmail.com>
parents: 1016
diff changeset
129 for _, level in ipairs(criteria) do
f9122efeaadd core.loggingmanager: Filled out most code, and cleaned up
Matthew Wild <mwild1@gmail.com>
parents: 1016
diff changeset
130 set[level] = true;
f9122efeaadd core.loggingmanager: Filled out most code, and cleaned up
Matthew Wild <mwild1@gmail.com>
parents: 1016
diff changeset
131 end
f9122efeaadd core.loggingmanager: Filled out most code, and cleaned up
Matthew Wild <mwild1@gmail.com>
parents: 1016
diff changeset
132 return set;
f9122efeaadd core.loggingmanager: Filled out most code, and cleaned up
Matthew Wild <mwild1@gmail.com>
parents: 1016
diff changeset
133 end
f9122efeaadd core.loggingmanager: Filled out most code, and cleaned up
Matthew Wild <mwild1@gmail.com>
parents: 1016
diff changeset
134
1031
ec013f93de81 core.loggingmanager: Refactoring, converted to a module. Now possible to register additional sink types (think syslog) from other modules
Matthew Wild <mwild1@gmail.com>
parents: 1024
diff changeset
135 --- Definition of built-in logging sinks ---
ec013f93de81 core.loggingmanager: Refactoring, converted to a module. Now possible to register additional sink types (think syslog) from other modules
Matthew Wild <mwild1@gmail.com>
parents: 1024
diff changeset
136
1080
b02290fd8a75 loggingmanager: Add a comment about 'nowhere' sink type
Matthew Wild <mwild1@gmail.com>
parents: 1078
diff changeset
137 -- Null sink, must enter log_sink_types *first*
1031
ec013f93de81 core.loggingmanager: Refactoring, converted to a module. Now possible to register additional sink types (think syslog) from other modules
Matthew Wild <mwild1@gmail.com>
parents: 1024
diff changeset
138 function log_sink_types.nowhere()
ec013f93de81 core.loggingmanager: Refactoring, converted to a module. Now possible to register additional sink types (think syslog) from other modules
Matthew Wild <mwild1@gmail.com>
parents: 1024
diff changeset
139 return function () return false; end;
ec013f93de81 core.loggingmanager: Refactoring, converted to a module. Now possible to register additional sink types (think syslog) from other modules
Matthew Wild <mwild1@gmail.com>
parents: 1024
diff changeset
140 end
ec013f93de81 core.loggingmanager: Refactoring, converted to a module. Now possible to register additional sink types (think syslog) from other modules
Matthew Wild <mwild1@gmail.com>
parents: 1024
diff changeset
141
ec013f93de81 core.loggingmanager: Refactoring, converted to a module. Now possible to register additional sink types (think syslog) from other modules
Matthew Wild <mwild1@gmail.com>
parents: 1024
diff changeset
142 -- Column width for "source" (used by stdout and console)
ec013f93de81 core.loggingmanager: Refactoring, converted to a module. Now possible to register additional sink types (think syslog) from other modules
Matthew Wild <mwild1@gmail.com>
parents: 1024
diff changeset
143 local sourcewidth = 20;
ec013f93de81 core.loggingmanager: Refactoring, converted to a module. Now possible to register additional sink types (think syslog) from other modules
Matthew Wild <mwild1@gmail.com>
parents: 1024
diff changeset
144
ec013f93de81 core.loggingmanager: Refactoring, converted to a module. Now possible to register additional sink types (think syslog) from other modules
Matthew Wild <mwild1@gmail.com>
parents: 1024
diff changeset
145 function log_sink_types.stdout()
1078
24c9ee99d900 loggingmanager: Support prepending timestamps in file/console/stdout log sinks
Matthew Wild <mwild1@gmail.com>
parents: 1067
diff changeset
146 local timestamps = config.timestamps;
24c9ee99d900 loggingmanager: Support prepending timestamps in file/console/stdout log sinks
Matthew Wild <mwild1@gmail.com>
parents: 1067
diff changeset
147
24c9ee99d900 loggingmanager: Support prepending timestamps in file/console/stdout log sinks
Matthew Wild <mwild1@gmail.com>
parents: 1067
diff changeset
148 if timestamps == true then
24c9ee99d900 loggingmanager: Support prepending timestamps in file/console/stdout log sinks
Matthew Wild <mwild1@gmail.com>
parents: 1067
diff changeset
149 timestamps = default_timestamp; -- Default format
24c9ee99d900 loggingmanager: Support prepending timestamps in file/console/stdout log sinks
Matthew Wild <mwild1@gmail.com>
parents: 1067
diff changeset
150 end
24c9ee99d900 loggingmanager: Support prepending timestamps in file/console/stdout log sinks
Matthew Wild <mwild1@gmail.com>
parents: 1067
diff changeset
151
1031
ec013f93de81 core.loggingmanager: Refactoring, converted to a module. Now possible to register additional sink types (think syslog) from other modules
Matthew Wild <mwild1@gmail.com>
parents: 1024
diff changeset
152 return function (name, level, message, ...)
ec013f93de81 core.loggingmanager: Refactoring, converted to a module. Now possible to register additional sink types (think syslog) from other modules
Matthew Wild <mwild1@gmail.com>
parents: 1024
diff changeset
153 sourcewidth = math_max(#name+2, sourcewidth);
ec013f93de81 core.loggingmanager: Refactoring, converted to a module. Now possible to register additional sink types (think syslog) from other modules
Matthew Wild <mwild1@gmail.com>
parents: 1024
diff changeset
154 local namelen = #name;
1078
24c9ee99d900 loggingmanager: Support prepending timestamps in file/console/stdout log sinks
Matthew Wild <mwild1@gmail.com>
parents: 1067
diff changeset
155 if timestamps then
24c9ee99d900 loggingmanager: Support prepending timestamps in file/console/stdout log sinks
Matthew Wild <mwild1@gmail.com>
parents: 1067
diff changeset
156 io_write(os_date(timestamps), " ");
24c9ee99d900 loggingmanager: Support prepending timestamps in file/console/stdout log sinks
Matthew Wild <mwild1@gmail.com>
parents: 1067
diff changeset
157 end
1031
ec013f93de81 core.loggingmanager: Refactoring, converted to a module. Now possible to register additional sink types (think syslog) from other modules
Matthew Wild <mwild1@gmail.com>
parents: 1024
diff changeset
158 if ... then
ec013f93de81 core.loggingmanager: Refactoring, converted to a module. Now possible to register additional sink types (think syslog) from other modules
Matthew Wild <mwild1@gmail.com>
parents: 1024
diff changeset
159 io_write(name, rep(" ", sourcewidth-namelen), level, "\t", format(message, ...), "\n");
ec013f93de81 core.loggingmanager: Refactoring, converted to a module. Now possible to register additional sink types (think syslog) from other modules
Matthew Wild <mwild1@gmail.com>
parents: 1024
diff changeset
160 else
ec013f93de81 core.loggingmanager: Refactoring, converted to a module. Now possible to register additional sink types (think syslog) from other modules
Matthew Wild <mwild1@gmail.com>
parents: 1024
diff changeset
161 io_write(name, rep(" ", sourcewidth-namelen), level, "\t", message, "\n");
ec013f93de81 core.loggingmanager: Refactoring, converted to a module. Now possible to register additional sink types (think syslog) from other modules
Matthew Wild <mwild1@gmail.com>
parents: 1024
diff changeset
162 end
ec013f93de81 core.loggingmanager: Refactoring, converted to a module. Now possible to register additional sink types (think syslog) from other modules
Matthew Wild <mwild1@gmail.com>
parents: 1024
diff changeset
163 end
ec013f93de81 core.loggingmanager: Refactoring, converted to a module. Now possible to register additional sink types (think syslog) from other modules
Matthew Wild <mwild1@gmail.com>
parents: 1024
diff changeset
164 end
1021
f9122efeaadd core.loggingmanager: Filled out most code, and cleaned up
Matthew Wild <mwild1@gmail.com>
parents: 1016
diff changeset
165
1031
ec013f93de81 core.loggingmanager: Refactoring, converted to a module. Now possible to register additional sink types (think syslog) from other modules
Matthew Wild <mwild1@gmail.com>
parents: 1024
diff changeset
166 do
ec013f93de81 core.loggingmanager: Refactoring, converted to a module. Now possible to register additional sink types (think syslog) from other modules
Matthew Wild <mwild1@gmail.com>
parents: 1024
diff changeset
167 local do_pretty_printing = not os_getenv("WINDIR");
ec013f93de81 core.loggingmanager: Refactoring, converted to a module. Now possible to register additional sink types (think syslog) from other modules
Matthew Wild <mwild1@gmail.com>
parents: 1024
diff changeset
168
ec013f93de81 core.loggingmanager: Refactoring, converted to a module. Now possible to register additional sink types (think syslog) from other modules
Matthew Wild <mwild1@gmail.com>
parents: 1024
diff changeset
169 local logstyles = {};
ec013f93de81 core.loggingmanager: Refactoring, converted to a module. Now possible to register additional sink types (think syslog) from other modules
Matthew Wild <mwild1@gmail.com>
parents: 1024
diff changeset
170 if do_pretty_printing then
ec013f93de81 core.loggingmanager: Refactoring, converted to a module. Now possible to register additional sink types (think syslog) from other modules
Matthew Wild <mwild1@gmail.com>
parents: 1024
diff changeset
171 logstyles["info"] = getstyle("bold");
ec013f93de81 core.loggingmanager: Refactoring, converted to a module. Now possible to register additional sink types (think syslog) from other modules
Matthew Wild <mwild1@gmail.com>
parents: 1024
diff changeset
172 logstyles["warn"] = getstyle("bold", "yellow");
ec013f93de81 core.loggingmanager: Refactoring, converted to a module. Now possible to register additional sink types (think syslog) from other modules
Matthew Wild <mwild1@gmail.com>
parents: 1024
diff changeset
173 logstyles["error"] = getstyle("bold", "red");
ec013f93de81 core.loggingmanager: Refactoring, converted to a module. Now possible to register additional sink types (think syslog) from other modules
Matthew Wild <mwild1@gmail.com>
parents: 1024
diff changeset
174 end
ec013f93de81 core.loggingmanager: Refactoring, converted to a module. Now possible to register additional sink types (think syslog) from other modules
Matthew Wild <mwild1@gmail.com>
parents: 1024
diff changeset
175 function log_sink_types.console(config)
ec013f93de81 core.loggingmanager: Refactoring, converted to a module. Now possible to register additional sink types (think syslog) from other modules
Matthew Wild <mwild1@gmail.com>
parents: 1024
diff changeset
176 -- Really if we don't want pretty colours then just use plain stdout
ec013f93de81 core.loggingmanager: Refactoring, converted to a module. Now possible to register additional sink types (think syslog) from other modules
Matthew Wild <mwild1@gmail.com>
parents: 1024
diff changeset
177 if not do_pretty_printing then
ec013f93de81 core.loggingmanager: Refactoring, converted to a module. Now possible to register additional sink types (think syslog) from other modules
Matthew Wild <mwild1@gmail.com>
parents: 1024
diff changeset
178 return log_sink_types.stdout(config);
ec013f93de81 core.loggingmanager: Refactoring, converted to a module. Now possible to register additional sink types (think syslog) from other modules
Matthew Wild <mwild1@gmail.com>
parents: 1024
diff changeset
179 end
ec013f93de81 core.loggingmanager: Refactoring, converted to a module. Now possible to register additional sink types (think syslog) from other modules
Matthew Wild <mwild1@gmail.com>
parents: 1024
diff changeset
180
1078
24c9ee99d900 loggingmanager: Support prepending timestamps in file/console/stdout log sinks
Matthew Wild <mwild1@gmail.com>
parents: 1067
diff changeset
181 local timestamps = config.timestamps;
24c9ee99d900 loggingmanager: Support prepending timestamps in file/console/stdout log sinks
Matthew Wild <mwild1@gmail.com>
parents: 1067
diff changeset
182
24c9ee99d900 loggingmanager: Support prepending timestamps in file/console/stdout log sinks
Matthew Wild <mwild1@gmail.com>
parents: 1067
diff changeset
183 if timestamps == true then
24c9ee99d900 loggingmanager: Support prepending timestamps in file/console/stdout log sinks
Matthew Wild <mwild1@gmail.com>
parents: 1067
diff changeset
184 timestamps = default_timestamp; -- Default format
24c9ee99d900 loggingmanager: Support prepending timestamps in file/console/stdout log sinks
Matthew Wild <mwild1@gmail.com>
parents: 1067
diff changeset
185 end
24c9ee99d900 loggingmanager: Support prepending timestamps in file/console/stdout log sinks
Matthew Wild <mwild1@gmail.com>
parents: 1067
diff changeset
186
1031
ec013f93de81 core.loggingmanager: Refactoring, converted to a module. Now possible to register additional sink types (think syslog) from other modules
Matthew Wild <mwild1@gmail.com>
parents: 1024
diff changeset
187 return function (name, level, message, ...)
ec013f93de81 core.loggingmanager: Refactoring, converted to a module. Now possible to register additional sink types (think syslog) from other modules
Matthew Wild <mwild1@gmail.com>
parents: 1024
diff changeset
188 sourcewidth = math_max(#name+2, sourcewidth);
ec013f93de81 core.loggingmanager: Refactoring, converted to a module. Now possible to register additional sink types (think syslog) from other modules
Matthew Wild <mwild1@gmail.com>
parents: 1024
diff changeset
189 local namelen = #name;
1078
24c9ee99d900 loggingmanager: Support prepending timestamps in file/console/stdout log sinks
Matthew Wild <mwild1@gmail.com>
parents: 1067
diff changeset
190 if timestamps then
24c9ee99d900 loggingmanager: Support prepending timestamps in file/console/stdout log sinks
Matthew Wild <mwild1@gmail.com>
parents: 1067
diff changeset
191 io_write(os_date(timestamps), " ");
24c9ee99d900 loggingmanager: Support prepending timestamps in file/console/stdout log sinks
Matthew Wild <mwild1@gmail.com>
parents: 1067
diff changeset
192 end
1031
ec013f93de81 core.loggingmanager: Refactoring, converted to a module. Now possible to register additional sink types (think syslog) from other modules
Matthew Wild <mwild1@gmail.com>
parents: 1024
diff changeset
193 if ... then
ec013f93de81 core.loggingmanager: Refactoring, converted to a module. Now possible to register additional sink types (think syslog) from other modules
Matthew Wild <mwild1@gmail.com>
parents: 1024
diff changeset
194 io_write(name, rep(" ", sourcewidth-namelen), getstring(logstyles[level], level), "\t", format(message, ...), "\n");
ec013f93de81 core.loggingmanager: Refactoring, converted to a module. Now possible to register additional sink types (think syslog) from other modules
Matthew Wild <mwild1@gmail.com>
parents: 1024
diff changeset
195 else
ec013f93de81 core.loggingmanager: Refactoring, converted to a module. Now possible to register additional sink types (think syslog) from other modules
Matthew Wild <mwild1@gmail.com>
parents: 1024
diff changeset
196 io_write(name, rep(" ", sourcewidth-namelen), getstring(logstyles[level], level), "\t", message, "\n");
ec013f93de81 core.loggingmanager: Refactoring, converted to a module. Now possible to register additional sink types (think syslog) from other modules
Matthew Wild <mwild1@gmail.com>
parents: 1024
diff changeset
197 end
ec013f93de81 core.loggingmanager: Refactoring, converted to a module. Now possible to register additional sink types (think syslog) from other modules
Matthew Wild <mwild1@gmail.com>
parents: 1024
diff changeset
198 end
ec013f93de81 core.loggingmanager: Refactoring, converted to a module. Now possible to register additional sink types (think syslog) from other modules
Matthew Wild <mwild1@gmail.com>
parents: 1024
diff changeset
199 end
ec013f93de81 core.loggingmanager: Refactoring, converted to a module. Now possible to register additional sink types (think syslog) from other modules
Matthew Wild <mwild1@gmail.com>
parents: 1024
diff changeset
200 end
ec013f93de81 core.loggingmanager: Refactoring, converted to a module. Now possible to register additional sink types (think syslog) from other modules
Matthew Wild <mwild1@gmail.com>
parents: 1024
diff changeset
201
1117
360ec48ea780 loggingmanager: File log sinks react to reopen-log-files event
Matthew Wild <mwild1@gmail.com>
parents: 1101
diff changeset
202 local empty_function = function () end;
1031
ec013f93de81 core.loggingmanager: Refactoring, converted to a module. Now possible to register additional sink types (think syslog) from other modules
Matthew Wild <mwild1@gmail.com>
parents: 1024
diff changeset
203 function log_sink_types.file(config)
ec013f93de81 core.loggingmanager: Refactoring, converted to a module. Now possible to register additional sink types (think syslog) from other modules
Matthew Wild <mwild1@gmail.com>
parents: 1024
diff changeset
204 local log = config.filename;
ec013f93de81 core.loggingmanager: Refactoring, converted to a module. Now possible to register additional sink types (think syslog) from other modules
Matthew Wild <mwild1@gmail.com>
parents: 1024
diff changeset
205 local logfile = io_open(log, "a+");
ec013f93de81 core.loggingmanager: Refactoring, converted to a module. Now possible to register additional sink types (think syslog) from other modules
Matthew Wild <mwild1@gmail.com>
parents: 1024
diff changeset
206 if not logfile then
1117
360ec48ea780 loggingmanager: File log sinks react to reopen-log-files event
Matthew Wild <mwild1@gmail.com>
parents: 1101
diff changeset
207 return empty_function;
1031
ec013f93de81 core.loggingmanager: Refactoring, converted to a module. Now possible to register additional sink types (think syslog) from other modules
Matthew Wild <mwild1@gmail.com>
parents: 1024
diff changeset
208 end
1117
360ec48ea780 loggingmanager: File log sinks react to reopen-log-files event
Matthew Wild <mwild1@gmail.com>
parents: 1101
diff changeset
209 local write, flush = logfile.write, logfile.flush;
360ec48ea780 loggingmanager: File log sinks react to reopen-log-files event
Matthew Wild <mwild1@gmail.com>
parents: 1101
diff changeset
210
360ec48ea780 loggingmanager: File log sinks react to reopen-log-files event
Matthew Wild <mwild1@gmail.com>
parents: 1101
diff changeset
211 eventmanager.add_event_hook("reopen-log-files", function ()
360ec48ea780 loggingmanager: File log sinks react to reopen-log-files event
Matthew Wild <mwild1@gmail.com>
parents: 1101
diff changeset
212 if logfile then
360ec48ea780 loggingmanager: File log sinks react to reopen-log-files event
Matthew Wild <mwild1@gmail.com>
parents: 1101
diff changeset
213 logfile:close();
360ec48ea780 loggingmanager: File log sinks react to reopen-log-files event
Matthew Wild <mwild1@gmail.com>
parents: 1101
diff changeset
214 end
360ec48ea780 loggingmanager: File log sinks react to reopen-log-files event
Matthew Wild <mwild1@gmail.com>
parents: 1101
diff changeset
215 logfile = io_open(log, "a+");
360ec48ea780 loggingmanager: File log sinks react to reopen-log-files event
Matthew Wild <mwild1@gmail.com>
parents: 1101
diff changeset
216 if not logfile then
360ec48ea780 loggingmanager: File log sinks react to reopen-log-files event
Matthew Wild <mwild1@gmail.com>
parents: 1101
diff changeset
217 write, flush = empty_function, empty_function;
360ec48ea780 loggingmanager: File log sinks react to reopen-log-files event
Matthew Wild <mwild1@gmail.com>
parents: 1101
diff changeset
218 else
360ec48ea780 loggingmanager: File log sinks react to reopen-log-files event
Matthew Wild <mwild1@gmail.com>
parents: 1101
diff changeset
219 write, flush = logfile.write, logfile.flush;
360ec48ea780 loggingmanager: File log sinks react to reopen-log-files event
Matthew Wild <mwild1@gmail.com>
parents: 1101
diff changeset
220 end
360ec48ea780 loggingmanager: File log sinks react to reopen-log-files event
Matthew Wild <mwild1@gmail.com>
parents: 1101
diff changeset
221 end);
1031
ec013f93de81 core.loggingmanager: Refactoring, converted to a module. Now possible to register additional sink types (think syslog) from other modules
Matthew Wild <mwild1@gmail.com>
parents: 1024
diff changeset
222
1078
24c9ee99d900 loggingmanager: Support prepending timestamps in file/console/stdout log sinks
Matthew Wild <mwild1@gmail.com>
parents: 1067
diff changeset
223 local timestamps = config.timestamps;
24c9ee99d900 loggingmanager: Support prepending timestamps in file/console/stdout log sinks
Matthew Wild <mwild1@gmail.com>
parents: 1067
diff changeset
224
1613
ebf0813a81f6 core.loggingmanager: Enable timestamps by default for file log sinks
Matthew Wild <mwild1@gmail.com>
parents: 1522
diff changeset
225 if timestamps == nil or timestamps == true then
1078
24c9ee99d900 loggingmanager: Support prepending timestamps in file/console/stdout log sinks
Matthew Wild <mwild1@gmail.com>
parents: 1067
diff changeset
226 timestamps = default_timestamp; -- Default format
24c9ee99d900 loggingmanager: Support prepending timestamps in file/console/stdout log sinks
Matthew Wild <mwild1@gmail.com>
parents: 1067
diff changeset
227 end
24c9ee99d900 loggingmanager: Support prepending timestamps in file/console/stdout log sinks
Matthew Wild <mwild1@gmail.com>
parents: 1067
diff changeset
228
1031
ec013f93de81 core.loggingmanager: Refactoring, converted to a module. Now possible to register additional sink types (think syslog) from other modules
Matthew Wild <mwild1@gmail.com>
parents: 1024
diff changeset
229 return function (name, level, message, ...)
1078
24c9ee99d900 loggingmanager: Support prepending timestamps in file/console/stdout log sinks
Matthew Wild <mwild1@gmail.com>
parents: 1067
diff changeset
230 if timestamps then
24c9ee99d900 loggingmanager: Support prepending timestamps in file/console/stdout log sinks
Matthew Wild <mwild1@gmail.com>
parents: 1067
diff changeset
231 write(logfile, os_date(timestamps), " ");
24c9ee99d900 loggingmanager: Support prepending timestamps in file/console/stdout log sinks
Matthew Wild <mwild1@gmail.com>
parents: 1067
diff changeset
232 end
1031
ec013f93de81 core.loggingmanager: Refactoring, converted to a module. Now possible to register additional sink types (think syslog) from other modules
Matthew Wild <mwild1@gmail.com>
parents: 1024
diff changeset
233 if ... then
ec013f93de81 core.loggingmanager: Refactoring, converted to a module. Now possible to register additional sink types (think syslog) from other modules
Matthew Wild <mwild1@gmail.com>
parents: 1024
diff changeset
234 write(logfile, name, "\t", level, "\t", format(message, ...), "\n");
ec013f93de81 core.loggingmanager: Refactoring, converted to a module. Now possible to register additional sink types (think syslog) from other modules
Matthew Wild <mwild1@gmail.com>
parents: 1024
diff changeset
235 else
ec013f93de81 core.loggingmanager: Refactoring, converted to a module. Now possible to register additional sink types (think syslog) from other modules
Matthew Wild <mwild1@gmail.com>
parents: 1024
diff changeset
236 write(logfile, name, "\t" , level, "\t", message, "\n");
ec013f93de81 core.loggingmanager: Refactoring, converted to a module. Now possible to register additional sink types (think syslog) from other modules
Matthew Wild <mwild1@gmail.com>
parents: 1024
diff changeset
237 end
ec013f93de81 core.loggingmanager: Refactoring, converted to a module. Now possible to register additional sink types (think syslog) from other modules
Matthew Wild <mwild1@gmail.com>
parents: 1024
diff changeset
238 flush(logfile);
ec013f93de81 core.loggingmanager: Refactoring, converted to a module. Now possible to register additional sink types (think syslog) from other modules
Matthew Wild <mwild1@gmail.com>
parents: 1024
diff changeset
239 end;
ec013f93de81 core.loggingmanager: Refactoring, converted to a module. Now possible to register additional sink types (think syslog) from other modules
Matthew Wild <mwild1@gmail.com>
parents: 1024
diff changeset
240 end
ec013f93de81 core.loggingmanager: Refactoring, converted to a module. Now possible to register additional sink types (think syslog) from other modules
Matthew Wild <mwild1@gmail.com>
parents: 1024
diff changeset
241
ec013f93de81 core.loggingmanager: Refactoring, converted to a module. Now possible to register additional sink types (think syslog) from other modules
Matthew Wild <mwild1@gmail.com>
parents: 1024
diff changeset
242 function register_sink_type(name, sink_maker)
ec013f93de81 core.loggingmanager: Refactoring, converted to a module. Now possible to register additional sink types (think syslog) from other modules
Matthew Wild <mwild1@gmail.com>
parents: 1024
diff changeset
243 local old_sink_maker = log_sink_types[name];
ec013f93de81 core.loggingmanager: Refactoring, converted to a module. Now possible to register additional sink types (think syslog) from other modules
Matthew Wild <mwild1@gmail.com>
parents: 1024
diff changeset
244 log_sink_types[name] = sink_maker;
ec013f93de81 core.loggingmanager: Refactoring, converted to a module. Now possible to register additional sink types (think syslog) from other modules
Matthew Wild <mwild1@gmail.com>
parents: 1024
diff changeset
245 return old_sink_maker;
ec013f93de81 core.loggingmanager: Refactoring, converted to a module. Now possible to register additional sink types (think syslog) from other modules
Matthew Wild <mwild1@gmail.com>
parents: 1024
diff changeset
246 end
ec013f93de81 core.loggingmanager: Refactoring, converted to a module. Now possible to register additional sink types (think syslog) from other modules
Matthew Wild <mwild1@gmail.com>
parents: 1024
diff changeset
247
ec013f93de81 core.loggingmanager: Refactoring, converted to a module. Now possible to register additional sink types (think syslog) from other modules
Matthew Wild <mwild1@gmail.com>
parents: 1024
diff changeset
248 return _M;

mercurial