Comparison

init.lua @ 461:fa5c40e5e079

Use util.format for logging
author Matthew Wild <mwild1@gmail.com>
date Thu, 16 Mar 2023 11:46:16 +0000
parent 444:12c1be0044c6
child 463:98fe3ed54639
comparison
equal deleted inserted replaced
460:a523535d8937 461:fa5c40e5e079
8 pcall(require, "ssl"); 8 pcall(require, "ssl");
9 9
10 local server = require "net.server"; 10 local server = require "net.server";
11 local events = require "util.events"; 11 local events = require "util.events";
12 local logger = require "util.logger"; 12 local logger = require "util.logger";
13
14 local format = require "util.format".format;
13 15
14 local verse = {}; 16 local verse = {};
15 verse.server = server; 17 verse.server = server;
16 18
17 local stream = {}; 19 local stream = {};
48 50
49 verse.logger = logger.init; -- COMPAT: Deprecated 51 verse.logger = logger.init; -- COMPAT: Deprecated
50 verse.new_logger = logger.init; 52 verse.new_logger = logger.init;
51 verse.log = verse.logger("verse"); 53 verse.log = verse.logger("verse");
52 54
53 local function format(format, ...)
54 local n, arg, maxn = 0, { ... }, select('#', ...);
55 return (format:gsub("%%(.)", function (c) if n <= maxn then n = n + 1; return tostring(arg[n]); end end));
56 end
57
58 function verse.set_log_handler(log_handler, levels) 55 function verse.set_log_handler(log_handler, levels)
59 levels = levels or { "debug", "info", "warn", "error" }; 56 levels = levels or { "debug", "info", "warn", "error" };
60 logger.reset(); 57 logger.reset();
61 if io.type(log_handler) == "file" then 58 if io.type(log_handler) == "file" then
62 local f = log_handler; 59 local f = log_handler;