Mercurial > prosody-hg
comparison util/logger.lua @ 883:0112ae30f399
Support to filter logging by source via pattern matching from config file.
| author | Tobias Markmann <tm@ayena.de> |
|---|---|
| date | Sat, 07 Mar 2009 20:33:21 +0100 |
| parents | 5fbbf34ef1c4 |
| children | 5758c39285ab |
comparison
equal
deleted
inserted
replaced
| 882:e362bafbbb68 | 883:0112ae30f399 |
|---|---|
| 11 local pcall = pcall; | 11 local pcall = pcall; |
| 12 local debug = debug; | 12 local debug = debug; |
| 13 local tostring = tostring; | 13 local tostring = tostring; |
| 14 local math_max = math.max; | 14 local math_max = math.max; |
| 15 | 15 |
| 16 local config = require "core.configmanager"; | |
| 17 local log_sources = config.get("*", "core", "log_sources"); | |
| 18 | |
| 16 local getstyle, getstring = require "util.termcolours".getstyle, require "util.termcolours".getstring; | 19 local getstyle, getstring = require "util.termcolours".getstyle, require "util.termcolours".getstring; |
| 17 local do_pretty_printing = not os.getenv("WINDIR"); | 20 local do_pretty_printing = not os.getenv("WINDIR"); |
| 21 local find = require "string".find; | |
| 22 local ipairs = ipairs; | |
| 18 | 23 |
| 19 module "logger" | 24 module "logger" |
| 20 | 25 |
| 21 local logstyles = {}; | 26 local logstyles = {}; |
| 22 | 27 |
| 30 local sourcewidth = 20; | 35 local sourcewidth = 20; |
| 31 | 36 |
| 32 local outfunction = nil; | 37 local outfunction = nil; |
| 33 | 38 |
| 34 function init(name) | 39 function init(name) |
| 40 if log_sources then | |
| 41 local log_this = false; | |
| 42 for _, source in ipairs(log_sources) do | |
| 43 if find(name, source) then | |
| 44 log_this = true | |
| 45 break | |
| 46 end | |
| 47 end | |
| 48 | |
| 49 if not log_this then return function () end end | |
| 50 end | |
| 51 | |
| 35 --name = nil; -- While this line is not commented, will automatically fill in file/line number info | 52 --name = nil; -- While this line is not commented, will automatically fill in file/line number info |
| 36 local namelen = #name; | 53 local namelen = #name; |
| 37 return function (level, message, ...) | 54 return function (level, message, ...) |
| 38 if outfunction then return outfunction(name, level, message, ...); end | 55 if outfunction then return outfunction(name, level, message, ...); end |
| 39 | 56 |
