logMgrSrv.lua 953 B

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. local skynet = require "skynet"
  2. require "skynet.manager"
  3. local queue = require "skynet.queue"
  4. local lfsUtil = require "utils.lfsUtil"
  5. local cs = queue()
  6. local baseService = require("baseService")
  7. local LOGGER = {}
  8. local CMD = {}
  9. local function open(filename)
  10. local handle = LOGGER[filename]
  11. if handle then
  12. return handle
  13. end
  14. handle = skynet.launch("jmlogger", filename)
  15. LOGGER[filename] = handle
  16. return handle
  17. end
  18. local function close(filename)
  19. if LOGGER[filename] then
  20. skynet.error("close logger ", filename)
  21. skynet.kill(LOGGER[filename])
  22. LOGGER[filename] = nil
  23. end
  24. end
  25. function CMD.open(filename)
  26. return cs(open, filename)
  27. end
  28. function CMD.close(filename)
  29. return cs(close, filename)
  30. end
  31. function CMD.onStart()
  32. local statisticPath = skynet.getenv("statistic_path")
  33. assert(statisticPath)
  34. lfsUtil:create_path(statisticPath)
  35. end
  36. baseService.start(CMD, ".logMgr")