55-- - when conn is set (after start), publishes log entries to {'logs', <level>}
66-- - publishes service lifecycle status to {'svc', <name>, 'status'}
77
8- local rxilog = require ' rxilog'
9- local runtime = require ' fibers.runtime'
10- local fibers = require ' fibers'
11- local sleep = require ' fibers.sleep'
12- local perform = require ' fibers.performer' .perform
8+ local rxilog = require ' rxilog'
9+ local runtime = require ' fibers.runtime'
10+ local fibers = require ' fibers'
11+ local sleep = require ' fibers.sleep'
12+ local perform = require ' fibers.performer' .perform
13+ local time_utils = require ' fibers.utils.time'
1314
1415local log_service = {}
1516
17+ --- @return (string | number )[]
1618local function t (...)
1719 return { ... }
1820end
1921
22+ --- @return number
2023local function now ()
2124 return runtime .now ()
2225end
2326
27+ --- @param conn Connection
28+ --- @param name string
29+ --- @param state string
30+ --- @param extra table ?
2431local function publish_status (conn , name , state , extra )
2532 local payload = { state = state , ts = now () }
2633 if type (extra ) == ' table' then
@@ -39,7 +46,6 @@ for _, mode in ipairs(rxilog.modes) do
3946 if log_service ._conn then
4047 local info = debug.getinfo (2 , " Sl" )
4148 local lineinfo = info .short_src .. " :" .. info .currentline
42- local time_utils = require ' fibers.utils.time'
4349 log_service ._conn :publish (t (' logs' , level ), {
4450 message = rxilog .format_log_message (level :upper (), lineinfo , msg ),
4551 timestamp = time_utils .realtime (),
@@ -48,6 +54,8 @@ for _, mode in ipairs(rxilog.modes) do
4854 end
4955end
5056
57+ --- @param conn Connection
58+ --- @param opts { name : string ?}?
5159function log_service .start (conn , opts )
5260 opts = opts or {}
5361 local name = opts .name or ' log'
@@ -60,8 +68,8 @@ function log_service.start(conn, opts)
6068 rxilog .trace (" Log: stopped" )
6169 end )
6270
63- log_service ._conn = conn
64- log_service ._name = name
71+ log_service ._conn = conn
72+ log_service ._name = name
6573
6674 publish_status (conn , name , ' running' )
6775 log_service .trace (" Log service started" )
0 commit comments