Software /
code /
prosody
Annotate
core/loggingmanager.lua @ 7592:10d2f008321d
net.server_epoll: Additional logging of connects and TLS
author | Kim Alvefur <zash@zash.se> |
---|---|
date | Thu, 18 Aug 2016 16:33:12 +0200 |
parent | 7163:eadbf19d0de0 |
child | 7949:8acc35b5355a |
rev | line source |
---|---|
1522
569d58d21612
Add copyright header to those files missing one
Matthew Wild <mwild1@gmail.com>
parents:
1344
diff
changeset
|
1 -- Prosody IM |
2923
b7049746bd29
Update copyright headers for 2010
Matthew Wild <mwild1@gmail.com>
parents:
2922
diff
changeset
|
2 -- Copyright (C) 2008-2010 Matthew Wild |
b7049746bd29
Update copyright headers for 2010
Matthew Wild <mwild1@gmail.com>
parents:
2922
diff
changeset
|
3 -- Copyright (C) 2008-2010 Waqas Hussain |
5776
bd0ff8ae98a8
Remove all trailing whitespace
Florian Zeitz <florob@babelmonkeys.de>
parents:
5377
diff
changeset
|
4 -- |
1522
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 |
5001
78a3d275715a
loggingmanager: Remove unused variables
Matthew Wild <mwild1@gmail.com>
parents:
4627
diff
changeset
|
10 local format = string.format; |
78a3d275715a
loggingmanager: Remove unused variables
Matthew Wild <mwild1@gmail.com>
parents:
4627
diff
changeset
|
11 local setmetatable, rawset, pairs, ipairs, type = |
78a3d275715a
loggingmanager: Remove unused variables
Matthew Wild <mwild1@gmail.com>
parents:
4627
diff
changeset
|
12 setmetatable, rawset, pairs, ipairs, type; |
7134
b7b6b1d01224
loggingmanager: Refactor the console log sink to re-use the stdout sink which in turn uses the file sink (tailcalls!)
Kim Alvefur <zash@zash.se>
parents:
7133
diff
changeset
|
13 local stdout = io.stdout; |
b7b6b1d01224
loggingmanager: Refactor the console log sink to re-use the stdout sink which in turn uses the file sink (tailcalls!)
Kim Alvefur <zash@zash.se>
parents:
7133
diff
changeset
|
14 local io_open = io.open; |
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
|
15 local math_max, rep = math.max, string.rep; |
5001
78a3d275715a
loggingmanager: Remove unused variables
Matthew Wild <mwild1@gmail.com>
parents:
4627
diff
changeset
|
16 local os_date = os.date; |
7133
ac142f5209d9
loggingmanager: Write out color code, log level and reset code in one call
Kim Alvefur <zash@zash.se>
parents:
7132
diff
changeset
|
17 local getstyle, getstring = require "util.termcolours".getstyle, require "util.termcolours".getstring; |
7139
2f9088c663c6
loggingmanager: Stringify all arguments to format so we can finally see the *real* error messages
Kim Alvefur <zash@zash.se>
parents:
7138
diff
changeset
|
18 local tostring = tostring; |
7163
eadbf19d0de0
loggingmanager,modulemanager,moduleapi: Ignore warning about accessing _G.unpack [luacheck]
Kim Alvefur <zash@zash.se>
parents:
7158
diff
changeset
|
19 local select = select; |
eadbf19d0de0
loggingmanager,modulemanager,moduleapi: Ignore warning about accessing _G.unpack [luacheck]
Kim Alvefur <zash@zash.se>
parents:
7158
diff
changeset
|
20 local unpack = table.unpack or unpack; --luacheck: ignore 113 |
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
|
21 |
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
|
22 local config = require "core.configmanager"; |
1016
73afe3e30e97
core.loggingmanager: A new manager (yay!) to manage log output
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
23 local logger = require "util.logger"; |
3358
b5a812cf698c
loggingmanager: Add reload_logging() method, which gets called on any config reload, to reset util.logger and remove and re-add all sink types to perform a full reload of the logging system without a restart.
Matthew Wild <mwild1@gmail.com>
parents:
3045
diff
changeset
|
24 local prosody = prosody; |
b5a812cf698c
loggingmanager: Add reload_logging() method, which gets called on any config reload, to reset util.logger and remove and re-add all sink types to perform a full reload of the logging system without a restart.
Matthew Wild <mwild1@gmail.com>
parents:
3045
diff
changeset
|
25 |
1046
6fef969ff307
core.loggingmanager: Reinstating global log() function
Matthew Wild <mwild1@gmail.com>
parents:
1031
diff
changeset
|
26 _G.log = logger.init("general"); |
7006
93771dad3e05
loggingmanager: Add prosody.log (intended to be used instead of _G.log now)
Matthew Wild <mwild1@gmail.com>
parents:
6779
diff
changeset
|
27 prosody.log = logger.init("general"); |
1046
6fef969ff307
core.loggingmanager: Reinstating global log() function
Matthew Wild <mwild1@gmail.com>
parents:
1031
diff
changeset
|
28 |
6779
6236668da30a
core.*: Remove use of module() function
Kim Alvefur <zash@zash.se>
parents:
6719
diff
changeset
|
29 local _ENV = nil; |
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
|
30 |
3358
b5a812cf698c
loggingmanager: Add reload_logging() method, which gets called on any config reload, to reset util.logger and remove and re-add all sink types to perform a full reload of the logging system without a restart.
Matthew Wild <mwild1@gmail.com>
parents:
3045
diff
changeset
|
31 -- The log config used if none specified in the config file (see reload_logging for initialization) |
b5a812cf698c
loggingmanager: Add reload_logging() method, which gets called on any config reload, to reset util.logger and remove and re-add all sink types to perform a full reload of the logging system without a restart.
Matthew Wild <mwild1@gmail.com>
parents:
3045
diff
changeset
|
32 local default_logging; |
b5a812cf698c
loggingmanager: Add reload_logging() method, which gets called on any config reload, to reset util.logger and remove and re-add all sink types to perform a full reload of the logging system without a restart.
Matthew Wild <mwild1@gmail.com>
parents:
3045
diff
changeset
|
33 local default_file_logging; |
7137
4a5619a87b44
loggingmanager: Write out timestamps in same write() call as everything else
Kim Alvefur <zash@zash.se>
parents:
7136
diff
changeset
|
34 local default_timestamp = "%b %d %H:%M:%S "; |
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 -- The actual config loggingmanager is using |
3358
b5a812cf698c
loggingmanager: Add reload_logging() method, which gets called on any config reload, to reset util.logger and remove and re-add all sink types to perform a full reload of the logging system without a restart.
Matthew Wild <mwild1@gmail.com>
parents:
3045
diff
changeset
|
36 local logging_config; |
1016
73afe3e30e97
core.loggingmanager: A new manager (yay!) to manage log output
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
37 |
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
|
38 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
|
39 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
|
40 local get_levels; |
4427
ae71ae5ddcfc
loggingmanager: Remove unused 'critical' level
Matthew Wild <mwild1@gmail.com>
parents:
4141
diff
changeset
|
41 local logging_levels = { "debug", "info", "warn", "error" } |
1016
73afe3e30e97
core.loggingmanager: A new manager (yay!) to manage log output
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
42 |
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
|
43 -- 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
|
44 -- 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
|
45 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
|
46 local sink_maker = log_sink_types[sink_config.to]; |
6617
a455dac79f58
loggingmanager: Improve code structure (removes empty if branch)
Matthew Wild <mwild1@gmail.com>
parents:
5776
diff
changeset
|
47 if not sink_maker then |
a455dac79f58
loggingmanager: Improve code structure (removes empty if branch)
Matthew Wild <mwild1@gmail.com>
parents:
5776
diff
changeset
|
48 return; -- No such sink type |
a455dac79f58
loggingmanager: Improve code structure (removes empty if branch)
Matthew Wild <mwild1@gmail.com>
parents:
5776
diff
changeset
|
49 end |
5776
bd0ff8ae98a8
Remove all trailing whitespace
Florian Zeitz <florob@babelmonkeys.de>
parents:
5377
diff
changeset
|
50 |
6617
a455dac79f58
loggingmanager: Improve code structure (removes empty if branch)
Matthew Wild <mwild1@gmail.com>
parents:
5776
diff
changeset
|
51 -- Create sink |
a455dac79f58
loggingmanager: Improve code structure (removes empty if branch)
Matthew Wild <mwild1@gmail.com>
parents:
5776
diff
changeset
|
52 local sink = sink_maker(sink_config); |
a455dac79f58
loggingmanager: Improve code structure (removes empty if branch)
Matthew Wild <mwild1@gmail.com>
parents:
5776
diff
changeset
|
53 |
a455dac79f58
loggingmanager: Improve code structure (removes empty if branch)
Matthew Wild <mwild1@gmail.com>
parents:
5776
diff
changeset
|
54 -- Set sink for all chosen levels |
a455dac79f58
loggingmanager: Improve code structure (removes empty if branch)
Matthew Wild <mwild1@gmail.com>
parents:
5776
diff
changeset
|
55 for level in pairs(get_levels(sink_config.levels or logging_levels)) do |
a455dac79f58
loggingmanager: Improve code structure (removes empty if branch)
Matthew Wild <mwild1@gmail.com>
parents:
5776
diff
changeset
|
56 logger.add_level_sink(level, sink); |
1016
73afe3e30e97
core.loggingmanager: A new manager (yay!) to manage log output
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
57 end |
73afe3e30e97
core.loggingmanager: A new manager (yay!) to manage log output
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
58 end |
73afe3e30e97
core.loggingmanager: A new manager (yay!) to manage log output
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
59 |
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
|
60 -- 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
|
61 -- 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
|
62 -- 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
|
63 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
|
64 if type(logging_config) == "table" then |
5776
bd0ff8ae98a8
Remove all trailing whitespace
Florian Zeitz <florob@babelmonkeys.de>
parents:
5377
diff
changeset
|
65 |
4141
ef94984c44a0
loggingmanager: Allow specifying a sink type in per-level logging config (thanks ruskie)
Matthew Wild <mwild1@gmail.com>
parents:
4140
diff
changeset
|
66 for _, level in ipairs(logging_levels) do |
ef94984c44a0
loggingmanager: Allow specifying a sink type in per-level logging config (thanks ruskie)
Matthew Wild <mwild1@gmail.com>
parents:
4140
diff
changeset
|
67 if type(logging_config[level]) == "string" then |
ef94984c44a0
loggingmanager: Allow specifying a sink type in per-level logging config (thanks ruskie)
Matthew Wild <mwild1@gmail.com>
parents:
4140
diff
changeset
|
68 local value = logging_config[level]; |
5272
1e555909f23d
core.loggingmanager: Don't create file log rules from [level] = "*sink" style config
Kim Alvefur <zash@zash.se>
parents:
5001
diff
changeset
|
69 if sink_type == "file" and not value:match("^%*") then |
3514
fdae08713c67
core.loggingmanager: Logging config simplification - allow [level] = filename and *sink to appear in the config table
Matthew Wild <mwild1@gmail.com>
parents:
3438
diff
changeset
|
70 add_rule({ |
4141
ef94984c44a0
loggingmanager: Allow specifying a sink type in per-level logging config (thanks ruskie)
Matthew Wild <mwild1@gmail.com>
parents:
4140
diff
changeset
|
71 to = sink_type; |
ef94984c44a0
loggingmanager: Allow specifying a sink type in per-level logging config (thanks ruskie)
Matthew Wild <mwild1@gmail.com>
parents:
4140
diff
changeset
|
72 filename = value; |
ef94984c44a0
loggingmanager: Allow specifying a sink type in per-level logging config (thanks ruskie)
Matthew Wild <mwild1@gmail.com>
parents:
4140
diff
changeset
|
73 timestamps = true; |
ef94984c44a0
loggingmanager: Allow specifying a sink type in per-level logging config (thanks ruskie)
Matthew Wild <mwild1@gmail.com>
parents:
4140
diff
changeset
|
74 levels = { min = level }; |
ef94984c44a0
loggingmanager: Allow specifying a sink type in per-level logging config (thanks ruskie)
Matthew Wild <mwild1@gmail.com>
parents:
4140
diff
changeset
|
75 }); |
ef94984c44a0
loggingmanager: Allow specifying a sink type in per-level logging config (thanks ruskie)
Matthew Wild <mwild1@gmail.com>
parents:
4140
diff
changeset
|
76 elseif value == "*"..sink_type then |
ef94984c44a0
loggingmanager: Allow specifying a sink type in per-level logging config (thanks ruskie)
Matthew Wild <mwild1@gmail.com>
parents:
4140
diff
changeset
|
77 add_rule({ |
ef94984c44a0
loggingmanager: Allow specifying a sink type in per-level logging config (thanks ruskie)
Matthew Wild <mwild1@gmail.com>
parents:
4140
diff
changeset
|
78 to = sink_type; |
ef94984c44a0
loggingmanager: Allow specifying a sink type in per-level logging config (thanks ruskie)
Matthew Wild <mwild1@gmail.com>
parents:
4140
diff
changeset
|
79 levels = { min = level }; |
3514
fdae08713c67
core.loggingmanager: Logging config simplification - allow [level] = filename and *sink to appear in the config table
Matthew Wild <mwild1@gmail.com>
parents:
3438
diff
changeset
|
80 }); |
fdae08713c67
core.loggingmanager: Logging config simplification - allow [level] = filename and *sink to appear in the config table
Matthew Wild <mwild1@gmail.com>
parents:
3438
diff
changeset
|
81 end |
fdae08713c67
core.loggingmanager: Logging config simplification - allow [level] = filename and *sink to appear in the config table
Matthew Wild <mwild1@gmail.com>
parents:
3438
diff
changeset
|
82 end |
fdae08713c67
core.loggingmanager: Logging config simplification - allow [level] = filename and *sink to appear in the config table
Matthew Wild <mwild1@gmail.com>
parents:
3438
diff
changeset
|
83 end |
5776
bd0ff8ae98a8
Remove all trailing whitespace
Florian Zeitz <florob@babelmonkeys.de>
parents:
5377
diff
changeset
|
84 |
4140
e463e1df1bda
loggingmanager: Iterate over logging config rules using ipairs rather than pairs
Matthew Wild <mwild1@gmail.com>
parents:
4124
diff
changeset
|
85 for _, sink_config in ipairs(logging_config) do |
3514
fdae08713c67
core.loggingmanager: Logging config simplification - allow [level] = filename and *sink to appear in the config table
Matthew Wild <mwild1@gmail.com>
parents:
3438
diff
changeset
|
86 if (type(sink_config) == "table" and sink_config.to == sink_type) 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
|
87 add_rule(sink_config); |
3514
fdae08713c67
core.loggingmanager: Logging config simplification - allow [level] = filename and *sink to appear in the config table
Matthew Wild <mwild1@gmail.com>
parents:
3438
diff
changeset
|
88 elseif (type(sink_config) == "string" and sink_config:match("^%*(.+)") == sink_type) then |
fdae08713c67
core.loggingmanager: Logging config simplification - allow [level] = filename and *sink to appear in the config table
Matthew Wild <mwild1@gmail.com>
parents:
3438
diff
changeset
|
89 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
|
90 end |
f9122efeaadd
core.loggingmanager: Filled out most code, and cleaned up
Matthew Wild <mwild1@gmail.com>
parents:
1016
diff
changeset
|
91 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
|
92 elseif type(logging_config) == "string" and (not logging_config:match("^%*")) and sink_type == "file" then |
2586
26ead5e16cd3
loggingmanager: Trailing whitespace
Matthew Wild <mwild1@gmail.com>
parents:
2139
diff
changeset
|
93 -- User specified simply a filename, and the "file" sink type |
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
|
94 -- 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
|
95 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
|
96 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
|
97 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
|
98 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
|
99 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
|
100 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
|
101 -- 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
|
102 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
|
103 end |
f9122efeaadd
core.loggingmanager: Filled out most code, and cleaned up
Matthew Wild <mwild1@gmail.com>
parents:
1016
diff
changeset
|
104 end |
1016
73afe3e30e97
core.loggingmanager: A new manager (yay!) to manage log output
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
105 |
1021
f9122efeaadd
core.loggingmanager: Filled out most code, and cleaned up
Matthew Wild <mwild1@gmail.com>
parents:
1016
diff
changeset
|
106 |
f9122efeaadd
core.loggingmanager: Filled out most code, and cleaned up
Matthew Wild <mwild1@gmail.com>
parents:
1016
diff
changeset
|
107 |
f9122efeaadd
core.loggingmanager: Filled out most code, and cleaned up
Matthew Wild <mwild1@gmail.com>
parents:
1016
diff
changeset
|
108 --- 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
|
109 function get_levels(criteria, set) |
f9122efeaadd
core.loggingmanager: Filled out most code, and cleaned up
Matthew Wild <mwild1@gmail.com>
parents:
1016
diff
changeset
|
110 set = set or {}; |
f9122efeaadd
core.loggingmanager: Filled out most code, and cleaned up
Matthew Wild <mwild1@gmail.com>
parents:
1016
diff
changeset
|
111 if type(criteria) == "string" then |
f9122efeaadd
core.loggingmanager: Filled out most code, and cleaned up
Matthew Wild <mwild1@gmail.com>
parents:
1016
diff
changeset
|
112 set[criteria] = true; |
f9122efeaadd
core.loggingmanager: Filled out most code, and cleaned up
Matthew Wild <mwild1@gmail.com>
parents:
1016
diff
changeset
|
113 return set; |
f9122efeaadd
core.loggingmanager: Filled out most code, and cleaned up
Matthew Wild <mwild1@gmail.com>
parents:
1016
diff
changeset
|
114 end |
f9122efeaadd
core.loggingmanager: Filled out most code, and cleaned up
Matthew Wild <mwild1@gmail.com>
parents:
1016
diff
changeset
|
115 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
|
116 if min or max then |
f9122efeaadd
core.loggingmanager: Filled out most code, and cleaned up
Matthew Wild <mwild1@gmail.com>
parents:
1016
diff
changeset
|
117 local in_range; |
f9122efeaadd
core.loggingmanager: Filled out most code, and cleaned up
Matthew Wild <mwild1@gmail.com>
parents:
1016
diff
changeset
|
118 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
|
119 if min == level then |
f9122efeaadd
core.loggingmanager: Filled out most code, and cleaned up
Matthew Wild <mwild1@gmail.com>
parents:
1016
diff
changeset
|
120 set[level] = true; |
f9122efeaadd
core.loggingmanager: Filled out most code, and cleaned up
Matthew Wild <mwild1@gmail.com>
parents:
1016
diff
changeset
|
121 in_range = true; |
f9122efeaadd
core.loggingmanager: Filled out most code, and cleaned up
Matthew Wild <mwild1@gmail.com>
parents:
1016
diff
changeset
|
122 elseif max == level then |
f9122efeaadd
core.loggingmanager: Filled out most code, and cleaned up
Matthew Wild <mwild1@gmail.com>
parents:
1016
diff
changeset
|
123 set[level] = true; |
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 elseif in_range then |
f9122efeaadd
core.loggingmanager: Filled out most code, and cleaned up
Matthew Wild <mwild1@gmail.com>
parents:
1016
diff
changeset
|
126 set[level] = true; |
2586
26ead5e16cd3
loggingmanager: Trailing whitespace
Matthew Wild <mwild1@gmail.com>
parents:
2139
diff
changeset
|
127 end |
1021
f9122efeaadd
core.loggingmanager: Filled out most code, and cleaned up
Matthew Wild <mwild1@gmail.com>
parents:
1016
diff
changeset
|
128 end |
f9122efeaadd
core.loggingmanager: Filled out most code, and cleaned up
Matthew Wild <mwild1@gmail.com>
parents:
1016
diff
changeset
|
129 end |
5776
bd0ff8ae98a8
Remove all trailing whitespace
Florian Zeitz <florob@babelmonkeys.de>
parents:
5377
diff
changeset
|
130 |
1021
f9122efeaadd
core.loggingmanager: Filled out most code, and cleaned up
Matthew Wild <mwild1@gmail.com>
parents:
1016
diff
changeset
|
131 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
|
132 set[level] = true; |
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 return set; |
f9122efeaadd
core.loggingmanager: Filled out most code, and cleaned up
Matthew Wild <mwild1@gmail.com>
parents:
1016
diff
changeset
|
135 end |
f9122efeaadd
core.loggingmanager: Filled out most code, and cleaned up
Matthew Wild <mwild1@gmail.com>
parents:
1016
diff
changeset
|
136 |
3358
b5a812cf698c
loggingmanager: Add reload_logging() method, which gets called on any config reload, to reset util.logger and remove and re-add all sink types to perform a full reload of the logging system without a restart.
Matthew Wild <mwild1@gmail.com>
parents:
3045
diff
changeset
|
137 -- Initialize config, etc. -- |
6779
6236668da30a
core.*: Remove use of module() function
Kim Alvefur <zash@zash.se>
parents:
6719
diff
changeset
|
138 local function reload_logging() |
3358
b5a812cf698c
loggingmanager: Add reload_logging() method, which gets called on any config reload, to reset util.logger and remove and re-add all sink types to perform a full reload of the logging system without a restart.
Matthew Wild <mwild1@gmail.com>
parents:
3045
diff
changeset
|
139 local old_sink_types = {}; |
5776
bd0ff8ae98a8
Remove all trailing whitespace
Florian Zeitz <florob@babelmonkeys.de>
parents:
5377
diff
changeset
|
140 |
3358
b5a812cf698c
loggingmanager: Add reload_logging() method, which gets called on any config reload, to reset util.logger and remove and re-add all sink types to perform a full reload of the logging system without a restart.
Matthew Wild <mwild1@gmail.com>
parents:
3045
diff
changeset
|
141 for name, sink_maker in pairs(log_sink_types) do |
b5a812cf698c
loggingmanager: Add reload_logging() method, which gets called on any config reload, to reset util.logger and remove and re-add all sink types to perform a full reload of the logging system without a restart.
Matthew Wild <mwild1@gmail.com>
parents:
3045
diff
changeset
|
142 old_sink_types[name] = sink_maker; |
b5a812cf698c
loggingmanager: Add reload_logging() method, which gets called on any config reload, to reset util.logger and remove and re-add all sink types to perform a full reload of the logging system without a restart.
Matthew Wild <mwild1@gmail.com>
parents:
3045
diff
changeset
|
143 log_sink_types[name] = nil; |
b5a812cf698c
loggingmanager: Add reload_logging() method, which gets called on any config reload, to reset util.logger and remove and re-add all sink types to perform a full reload of the logging system without a restart.
Matthew Wild <mwild1@gmail.com>
parents:
3045
diff
changeset
|
144 end |
5776
bd0ff8ae98a8
Remove all trailing whitespace
Florian Zeitz <florob@babelmonkeys.de>
parents:
5377
diff
changeset
|
145 |
3358
b5a812cf698c
loggingmanager: Add reload_logging() method, which gets called on any config reload, to reset util.logger and remove and re-add all sink types to perform a full reload of the logging system without a restart.
Matthew Wild <mwild1@gmail.com>
parents:
3045
diff
changeset
|
146 logger.reset(); |
b5a812cf698c
loggingmanager: Add reload_logging() method, which gets called on any config reload, to reset util.logger and remove and re-add all sink types to perform a full reload of the logging system without a restart.
Matthew Wild <mwild1@gmail.com>
parents:
3045
diff
changeset
|
147 |
5377
898454038524
core.*: Complete removal of all traces of the "core" section and section-related code.
Kim Alvefur <zash@zash.se>
parents:
5272
diff
changeset
|
148 local debug_mode = config.get("*", "debug"); |
4123
0c9399a66b17
loggingmanager: Re-read 'debug' option on reload.
Waqas Hussain <waqas20@gmail.com>
parents:
4117
diff
changeset
|
149 |
3358
b5a812cf698c
loggingmanager: Add reload_logging() method, which gets called on any config reload, to reset util.logger and remove and re-add all sink types to perform a full reload of the logging system without a restart.
Matthew Wild <mwild1@gmail.com>
parents:
3045
diff
changeset
|
150 default_logging = { { to = "console" , levels = { min = (debug_mode and "debug") or "info" } } }; |
3514
fdae08713c67
core.loggingmanager: Logging config simplification - allow [level] = filename and *sink to appear in the config table
Matthew Wild <mwild1@gmail.com>
parents:
3438
diff
changeset
|
151 default_file_logging = { |
3540
bc139431830b
Monster whitespace commit (beware the whitespace monster).
Waqas Hussain <waqas20@gmail.com>
parents:
3514
diff
changeset
|
152 { to = "file", levels = { min = (debug_mode and "debug") or "info" }, timestamps = true } |
3514
fdae08713c67
core.loggingmanager: Logging config simplification - allow [level] = filename and *sink to appear in the config table
Matthew Wild <mwild1@gmail.com>
parents:
3438
diff
changeset
|
153 }; |
3358
b5a812cf698c
loggingmanager: Add reload_logging() method, which gets called on any config reload, to reset util.logger and remove and re-add all sink types to perform a full reload of the logging system without a restart.
Matthew Wild <mwild1@gmail.com>
parents:
3045
diff
changeset
|
154 |
5377
898454038524
core.*: Complete removal of all traces of the "core" section and section-related code.
Kim Alvefur <zash@zash.se>
parents:
5272
diff
changeset
|
155 logging_config = config.get("*", "log") or default_logging; |
5776
bd0ff8ae98a8
Remove all trailing whitespace
Florian Zeitz <florob@babelmonkeys.de>
parents:
5377
diff
changeset
|
156 |
3358
b5a812cf698c
loggingmanager: Add reload_logging() method, which gets called on any config reload, to reset util.logger and remove and re-add all sink types to perform a full reload of the logging system without a restart.
Matthew Wild <mwild1@gmail.com>
parents:
3045
diff
changeset
|
157 for name, sink_maker in pairs(old_sink_types) do |
b5a812cf698c
loggingmanager: Add reload_logging() method, which gets called on any config reload, to reset util.logger and remove and re-add all sink types to perform a full reload of the logging system without a restart.
Matthew Wild <mwild1@gmail.com>
parents:
3045
diff
changeset
|
158 log_sink_types[name] = sink_maker; |
b5a812cf698c
loggingmanager: Add reload_logging() method, which gets called on any config reload, to reset util.logger and remove and re-add all sink types to perform a full reload of the logging system without a restart.
Matthew Wild <mwild1@gmail.com>
parents:
3045
diff
changeset
|
159 end |
5776
bd0ff8ae98a8
Remove all trailing whitespace
Florian Zeitz <florob@babelmonkeys.de>
parents:
5377
diff
changeset
|
160 |
3358
b5a812cf698c
loggingmanager: Add reload_logging() method, which gets called on any config reload, to reset util.logger and remove and re-add all sink types to perform a full reload of the logging system without a restart.
Matthew Wild <mwild1@gmail.com>
parents:
3045
diff
changeset
|
161 prosody.events.fire_event("logging-reloaded"); |
b5a812cf698c
loggingmanager: Add reload_logging() method, which gets called on any config reload, to reset util.logger and remove and re-add all sink types to perform a full reload of the logging system without a restart.
Matthew Wild <mwild1@gmail.com>
parents:
3045
diff
changeset
|
162 end |
b5a812cf698c
loggingmanager: Add reload_logging() method, which gets called on any config reload, to reset util.logger and remove and re-add all sink types to perform a full reload of the logging system without a restart.
Matthew Wild <mwild1@gmail.com>
parents:
3045
diff
changeset
|
163 |
b5a812cf698c
loggingmanager: Add reload_logging() method, which gets called on any config reload, to reset util.logger and remove and re-add all sink types to perform a full reload of the logging system without a restart.
Matthew Wild <mwild1@gmail.com>
parents:
3045
diff
changeset
|
164 reload_logging(); |
b5a812cf698c
loggingmanager: Add reload_logging() method, which gets called on any config reload, to reset util.logger and remove and re-add all sink types to perform a full reload of the logging system without a restart.
Matthew Wild <mwild1@gmail.com>
parents:
3045
diff
changeset
|
165 prosody.events.add_handler("config-reloaded", reload_logging); |
b5a812cf698c
loggingmanager: Add reload_logging() method, which gets called on any config reload, to reset util.logger and remove and re-add all sink types to perform a full reload of the logging system without a restart.
Matthew Wild <mwild1@gmail.com>
parents:
3045
diff
changeset
|
166 |
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
|
167 --- 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
|
168 |
1080
b02290fd8a75
loggingmanager: Add a comment about 'nowhere' sink type
Matthew Wild <mwild1@gmail.com>
parents:
1078
diff
changeset
|
169 -- Null sink, must enter log_sink_types *first* |
7134
b7b6b1d01224
loggingmanager: Refactor the console log sink to re-use the stdout sink which in turn uses the file sink (tailcalls!)
Kim Alvefur <zash@zash.se>
parents:
7133
diff
changeset
|
170 local function log_to_nowhere() |
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
|
171 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
|
172 end |
7134
b7b6b1d01224
loggingmanager: Refactor the console log sink to re-use the stdout sink which in turn uses the file sink (tailcalls!)
Kim Alvefur <zash@zash.se>
parents:
7133
diff
changeset
|
173 log_sink_types.nowhere = log_to_nowhere; |
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
|
174 |
7134
b7b6b1d01224
loggingmanager: Refactor the console log sink to re-use the stdout sink which in turn uses the file sink (tailcalls!)
Kim Alvefur <zash@zash.se>
parents:
7133
diff
changeset
|
175 local function log_to_file(sink_config, logfile) |
b7b6b1d01224
loggingmanager: Refactor the console log sink to re-use the stdout sink which in turn uses the file sink (tailcalls!)
Kim Alvefur <zash@zash.se>
parents:
7133
diff
changeset
|
176 logfile = logfile or io_open(sink_config.filename, "a+"); |
b7b6b1d01224
loggingmanager: Refactor the console log sink to re-use the stdout sink which in turn uses the file sink (tailcalls!)
Kim Alvefur <zash@zash.se>
parents:
7133
diff
changeset
|
177 if not logfile then |
b7b6b1d01224
loggingmanager: Refactor the console log sink to re-use the stdout sink which in turn uses the file sink (tailcalls!)
Kim Alvefur <zash@zash.se>
parents:
7133
diff
changeset
|
178 return log_to_nowhere(sink_config); |
b7b6b1d01224
loggingmanager: Refactor the console log sink to re-use the stdout sink which in turn uses the file sink (tailcalls!)
Kim Alvefur <zash@zash.se>
parents:
7133
diff
changeset
|
179 end |
b7b6b1d01224
loggingmanager: Refactor the console log sink to re-use the stdout sink which in turn uses the file sink (tailcalls!)
Kim Alvefur <zash@zash.se>
parents:
7133
diff
changeset
|
180 local write = logfile.write; |
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
|
181 |
6719
0ef7a8c8fe8c
loggingmanager: Rename function arguments to avoid name conflict [luacheck] (core/ is now luacheck-clean!)
Matthew Wild <mwild1@gmail.com>
parents:
6617
diff
changeset
|
182 local timestamps = sink_config.timestamps; |
5776
bd0ff8ae98a8
Remove all trailing whitespace
Florian Zeitz <florob@babelmonkeys.de>
parents:
5377
diff
changeset
|
183 |
1078
24c9ee99d900
loggingmanager: Support prepending timestamps in file/console/stdout log sinks
Matthew Wild <mwild1@gmail.com>
parents:
1067
diff
changeset
|
184 if timestamps == true then |
24c9ee99d900
loggingmanager: Support prepending timestamps in file/console/stdout log sinks
Matthew Wild <mwild1@gmail.com>
parents:
1067
diff
changeset
|
185 timestamps = default_timestamp; -- Default format |
7137
4a5619a87b44
loggingmanager: Write out timestamps in same write() call as everything else
Kim Alvefur <zash@zash.se>
parents:
7136
diff
changeset
|
186 elseif timestamps then |
4a5619a87b44
loggingmanager: Write out timestamps in same write() call as everything else
Kim Alvefur <zash@zash.se>
parents:
7136
diff
changeset
|
187 timestamps = timestamps .. " "; |
1078
24c9ee99d900
loggingmanager: Support prepending timestamps in file/console/stdout log sinks
Matthew Wild <mwild1@gmail.com>
parents:
1067
diff
changeset
|
188 end |
5776
bd0ff8ae98a8
Remove all trailing whitespace
Florian Zeitz <florob@babelmonkeys.de>
parents:
5377
diff
changeset
|
189 |
7125
631c47a65519
loggingmanager: Call setvbuf on output files, defaulting to line-buffered, instead of manually calling flush(). Adds 'buffer_mode' option to sink configuration for stdout, console and file sinks.
Matthew Wild <mwild1@gmail.com>
parents:
7006
diff
changeset
|
190 if sink_config.buffer_mode ~= false then |
631c47a65519
loggingmanager: Call setvbuf on output files, defaulting to line-buffered, instead of manually calling flush(). Adds 'buffer_mode' option to sink configuration for stdout, console and file sinks.
Matthew Wild <mwild1@gmail.com>
parents:
7006
diff
changeset
|
191 logfile:setvbuf(sink_config.buffer_mode or "line"); |
631c47a65519
loggingmanager: Call setvbuf on output files, defaulting to line-buffered, instead of manually calling flush(). Adds 'buffer_mode' option to sink configuration for stdout, console and file sinks.
Matthew Wild <mwild1@gmail.com>
parents:
7006
diff
changeset
|
192 end |
631c47a65519
loggingmanager: Call setvbuf on output files, defaulting to line-buffered, instead of manually calling flush(). Adds 'buffer_mode' option to sink configuration for stdout, console and file sinks.
Matthew Wild <mwild1@gmail.com>
parents:
7006
diff
changeset
|
193 |
7135
0b614b7333f1
loggingmanager: Move logic for adaptive column width into file sink, append tab if disabled (fixes separation between name and level in plain file sinks)
Kim Alvefur <zash@zash.se>
parents:
7134
diff
changeset
|
194 -- Column width for "source" (used by stdout and console) |
0b614b7333f1
loggingmanager: Move logic for adaptive column width into file sink, append tab if disabled (fixes separation between name and level in plain file sinks)
Kim Alvefur <zash@zash.se>
parents:
7134
diff
changeset
|
195 local sourcewidth = sink_config.source_width; |
0b614b7333f1
loggingmanager: Move logic for adaptive column width into file sink, append tab if disabled (fixes separation between name and level in plain file sinks)
Kim Alvefur <zash@zash.se>
parents:
7134
diff
changeset
|
196 |
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
|
197 return function (name, level, message, ...) |
7139
2f9088c663c6
loggingmanager: Stringify all arguments to format so we can finally see the *real* error messages
Kim Alvefur <zash@zash.se>
parents:
7138
diff
changeset
|
198 local n = select('#', ...); |
2f9088c663c6
loggingmanager: Stringify all arguments to format so we can finally see the *real* error messages
Kim Alvefur <zash@zash.se>
parents:
7138
diff
changeset
|
199 if n ~= 0 then |
2f9088c663c6
loggingmanager: Stringify all arguments to format so we can finally see the *real* error messages
Kim Alvefur <zash@zash.se>
parents:
7138
diff
changeset
|
200 local arg = { ... }; |
2f9088c663c6
loggingmanager: Stringify all arguments to format so we can finally see the *real* error messages
Kim Alvefur <zash@zash.se>
parents:
7138
diff
changeset
|
201 for i = 1, n do |
2f9088c663c6
loggingmanager: Stringify all arguments to format so we can finally see the *real* error messages
Kim Alvefur <zash@zash.se>
parents:
7138
diff
changeset
|
202 arg[i] = tostring(arg[i]); |
2f9088c663c6
loggingmanager: Stringify all arguments to format so we can finally see the *real* error messages
Kim Alvefur <zash@zash.se>
parents:
7138
diff
changeset
|
203 end |
2f9088c663c6
loggingmanager: Stringify all arguments to format so we can finally see the *real* error messages
Kim Alvefur <zash@zash.se>
parents:
7138
diff
changeset
|
204 message = format(message, unpack(arg, 1, n)); |
2f9088c663c6
loggingmanager: Stringify all arguments to format so we can finally see the *real* error messages
Kim Alvefur <zash@zash.se>
parents:
7138
diff
changeset
|
205 end |
2f9088c663c6
loggingmanager: Stringify all arguments to format so we can finally see the *real* error messages
Kim Alvefur <zash@zash.se>
parents:
7138
diff
changeset
|
206 |
7135
0b614b7333f1
loggingmanager: Move logic for adaptive column width into file sink, append tab if disabled (fixes separation between name and level in plain file sinks)
Kim Alvefur <zash@zash.se>
parents:
7134
diff
changeset
|
207 if sourcewidth then |
0b614b7333f1
loggingmanager: Move logic for adaptive column width into file sink, append tab if disabled (fixes separation between name and level in plain file sinks)
Kim Alvefur <zash@zash.se>
parents:
7134
diff
changeset
|
208 sourcewidth = math_max(#name+2, sourcewidth); |
0b614b7333f1
loggingmanager: Move logic for adaptive column width into file sink, append tab if disabled (fixes separation between name and level in plain file sinks)
Kim Alvefur <zash@zash.se>
parents:
7134
diff
changeset
|
209 name = name .. rep(" ", sourcewidth-#name); |
0b614b7333f1
loggingmanager: Move logic for adaptive column width into file sink, append tab if disabled (fixes separation between name and level in plain file sinks)
Kim Alvefur <zash@zash.se>
parents:
7134
diff
changeset
|
210 else |
0b614b7333f1
loggingmanager: Move logic for adaptive column width into file sink, append tab if disabled (fixes separation between name and level in plain file sinks)
Kim Alvefur <zash@zash.se>
parents:
7134
diff
changeset
|
211 name = name .. "\t"; |
0b614b7333f1
loggingmanager: Move logic for adaptive column width into file sink, append tab if disabled (fixes separation between name and level in plain file sinks)
Kim Alvefur <zash@zash.se>
parents:
7134
diff
changeset
|
212 end |
7139
2f9088c663c6
loggingmanager: Stringify all arguments to format so we can finally see the *real* error messages
Kim Alvefur <zash@zash.se>
parents:
7138
diff
changeset
|
213 write(logfile, timestamps and os_date(timestamps) or "", name, level, "\t", message, "\n"); |
7134
b7b6b1d01224
loggingmanager: Refactor the console log sink to re-use the stdout sink which in turn uses the file sink (tailcalls!)
Kim Alvefur <zash@zash.se>
parents:
7133
diff
changeset
|
214 end |
b7b6b1d01224
loggingmanager: Refactor the console log sink to re-use the stdout sink which in turn uses the file sink (tailcalls!)
Kim Alvefur <zash@zash.se>
parents:
7133
diff
changeset
|
215 end |
b7b6b1d01224
loggingmanager: Refactor the console log sink to re-use the stdout sink which in turn uses the file sink (tailcalls!)
Kim Alvefur <zash@zash.se>
parents:
7133
diff
changeset
|
216 log_sink_types.file = log_to_file; |
b7b6b1d01224
loggingmanager: Refactor the console log sink to re-use the stdout sink which in turn uses the file sink (tailcalls!)
Kim Alvefur <zash@zash.se>
parents:
7133
diff
changeset
|
217 |
b7b6b1d01224
loggingmanager: Refactor the console log sink to re-use the stdout sink which in turn uses the file sink (tailcalls!)
Kim Alvefur <zash@zash.se>
parents:
7133
diff
changeset
|
218 local function log_to_stdout(sink_config) |
b7b6b1d01224
loggingmanager: Refactor the console log sink to re-use the stdout sink which in turn uses the file sink (tailcalls!)
Kim Alvefur <zash@zash.se>
parents:
7133
diff
changeset
|
219 if not sink_config.timestamps then |
b7b6b1d01224
loggingmanager: Refactor the console log sink to re-use the stdout sink which in turn uses the file sink (tailcalls!)
Kim Alvefur <zash@zash.se>
parents:
7133
diff
changeset
|
220 sink_config.timestamps = false; |
b7b6b1d01224
loggingmanager: Refactor the console log sink to re-use the stdout sink which in turn uses the file sink (tailcalls!)
Kim Alvefur <zash@zash.se>
parents:
7133
diff
changeset
|
221 end |
7136
6c3a33e54399
loggingmanager: Make initial value for width of log name configurable
Kim Alvefur <zash@zash.se>
parents:
7135
diff
changeset
|
222 if sink_config.source_width == nil then |
6c3a33e54399
loggingmanager: Make initial value for width of log name configurable
Kim Alvefur <zash@zash.se>
parents:
7135
diff
changeset
|
223 sink_config.source_width = 20; |
6c3a33e54399
loggingmanager: Make initial value for width of log name configurable
Kim Alvefur <zash@zash.se>
parents:
7135
diff
changeset
|
224 end |
7135
0b614b7333f1
loggingmanager: Move logic for adaptive column width into file sink, append tab if disabled (fixes separation between name and level in plain file sinks)
Kim Alvefur <zash@zash.se>
parents:
7134
diff
changeset
|
225 return log_to_file(sink_config, stdout); |
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
|
226 end |
7134
b7b6b1d01224
loggingmanager: Refactor the console log sink to re-use the stdout sink which in turn uses the file sink (tailcalls!)
Kim Alvefur <zash@zash.se>
parents:
7133
diff
changeset
|
227 log_sink_types.stdout = log_to_stdout; |
b7b6b1d01224
loggingmanager: Refactor the console log sink to re-use the stdout sink which in turn uses the file sink (tailcalls!)
Kim Alvefur <zash@zash.se>
parents:
7133
diff
changeset
|
228 |
b7b6b1d01224
loggingmanager: Refactor the console log sink to re-use the stdout sink which in turn uses the file sink (tailcalls!)
Kim Alvefur <zash@zash.se>
parents:
7133
diff
changeset
|
229 local do_pretty_printing = true; |
b7b6b1d01224
loggingmanager: Refactor the console log sink to re-use the stdout sink which in turn uses the file sink (tailcalls!)
Kim Alvefur <zash@zash.se>
parents:
7133
diff
changeset
|
230 |
b7b6b1d01224
loggingmanager: Refactor the console log sink to re-use the stdout sink which in turn uses the file sink (tailcalls!)
Kim Alvefur <zash@zash.se>
parents:
7133
diff
changeset
|
231 local logstyles; |
b7b6b1d01224
loggingmanager: Refactor the console log sink to re-use the stdout sink which in turn uses the file sink (tailcalls!)
Kim Alvefur <zash@zash.se>
parents:
7133
diff
changeset
|
232 if do_pretty_printing then |
b7b6b1d01224
loggingmanager: Refactor the console log sink to re-use the stdout sink which in turn uses the file sink (tailcalls!)
Kim Alvefur <zash@zash.se>
parents:
7133
diff
changeset
|
233 logstyles = {}; |
b7b6b1d01224
loggingmanager: Refactor the console log sink to re-use the stdout sink which in turn uses the file sink (tailcalls!)
Kim Alvefur <zash@zash.se>
parents:
7133
diff
changeset
|
234 logstyles["info"] = getstyle("bold"); |
b7b6b1d01224
loggingmanager: Refactor the console log sink to re-use the stdout sink which in turn uses the file sink (tailcalls!)
Kim Alvefur <zash@zash.se>
parents:
7133
diff
changeset
|
235 logstyles["warn"] = getstyle("bold", "yellow"); |
b7b6b1d01224
loggingmanager: Refactor the console log sink to re-use the stdout sink which in turn uses the file sink (tailcalls!)
Kim Alvefur <zash@zash.se>
parents:
7133
diff
changeset
|
236 logstyles["error"] = getstyle("bold", "red"); |
b7b6b1d01224
loggingmanager: Refactor the console log sink to re-use the stdout sink which in turn uses the file sink (tailcalls!)
Kim Alvefur <zash@zash.se>
parents:
7133
diff
changeset
|
237 end |
b7b6b1d01224
loggingmanager: Refactor the console log sink to re-use the stdout sink which in turn uses the file sink (tailcalls!)
Kim Alvefur <zash@zash.se>
parents:
7133
diff
changeset
|
238 |
b7b6b1d01224
loggingmanager: Refactor the console log sink to re-use the stdout sink which in turn uses the file sink (tailcalls!)
Kim Alvefur <zash@zash.se>
parents:
7133
diff
changeset
|
239 local function log_to_console(sink_config) |
b7b6b1d01224
loggingmanager: Refactor the console log sink to re-use the stdout sink which in turn uses the file sink (tailcalls!)
Kim Alvefur <zash@zash.se>
parents:
7133
diff
changeset
|
240 -- Really if we don't want pretty colours then just use plain stdout |
b7b6b1d01224
loggingmanager: Refactor the console log sink to re-use the stdout sink which in turn uses the file sink (tailcalls!)
Kim Alvefur <zash@zash.se>
parents:
7133
diff
changeset
|
241 local logstdout = log_to_stdout(sink_config); |
b7b6b1d01224
loggingmanager: Refactor the console log sink to re-use the stdout sink which in turn uses the file sink (tailcalls!)
Kim Alvefur <zash@zash.se>
parents:
7133
diff
changeset
|
242 if not do_pretty_printing then |
b7b6b1d01224
loggingmanager: Refactor the console log sink to re-use the stdout sink which in turn uses the file sink (tailcalls!)
Kim Alvefur <zash@zash.se>
parents:
7133
diff
changeset
|
243 return logstdout; |
b7b6b1d01224
loggingmanager: Refactor the console log sink to re-use the stdout sink which in turn uses the file sink (tailcalls!)
Kim Alvefur <zash@zash.se>
parents:
7133
diff
changeset
|
244 end |
b7b6b1d01224
loggingmanager: Refactor the console log sink to re-use the stdout sink which in turn uses the file sink (tailcalls!)
Kim Alvefur <zash@zash.se>
parents:
7133
diff
changeset
|
245 return function (name, level, message, ...) |
b7b6b1d01224
loggingmanager: Refactor the console log sink to re-use the stdout sink which in turn uses the file sink (tailcalls!)
Kim Alvefur <zash@zash.se>
parents:
7133
diff
changeset
|
246 local logstyle = logstyles[level]; |
b7b6b1d01224
loggingmanager: Refactor the console log sink to re-use the stdout sink which in turn uses the file sink (tailcalls!)
Kim Alvefur <zash@zash.se>
parents:
7133
diff
changeset
|
247 if logstyle then |
b7b6b1d01224
loggingmanager: Refactor the console log sink to re-use the stdout sink which in turn uses the file sink (tailcalls!)
Kim Alvefur <zash@zash.se>
parents:
7133
diff
changeset
|
248 level = getstring(logstyle, level); |
b7b6b1d01224
loggingmanager: Refactor the console log sink to re-use the stdout sink which in turn uses the file sink (tailcalls!)
Kim Alvefur <zash@zash.se>
parents:
7133
diff
changeset
|
249 end |
b7b6b1d01224
loggingmanager: Refactor the console log sink to re-use the stdout sink which in turn uses the file sink (tailcalls!)
Kim Alvefur <zash@zash.se>
parents:
7133
diff
changeset
|
250 return logstdout(name, level, message, ...); |
b7b6b1d01224
loggingmanager: Refactor the console log sink to re-use the stdout sink which in turn uses the file sink (tailcalls!)
Kim Alvefur <zash@zash.se>
parents:
7133
diff
changeset
|
251 end |
b7b6b1d01224
loggingmanager: Refactor the console log sink to re-use the stdout sink which in turn uses the file sink (tailcalls!)
Kim Alvefur <zash@zash.se>
parents:
7133
diff
changeset
|
252 end |
b7b6b1d01224
loggingmanager: Refactor the console log sink to re-use the stdout sink which in turn uses the file sink (tailcalls!)
Kim Alvefur <zash@zash.se>
parents:
7133
diff
changeset
|
253 log_sink_types.console = log_to_console; |
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
|
254 |
6779
6236668da30a
core.*: Remove use of module() function
Kim Alvefur <zash@zash.se>
parents:
6719
diff
changeset
|
255 local function register_sink_type(name, sink_maker) |
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
|
256 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
|
257 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
|
258 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
|
259 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
|
260 |
6779
6236668da30a
core.*: Remove use of module() function
Kim Alvefur <zash@zash.se>
parents:
6719
diff
changeset
|
261 return { |
6236668da30a
core.*: Remove use of module() function
Kim Alvefur <zash@zash.se>
parents:
6719
diff
changeset
|
262 reload_logging = reload_logging; |
6236668da30a
core.*: Remove use of module() function
Kim Alvefur <zash@zash.se>
parents:
6719
diff
changeset
|
263 register_sink_type = register_sink_type; |
6236668da30a
core.*: Remove use of module() function
Kim Alvefur <zash@zash.se>
parents:
6719
diff
changeset
|
264 } |