Software /
code /
prosody
Annotate
core/loggingmanager.lua @ 1344:ca74a6a38dfb
loggingmanager: Log timestamps when using default file logging
author | Matthew Wild <mwild1@gmail.com> |
---|---|
date | Fri, 19 Jun 2009 17:23:17 +0100 |
parent | 1343:a0bee511d144 |
child | 1522:569d58d21612 |
rev | line source |
---|---|
1016
73afe3e30e97
core.loggingmanager: A new manager (yay!) to manage log output
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1 |
73afe3e30e97
core.loggingmanager: A new manager (yay!) to manage log output
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
2 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
|
3 local pcall = pcall; |
73afe3e30e97
core.loggingmanager: A new manager (yay!) to manage log output
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
4 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
|
5 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
|
6 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
|
7 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
|
8 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
|
9 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
|
10 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
|
11 |
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
|
12 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
|
13 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
|
14 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
|
15 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
|
16 |
1046
6fef969ff307
core.loggingmanager: Reinstating global log() function
Matthew Wild <mwild1@gmail.com>
parents:
1031
diff
changeset
|
17 _G.log = logger.init("general"); |
6fef969ff307
core.loggingmanager: Reinstating global log() function
Matthew Wild <mwild1@gmail.com>
parents:
1031
diff
changeset
|
18 |
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
|
19 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
|
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
|
21 -- 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
|
22 local default_logging = { { to = "console" } }; |
1344
ca74a6a38dfb
loggingmanager: Log timestamps when using default file logging
Matthew Wild <mwild1@gmail.com>
parents:
1343
diff
changeset
|
23 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
|
24 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
|
25 -- 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
|
26 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
|
27 |
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
|
28 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
|
29 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
|
30 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
|
31 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
|
32 |
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
|
33 -- 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
|
34 -- 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
|
35 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
|
36 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
|
37 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
|
38 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
|
39 -- 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
|
40 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
|
41 |
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
|
42 -- 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
|
43 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
|
44 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
|
45 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
|
46 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
|
47 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
|
48 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
|
49 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
|
50 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
|
51 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
|
52 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
|
53 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
|
54 return sink(name, level, ...); |
1021
f9122efeaadd
core.loggingmanager: Filled out most code, and cleaned up
Matthew Wild <mwild1@gmail.com>
parents:
1016
diff
changeset
|
55 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
|
56 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
|
57 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
|
58 -- 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
|
59 -- 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
|
60 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
|
61 |
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 -- 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
|
63 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
|
64 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
|
65 end |
1016
73afe3e30e97
core.loggingmanager: A new manager (yay!) to manage log output
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
66 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
|
67 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
|
68 -- No such sink type |
1016
73afe3e30e97
core.loggingmanager: A new manager (yay!) to manage log output
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
69 end |
73afe3e30e97
core.loggingmanager: A new manager (yay!) to manage log output
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
70 end |
73afe3e30e97
core.loggingmanager: A new manager (yay!) to manage log output
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
71 |
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
|
72 -- 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
|
73 -- 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
|
74 -- 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
|
75 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
|
76 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
|
77 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
|
78 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
|
79 add_rule(sink_config); |
1021
f9122efeaadd
core.loggingmanager: Filled out most code, and cleaned up
Matthew Wild <mwild1@gmail.com>
parents:
1016
diff
changeset
|
80 end |
f9122efeaadd
core.loggingmanager: Filled out most code, and cleaned up
Matthew Wild <mwild1@gmail.com>
parents:
1016
diff
changeset
|
81 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
|
82 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
|
83 -- 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
|
84 -- 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
|
85 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
|
86 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
|
87 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
|
88 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
|
89 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
|
90 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
|
91 -- 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
|
92 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
|
93 end |
f9122efeaadd
core.loggingmanager: Filled out most code, and cleaned up
Matthew Wild <mwild1@gmail.com>
parents:
1016
diff
changeset
|
94 end |
1016
73afe3e30e97
core.loggingmanager: A new manager (yay!) to manage log output
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
95 |
1021
f9122efeaadd
core.loggingmanager: Filled out most code, and cleaned up
Matthew Wild <mwild1@gmail.com>
parents:
1016
diff
changeset
|
96 |
f9122efeaadd
core.loggingmanager: Filled out most code, and cleaned up
Matthew Wild <mwild1@gmail.com>
parents:
1016
diff
changeset
|
97 |
f9122efeaadd
core.loggingmanager: Filled out most code, and cleaned up
Matthew Wild <mwild1@gmail.com>
parents:
1016
diff
changeset
|
98 --- 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
|
99 function get_levels(criteria, set) |
f9122efeaadd
core.loggingmanager: Filled out most code, and cleaned up
Matthew Wild <mwild1@gmail.com>
parents:
1016
diff
changeset
|
100 set = set or {}; |
f9122efeaadd
core.loggingmanager: Filled out most code, and cleaned up
Matthew Wild <mwild1@gmail.com>
parents:
1016
diff
changeset
|
101 if type(criteria) == "string" then |
f9122efeaadd
core.loggingmanager: Filled out most code, and cleaned up
Matthew Wild <mwild1@gmail.com>
parents:
1016
diff
changeset
|
102 set[criteria] = true; |
f9122efeaadd
core.loggingmanager: Filled out most code, and cleaned up
Matthew Wild <mwild1@gmail.com>
parents:
1016
diff
changeset
|
103 return set; |
f9122efeaadd
core.loggingmanager: Filled out most code, and cleaned up
Matthew Wild <mwild1@gmail.com>
parents:
1016
diff
changeset
|
104 end |
f9122efeaadd
core.loggingmanager: Filled out most code, and cleaned up
Matthew Wild <mwild1@gmail.com>
parents:
1016
diff
changeset
|
105 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
|
106 if min or max then |
f9122efeaadd
core.loggingmanager: Filled out most code, and cleaned up
Matthew Wild <mwild1@gmail.com>
parents:
1016
diff
changeset
|
107 local in_range; |
f9122efeaadd
core.loggingmanager: Filled out most code, and cleaned up
Matthew Wild <mwild1@gmail.com>
parents:
1016
diff
changeset
|
108 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
|
109 if min == level then |
f9122efeaadd
core.loggingmanager: Filled out most code, and cleaned up
Matthew Wild <mwild1@gmail.com>
parents:
1016
diff
changeset
|
110 set[level] = true; |
f9122efeaadd
core.loggingmanager: Filled out most code, and cleaned up
Matthew Wild <mwild1@gmail.com>
parents:
1016
diff
changeset
|
111 in_range = true; |
f9122efeaadd
core.loggingmanager: Filled out most code, and cleaned up
Matthew Wild <mwild1@gmail.com>
parents:
1016
diff
changeset
|
112 elseif max == level then |
f9122efeaadd
core.loggingmanager: Filled out most code, and cleaned up
Matthew Wild <mwild1@gmail.com>
parents:
1016
diff
changeset
|
113 set[level] = true; |
f9122efeaadd
core.loggingmanager: Filled out most code, and cleaned up
Matthew Wild <mwild1@gmail.com>
parents:
1016
diff
changeset
|
114 return set; |
f9122efeaadd
core.loggingmanager: Filled out most code, and cleaned up
Matthew Wild <mwild1@gmail.com>
parents:
1016
diff
changeset
|
115 elseif in_range then |
f9122efeaadd
core.loggingmanager: Filled out most code, and cleaned up
Matthew Wild <mwild1@gmail.com>
parents:
1016
diff
changeset
|
116 set[level] = true; |
f9122efeaadd
core.loggingmanager: Filled out most code, and cleaned up
Matthew Wild <mwild1@gmail.com>
parents:
1016
diff
changeset
|
117 end |
f9122efeaadd
core.loggingmanager: Filled out most code, and cleaned up
Matthew Wild <mwild1@gmail.com>
parents:
1016
diff
changeset
|
118 end |
f9122efeaadd
core.loggingmanager: Filled out most code, and cleaned up
Matthew Wild <mwild1@gmail.com>
parents:
1016
diff
changeset
|
119 end |
f9122efeaadd
core.loggingmanager: Filled out most code, and cleaned up
Matthew Wild <mwild1@gmail.com>
parents:
1016
diff
changeset
|
120 |
f9122efeaadd
core.loggingmanager: Filled out most code, and cleaned up
Matthew Wild <mwild1@gmail.com>
parents:
1016
diff
changeset
|
121 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
|
122 set[level] = true; |
f9122efeaadd
core.loggingmanager: Filled out most code, and cleaned up
Matthew Wild <mwild1@gmail.com>
parents:
1016
diff
changeset
|
123 end |
f9122efeaadd
core.loggingmanager: Filled out most code, and cleaned up
Matthew Wild <mwild1@gmail.com>
parents:
1016
diff
changeset
|
124 return set; |
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 |
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
|
127 --- 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
|
128 |
1080
b02290fd8a75
loggingmanager: Add a comment about 'nowhere' sink type
Matthew Wild <mwild1@gmail.com>
parents:
1078
diff
changeset
|
129 -- 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
|
130 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
|
131 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
|
132 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
|
133 |
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
|
134 -- 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
|
135 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
|
136 |
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
|
137 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
|
138 local timestamps = config.timestamps; |
24c9ee99d900
loggingmanager: Support prepending timestamps in file/console/stdout log sinks
Matthew Wild <mwild1@gmail.com>
parents:
1067
diff
changeset
|
139 |
24c9ee99d900
loggingmanager: Support prepending timestamps in file/console/stdout log sinks
Matthew Wild <mwild1@gmail.com>
parents:
1067
diff
changeset
|
140 if timestamps == true then |
24c9ee99d900
loggingmanager: Support prepending timestamps in file/console/stdout log sinks
Matthew Wild <mwild1@gmail.com>
parents:
1067
diff
changeset
|
141 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
|
142 end |
24c9ee99d900
loggingmanager: Support prepending timestamps in file/console/stdout log sinks
Matthew Wild <mwild1@gmail.com>
parents:
1067
diff
changeset
|
143 |
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
|
144 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
|
145 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
|
146 local namelen = #name; |
1078
24c9ee99d900
loggingmanager: Support prepending timestamps in file/console/stdout log sinks
Matthew Wild <mwild1@gmail.com>
parents:
1067
diff
changeset
|
147 if timestamps then |
24c9ee99d900
loggingmanager: Support prepending timestamps in file/console/stdout log sinks
Matthew Wild <mwild1@gmail.com>
parents:
1067
diff
changeset
|
148 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
|
149 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
|
150 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
|
151 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
|
152 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
|
153 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
|
154 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
|
155 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
|
156 end |
1021
f9122efeaadd
core.loggingmanager: Filled out most code, and cleaned up
Matthew Wild <mwild1@gmail.com>
parents:
1016
diff
changeset
|
157 |
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 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
|
159 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
|
160 |
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 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
|
162 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
|
163 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
|
164 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
|
165 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
|
166 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
|
167 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
|
168 -- 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
|
169 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
|
170 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
|
171 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
|
172 |
1078
24c9ee99d900
loggingmanager: Support prepending timestamps in file/console/stdout log sinks
Matthew Wild <mwild1@gmail.com>
parents:
1067
diff
changeset
|
173 local timestamps = config.timestamps; |
24c9ee99d900
loggingmanager: Support prepending timestamps in file/console/stdout log sinks
Matthew Wild <mwild1@gmail.com>
parents:
1067
diff
changeset
|
174 |
24c9ee99d900
loggingmanager: Support prepending timestamps in file/console/stdout log sinks
Matthew Wild <mwild1@gmail.com>
parents:
1067
diff
changeset
|
175 if timestamps == true then |
24c9ee99d900
loggingmanager: Support prepending timestamps in file/console/stdout log sinks
Matthew Wild <mwild1@gmail.com>
parents:
1067
diff
changeset
|
176 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
|
177 end |
24c9ee99d900
loggingmanager: Support prepending timestamps in file/console/stdout log sinks
Matthew Wild <mwild1@gmail.com>
parents:
1067
diff
changeset
|
178 |
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
|
179 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
|
180 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
|
181 local namelen = #name; |
1078
24c9ee99d900
loggingmanager: Support prepending timestamps in file/console/stdout log sinks
Matthew Wild <mwild1@gmail.com>
parents:
1067
diff
changeset
|
182 if timestamps then |
24c9ee99d900
loggingmanager: Support prepending timestamps in file/console/stdout log sinks
Matthew Wild <mwild1@gmail.com>
parents:
1067
diff
changeset
|
183 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
|
184 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
|
185 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
|
186 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
|
187 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
|
188 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
|
189 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
|
190 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
|
191 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
|
192 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
|
193 |
1117
360ec48ea780
loggingmanager: File log sinks react to reopen-log-files event
Matthew Wild <mwild1@gmail.com>
parents:
1101
diff
changeset
|
194 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
|
195 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
|
196 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
|
197 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
|
198 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
|
199 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
|
200 end |
1117
360ec48ea780
loggingmanager: File log sinks react to reopen-log-files event
Matthew Wild <mwild1@gmail.com>
parents:
1101
diff
changeset
|
201 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
|
202 |
360ec48ea780
loggingmanager: File log sinks react to reopen-log-files event
Matthew Wild <mwild1@gmail.com>
parents:
1101
diff
changeset
|
203 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
|
204 if logfile then |
360ec48ea780
loggingmanager: File log sinks react to reopen-log-files event
Matthew Wild <mwild1@gmail.com>
parents:
1101
diff
changeset
|
205 logfile:close(); |
360ec48ea780
loggingmanager: File log sinks react to reopen-log-files event
Matthew Wild <mwild1@gmail.com>
parents:
1101
diff
changeset
|
206 end |
360ec48ea780
loggingmanager: File log sinks react to reopen-log-files event
Matthew Wild <mwild1@gmail.com>
parents:
1101
diff
changeset
|
207 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
|
208 if not logfile then |
360ec48ea780
loggingmanager: File log sinks react to reopen-log-files event
Matthew Wild <mwild1@gmail.com>
parents:
1101
diff
changeset
|
209 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
|
210 else |
360ec48ea780
loggingmanager: File log sinks react to reopen-log-files event
Matthew Wild <mwild1@gmail.com>
parents:
1101
diff
changeset
|
211 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
|
212 end |
360ec48ea780
loggingmanager: File log sinks react to reopen-log-files event
Matthew Wild <mwild1@gmail.com>
parents:
1101
diff
changeset
|
213 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
|
214 |
1078
24c9ee99d900
loggingmanager: Support prepending timestamps in file/console/stdout log sinks
Matthew Wild <mwild1@gmail.com>
parents:
1067
diff
changeset
|
215 local timestamps = config.timestamps; |
24c9ee99d900
loggingmanager: Support prepending timestamps in file/console/stdout log sinks
Matthew Wild <mwild1@gmail.com>
parents:
1067
diff
changeset
|
216 |
24c9ee99d900
loggingmanager: Support prepending timestamps in file/console/stdout log sinks
Matthew Wild <mwild1@gmail.com>
parents:
1067
diff
changeset
|
217 if timestamps == true then |
24c9ee99d900
loggingmanager: Support prepending timestamps in file/console/stdout log sinks
Matthew Wild <mwild1@gmail.com>
parents:
1067
diff
changeset
|
218 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
|
219 end |
24c9ee99d900
loggingmanager: Support prepending timestamps in file/console/stdout log sinks
Matthew Wild <mwild1@gmail.com>
parents:
1067
diff
changeset
|
220 |
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
|
221 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
|
222 if timestamps then |
24c9ee99d900
loggingmanager: Support prepending timestamps in file/console/stdout log sinks
Matthew Wild <mwild1@gmail.com>
parents:
1067
diff
changeset
|
223 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
|
224 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
|
225 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
|
226 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
|
227 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
|
228 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
|
229 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
|
230 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
|
231 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
|
232 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
|
233 |
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 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
|
235 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
|
236 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
|
237 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
|
238 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
|
239 |
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 return _M; |