123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657 |
- --[[
- Descripttion:
- version:
- Author: Neo,Huang
- Date: 2022-07-04 15:20:47
- LastEditors: Neo,Huang
- LastEditTime: 2022-07-04 15:21:23
- --]]
- local skynet = require "skynet"
- require "skynet.manager"
- local queue = require "skynet.queue"
- local cs = queue()
- local LOGGER = {}
- local CMD = {}
- local function open(filename)
- local handle = LOGGER[filename]
- if handle then
- return handle
- end
- handle = skynet.launch("jmlogger", filename)
- LOGGER[filename] = handle
- return handle
- end
- local function close(filename)
- if LOGGER[filename] then
- skynet.error("close logger ", filename)
- skynet.kill(LOGGER[filename])
- LOGGER[filename] = nil
- end
- end
- function CMD.open(filename)
- return cs(open, filename)
- end
- function CMD.close(filename)
- return cs(close, filename)
- end
- skynet.start(
- function()
- skynet.register(".jmlogger")
- skynet.dispatch(
- "lua",
- function(session, _, command, ...)
- local f = CMD[command]
- if session == 0 then
- return f(...)
- end
- skynet.ret(skynet.pack(f(...)))
- end
- )
- end
- )
|