Skip to content

Commit

Permalink
暂存
Browse files Browse the repository at this point in the history
  • Loading branch information
sumneko committed May 14, 2024
1 parent 880d551 commit 46bff10
Show file tree
Hide file tree
Showing 7 changed files with 74 additions and 3 deletions.
12 changes: 10 additions & 2 deletions script/brave/log.lua
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
local brave = require 'brave'
local time = require 'bee.time'
local ltask = require 'ltask'

local tablePack = table.pack
local tostring = tostring
Expand All @@ -8,6 +8,8 @@ local debugTraceBack = debug.traceback
local debugGetInfo = debug.getinfo
local monotonic = time.monotonic

local logAddr = ltask.queryservice('log')

_ENV = nil

local function pushLog(level, ...)
Expand All @@ -20,7 +22,7 @@ local function pushLog(level, ...)
str = str .. '\n' .. debugTraceBack(nil, 3)
end
local info = debugGetInfo(3, 'Sl')
brave.push('log', {
ltask.call(logAddr, 'log', {
level = level,
msg = str,
src = info.source,
Expand Down Expand Up @@ -52,4 +54,10 @@ function m.error(...)
pushLog('error', ...)
end

---@param root fs.path
---@param path fs.path
function m.init(root, path)
ltask.call(logAddr, 'init', root:string(), path:string())
end

return m
4 changes: 4 additions & 0 deletions script/ltask2/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,10 @@ local root_config = {
}
}
},
{
name = 'log',
unique = true,
},
{
name = "main",
args = {
Expand Down
1 change: 1 addition & 0 deletions script/ltask2/lualib/service.lua
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ local RECEIPT_BLOCK <const> = 3

local SESSION_SEND_MESSAGE <const> = 0

---@class ltask
local ltask = require "ltask"

local CURRENT_SERVICE <const> = ltask.self()
Expand Down
16 changes: 16 additions & 0 deletions script/ltask2/service/log.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
local fs = require 'bee.filesystem'
local log = require 'log'

local S = {}

---@param root string
---@param path string
function S.init(root, path)
log.init(fs.path(root), fs.path(path))
end

function S.log(params)
log.raw(-1, params.level, params.msg, params.src, params.line, params.clock)
end

return S
2 changes: 1 addition & 1 deletion script/ltask2/service/main.lua
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ LOGLEVEL = ENV.LOGLEVEL
require 'tracy'

---@diagnostic disable-next-line: lowercase-global
log = require 'log'
log = require 'brave.log'
log.init(ROOT, fs.path(LOGPATH) / 'service.log')
if LOGLEVEL then
log.level = tostring(LOGLEVEL):lower()
Expand Down
1 change: 1 addition & 0 deletions script/ltask2/service/root.lua
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ local anonymous_services = {}
local named_services = {}

local root_quit = ltask.quit
---@diagnostic disable-next-line: duplicate-set-field
ltask.quit = function() end

local function writelog()
Expand Down
41 changes: 41 additions & 0 deletions script/meta/ltask.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
---@meta ltask

---@class ltask
local M = {}

---@return string
function M.self() end

---@return string
function M.label() end

function M.pushlog(...) end

function M.pack(...) end

function M.send_message(...) end

---@return ...
function M.message_receipt() end

function M.remove(...) end

---@return ...
function M.unpack_remove(...) end

function M.timer_add(...) end

---@return ...
function M.recv_message() end

---@return ...
function M.poplog() end

function M.eventinit() end

function M.timer_update(message) end

---@param ms integer
function M.timer_sleep(ms) end

return M

0 comments on commit 46bff10

Please sign in to comment.