srvLoggerMgr.lua 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. --[[
  2. Descripttion:
  3. version:
  4. Author: Neo,Huang
  5. Date: 2022-07-04 15:20:47
  6. LastEditors: Neo,Huang
  7. LastEditTime: 2022-07-04 15:21:23
  8. --]]
  9. local skynet = require "skynet"
  10. require "skynet.manager"
  11. local queue = require "skynet.queue"
  12. local cs = queue()
  13. local LOGGER = {}
  14. local CMD = {}
  15. local function open(filename)
  16. local handle = LOGGER[filename]
  17. if handle then
  18. return handle
  19. end
  20. handle = skynet.launch("jmlogger", filename)
  21. LOGGER[filename] = handle
  22. return handle
  23. end
  24. local function close(filename)
  25. if LOGGER[filename] then
  26. skynet.error("close logger ", filename)
  27. skynet.kill(LOGGER[filename])
  28. LOGGER[filename] = nil
  29. end
  30. end
  31. function CMD.open(filename)
  32. return cs(open, filename)
  33. end
  34. function CMD.close(filename)
  35. return cs(close, filename)
  36. end
  37. skynet.start(
  38. function()
  39. skynet.register(".jmlogger")
  40. skynet.dispatch(
  41. "lua",
  42. function(session, _, command, ...)
  43. local f = CMD[command]
  44. if session == 0 then
  45. return f(...)
  46. end
  47. skynet.ret(skynet.pack(f(...)))
  48. end
  49. )
  50. end
  51. )