#217 close log files on exit (including crash)
This commit is contained in:
parent
e9788abde7
commit
5db517cedc
@ -20,7 +20,7 @@ local sounder = require("coordinator.sounder")
|
|||||||
|
|
||||||
local apisessions = require("coordinator.session.apisessions")
|
local apisessions = require("coordinator.session.apisessions")
|
||||||
|
|
||||||
local COORDINATOR_VERSION = "v0.13.4"
|
local COORDINATOR_VERSION = "v0.13.5"
|
||||||
|
|
||||||
local println = util.println
|
local println = util.println
|
||||||
local println_ts = util.println_ts
|
local println_ts = util.println_ts
|
||||||
@ -389,4 +389,6 @@ if not xpcall(main, crash.handler) then
|
|||||||
pcall(renderer.close_ui)
|
pcall(renderer.close_ui)
|
||||||
pcall(sounder.stop)
|
pcall(sounder.stop)
|
||||||
crash.exit()
|
crash.exit()
|
||||||
|
else
|
||||||
|
log.close()
|
||||||
end
|
end
|
||||||
|
|||||||
File diff suppressed because one or more lines are too long
@ -18,7 +18,7 @@ local plc = require("reactor-plc.plc")
|
|||||||
local renderer = require("reactor-plc.renderer")
|
local renderer = require("reactor-plc.renderer")
|
||||||
local threads = require("reactor-plc.threads")
|
local threads = require("reactor-plc.threads")
|
||||||
|
|
||||||
local R_PLC_VERSION = "v1.1.12"
|
local R_PLC_VERSION = "v1.1.13"
|
||||||
|
|
||||||
local println = util.println
|
local println = util.println
|
||||||
local println_ts = util.println_ts
|
local println_ts = util.println_ts
|
||||||
@ -264,4 +264,4 @@ local function main()
|
|||||||
log.info("exited")
|
log.info("exited")
|
||||||
end
|
end
|
||||||
|
|
||||||
if not xpcall(main, crash.handler) then crash.exit() end
|
if not xpcall(main, crash.handler) then crash.exit() else log.close() end
|
||||||
|
|||||||
@ -28,7 +28,7 @@ local sna_rtu = require("rtu.dev.sna_rtu")
|
|||||||
local sps_rtu = require("rtu.dev.sps_rtu")
|
local sps_rtu = require("rtu.dev.sps_rtu")
|
||||||
local turbinev_rtu = require("rtu.dev.turbinev_rtu")
|
local turbinev_rtu = require("rtu.dev.turbinev_rtu")
|
||||||
|
|
||||||
local RTU_VERSION = "v1.0.0"
|
local RTU_VERSION = "v1.0.1"
|
||||||
|
|
||||||
local RTU_UNIT_TYPE = types.RTU_UNIT_TYPE
|
local RTU_UNIT_TYPE = types.RTU_UNIT_TYPE
|
||||||
local RTU_UNIT_HW_STATE = databus.RTU_UNIT_HW_STATE
|
local RTU_UNIT_HW_STATE = databus.RTU_UNIT_HW_STATE
|
||||||
@ -497,4 +497,4 @@ local function main()
|
|||||||
log.info("exited")
|
log.info("exited")
|
||||||
end
|
end
|
||||||
|
|
||||||
if not xpcall(main, crash.handler) then crash.exit() end
|
if not xpcall(main, crash.handler) then crash.exit() else log.close() end
|
||||||
|
|||||||
@ -39,6 +39,7 @@ end
|
|||||||
|
|
||||||
-- final error print on failed xpcall, app exits here
|
-- final error print on failed xpcall, app exits here
|
||||||
function crash.exit()
|
function crash.exit()
|
||||||
|
log.close()
|
||||||
util.println("fatal error occured in main application:")
|
util.println("fatal error occured in main application:")
|
||||||
error(err, 0)
|
error(err, 0)
|
||||||
end
|
end
|
||||||
|
|||||||
@ -16,7 +16,7 @@ local MODE = {
|
|||||||
log.MODE = MODE
|
log.MODE = MODE
|
||||||
|
|
||||||
-- whether to log debug messages or not
|
-- whether to log debug messages or not
|
||||||
local LOG_DEBUG = false
|
local LOG_DEBUG = true
|
||||||
|
|
||||||
local log_sys = {
|
local log_sys = {
|
||||||
path = "/log.txt",
|
path = "/log.txt",
|
||||||
@ -28,30 +28,9 @@ local log_sys = {
|
|||||||
---@type function
|
---@type function
|
||||||
local free_space = fs.getFreeSpace
|
local free_space = fs.getFreeSpace
|
||||||
|
|
||||||
-- initialize logger
|
-----------------------
|
||||||
---@param path string file path
|
-- PRIVATE FUNCTIONS --
|
||||||
---@param write_mode MODE
|
-----------------------
|
||||||
---@param dmesg_redirect? table terminal/window to direct dmesg to
|
|
||||||
function log.init(path, write_mode, dmesg_redirect)
|
|
||||||
log_sys.path = path
|
|
||||||
log_sys.mode = write_mode
|
|
||||||
|
|
||||||
if log_sys.mode == MODE.APPEND then
|
|
||||||
log_sys.file = fs.open(path, "a")
|
|
||||||
else
|
|
||||||
log_sys.file = fs.open(path, "w")
|
|
||||||
end
|
|
||||||
|
|
||||||
if dmesg_redirect then
|
|
||||||
log_sys.dmesg_out = dmesg_redirect
|
|
||||||
else
|
|
||||||
log_sys.dmesg_out = term.current()
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
-- direct dmesg output to a monitor/window
|
|
||||||
---@param window table window or terminal reference
|
|
||||||
function log.direct_dmesg(window) log_sys.dmesg_out = window end
|
|
||||||
|
|
||||||
-- private log write function
|
-- private log write function
|
||||||
---@param msg string
|
---@param msg string
|
||||||
@ -93,6 +72,40 @@ local function _log(msg)
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
----------------------
|
||||||
|
-- PUBLIC FUNCTIONS --
|
||||||
|
----------------------
|
||||||
|
|
||||||
|
-- initialize logger
|
||||||
|
---@param path string file path
|
||||||
|
---@param write_mode MODE
|
||||||
|
---@param dmesg_redirect? table terminal/window to direct dmesg to
|
||||||
|
function log.init(path, write_mode, dmesg_redirect)
|
||||||
|
log_sys.path = path
|
||||||
|
log_sys.mode = write_mode
|
||||||
|
|
||||||
|
if log_sys.mode == MODE.APPEND then
|
||||||
|
log_sys.file = fs.open(path, "a")
|
||||||
|
else
|
||||||
|
log_sys.file = fs.open(path, "w")
|
||||||
|
end
|
||||||
|
|
||||||
|
if dmesg_redirect then
|
||||||
|
log_sys.dmesg_out = dmesg_redirect
|
||||||
|
else
|
||||||
|
log_sys.dmesg_out = term.current()
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
-- close the log file handle
|
||||||
|
function log.close()
|
||||||
|
log_sys.file.close()
|
||||||
|
end
|
||||||
|
|
||||||
|
-- direct dmesg output to a monitor/window
|
||||||
|
---@param window table window or terminal reference
|
||||||
|
function log.direct_dmesg(window) log_sys.dmesg_out = window end
|
||||||
|
|
||||||
-- dmesg style logging for boot because I like linux-y things
|
-- dmesg style logging for boot because I like linux-y things
|
||||||
---@param msg string message
|
---@param msg string message
|
||||||
---@param tag? string log tag
|
---@param tag? string log tag
|
||||||
|
|||||||
@ -14,7 +14,7 @@ local supervisor = require("supervisor.supervisor")
|
|||||||
|
|
||||||
local svsessions = require("supervisor.session.svsessions")
|
local svsessions = require("supervisor.session.svsessions")
|
||||||
|
|
||||||
local SUPERVISOR_VERSION = "v0.15.3"
|
local SUPERVISOR_VERSION = "v0.15.4"
|
||||||
|
|
||||||
local println = util.println
|
local println = util.println
|
||||||
local println_ts = util.println_ts
|
local println_ts = util.println_ts
|
||||||
@ -169,4 +169,4 @@ local function main()
|
|||||||
log.info("exited")
|
log.info("exited")
|
||||||
end
|
end
|
||||||
|
|
||||||
if not xpcall(main, crash.handler) then crash.exit() end
|
if not xpcall(main, crash.handler) then crash.exit() else log.close() end
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user