Comparison

plugins/mod_posix.lua @ 1033:4a9f0d482028

mod_posix: Integrate with loggingmanager, register syslog sink, remove redundant logging code
author Matthew Wild <mwild1@gmail.com>
date Wed, 22 Apr 2009 20:01:19 +0100
parent 1032:409f22d0430f
child 1042:a3d77353c18a
child 1045:06887b889b17
comparison
equal deleted inserted replaced
1032:409f22d0430f 1033:4a9f0d482028
38 pidfile_written = pidfile; 38 pidfile_written = pidfile;
39 end 39 end
40 end 40 end
41 end 41 end
42 42
43 local logfilename = config_get("*", "core", "log"); 43 local syslog_opened
44 if logfilename == "syslog" then 44 function syslog_sink_maker(config)
45 pposix.syslog_open("prosody"); 45 if not syslog_opened then
46 pposix.syslog_setminlevel(config.get("*", "core", "minimum_log_level") or "info"); 46 print("OPENING SYSLOOOOOOOOOG");
47 local syslog, format = pposix.syslog_log, string.format; 47 pposix.syslog_open("prosody");
48 logwriter = function (name, level, message, ...) 48 syslog_opened = true;
49 if ... then
50 syslog(level, format(message, ...));
51 else
52 syslog(level, message);
53 end
54 end;
55 elseif logfilename then
56 local logfile = io.open(logfilename, "a+");
57 if logfile then
58 local write, format, flush = logfile.write, string.format, logfile.flush;
59 logwriter = function (name, level, message, ...)
60 if ... then
61 write(logfile, name, "\t", level, "\t", format(message, ...), "\n");
62 else
63 write(logfile, name, "\t" , level, "\t", message, "\n");
64 end
65 flush(logfile);
66 end;
67 end 49 end
68 else 50 local syslog, format = pposix.syslog_log, string.format;
69 log("debug", "No logging specified, will continue with default"); 51 return function (name, level, message, ...)
52 if ... then
53 syslog(level, format(message, ...));
54 else
55 syslog(level, message);
56 end
57 end;
70 end 58 end
71 59 require "core.loggingmanager".register_sink_type("syslog", syslog_sink_maker);
72 if logwriter then
73 local ok, ret = logger_set(logwriter);
74 if not ok then
75 log("error", "Couldn't set new log output: %s", ret);
76 end
77 end
78 60
79 if not config_get("*", "core", "no_daemonize") then 61 if not config_get("*", "core", "no_daemonize") then
80 local function daemonize_server() 62 local function daemonize_server()
81 local logwriter;
82
83
84 local ok, ret = pposix.daemonize(); 63 local ok, ret = pposix.daemonize();
85 if not ok then 64 if not ok then
86 log("error", "Failed to daemonize: %s", ret); 65 log("error", "Failed to daemonize: %s", ret);
87 elseif ret and ret > 0 then 66 elseif ret and ret > 0 then
88 os.exit(0); 67 os.exit(0);