diff options
| author | rebecca <ubq323@ubq323.website> | 2026-09-13 14:55:10 +0100 |
|---|---|---|
| committer | rebecca <ubq323@ubq323.website> | 2026-09-13 14:55:10 +0100 |
| commit | dbb98dbb0233f8d9fd6a31849de4e297d838189a (patch) | |
| tree | 2c20dd91c59bf345e9a5cfda50a2031673a7da9b /main.lua | |
| parent | af5285331ec224b14a3de9eda7e3db648603084b (diff) | |
add Log class
Diffstat (limited to 'main.lua')
| -rw-r--r-- | main.lua | 19 |
1 files changed, 11 insertions, 8 deletions
@@ -2,9 +2,9 @@ local cqueues = require'cqueues' local class = require'r.class' local pprint = require'pprint' -local bs = require 'bs' local config = require'config' local Channel = require'channel' +local Log = require 'log' local pylon_classes = { irc = require'irc.pylon', @@ -15,17 +15,19 @@ local pylon_classes = { local Wilson = class() function Wilson.make(cls, conf) + local tlc = conf.top.level or {} local self = setmetatable({ pylons={}, busses={}, cq = cqueues.new(), + log = Log('(toplevel)',tlc.loglevel or 'info'), }, Wilson) for name, pylon_conf in pairs(conf.pylon) do pylon_conf.name = name local pylon_class = pylon_classes[pylon_conf.type] assert(pylon_class, "no such pylon type "..pylon_conf.type) self.pylons[name] = pylon_class:make(self, pylon_conf) - print("constructed pylon",name,pylon_conf.type) + self.log("constructed pylon",name,pylon_conf.type) end for name, bus_conf in pairs(conf.bus) do local bus = {} @@ -35,24 +37,25 @@ function Wilson.make(cls, conf) assert(pylon,"no such pylon named "..pylon_name) table.insert(bus, Channel(pylon, channel_descriptor)) end - print("constructed bus ",name,'with '..#bus_conf..' channels') + self.log("constructed bus ",name,'with '..#bus_conf..' channels') self.busses[name] = bus end - return self end + return self +end -- find bus containing given channel function Wilson._find_bus(self, channel) for name, bus in pairs(self.busses) do for _, q in ipairs(bus) do if q == channel then return bus end end end - print("warning: unfound bus for",channel) + self.log:warn("unfound bus for",channel) end function Wilson.deliver(self, source_channel, message) local bus = self:_find_bus(source_channel) if bus then for _, dest_channel in ipairs(bus) do if source_channel ~= dest_channel then - pprint(source_channel, "-->", dest_channel, message) + self.log:debug(source_channel, "-->", dest_channel, message) dest_channel.pylon:post(dest_channel, message) end end @@ -61,9 +64,9 @@ end function Wilson.run(self) for pylonname, pylon in pairs(self.pylons) do self.cq:wrap(pylon.run, pylon) - print("now running pylon", pylonname) + self.log("now running pylon", pylonname) end - bs.loop_correctly('(toplevel)',self.cq) + self.log:loop(self.cq) end local config_file = assert(io.open("wilson.ini","r")) |
