mirror of
https://github.com/MikaylaFischler/cc-mek-scada.git
synced 2024-08-30 18:22:34 +00:00
#222 added debug log enable to configs
This commit is contained in:
parent
032284e90d
commit
50c0a4a3eb
@ -28,5 +28,7 @@ config.LOG_PATH = "/log.txt"
|
|||||||
-- 0 = APPEND (adds to existing file on start)
|
-- 0 = APPEND (adds to existing file on start)
|
||||||
-- 1 = NEW (replaces existing file on start)
|
-- 1 = NEW (replaces existing file on start)
|
||||||
config.LOG_MODE = 0
|
config.LOG_MODE = 0
|
||||||
|
-- true to log verbose debug messages
|
||||||
|
config.LOG_DEBUG = false
|
||||||
|
|
||||||
return config
|
return config
|
||||||
|
@ -50,6 +50,7 @@ cfv.assert_type_num(config.SOUNDER_VOLUME)
|
|||||||
cfv.assert_type_bool(config.TIME_24_HOUR)
|
cfv.assert_type_bool(config.TIME_24_HOUR)
|
||||||
cfv.assert_type_str(config.LOG_PATH)
|
cfv.assert_type_str(config.LOG_PATH)
|
||||||
cfv.assert_type_int(config.LOG_MODE)
|
cfv.assert_type_int(config.LOG_MODE)
|
||||||
|
cfv.assert_type_bool(config.LOG_DEBUG)
|
||||||
|
|
||||||
assert(cfv.valid(), "bad config file: missing/invalid fields")
|
assert(cfv.valid(), "bad config file: missing/invalid fields")
|
||||||
|
|
||||||
@ -57,7 +58,7 @@ assert(cfv.valid(), "bad config file: missing/invalid fields")
|
|||||||
-- log init
|
-- log init
|
||||||
----------------------------------------
|
----------------------------------------
|
||||||
|
|
||||||
log.init(config.LOG_PATH, config.LOG_MODE)
|
log.init(config.LOG_PATH, config.LOG_MODE, config.LOG_DEBUG)
|
||||||
|
|
||||||
log.info("========================================")
|
log.info("========================================")
|
||||||
log.info("BOOTING coordinator.startup " .. COORDINATOR_VERSION)
|
log.info("BOOTING coordinator.startup " .. COORDINATOR_VERSION)
|
||||||
|
@ -17,5 +17,7 @@ config.LOG_PATH = "/log.txt"
|
|||||||
-- 0 = APPEND (adds to existing file on start)
|
-- 0 = APPEND (adds to existing file on start)
|
||||||
-- 1 = NEW (replaces existing file on start)
|
-- 1 = NEW (replaces existing file on start)
|
||||||
config.LOG_MODE = 0
|
config.LOG_MODE = 0
|
||||||
|
-- true to log verbose debug messages
|
||||||
|
config.LOG_DEBUG = false
|
||||||
|
|
||||||
return config
|
return config
|
||||||
|
@ -36,6 +36,7 @@ cfv.assert_type_num(config.COMMS_TIMEOUT)
|
|||||||
cfv.assert_min(config.COMMS_TIMEOUT, 2)
|
cfv.assert_min(config.COMMS_TIMEOUT, 2)
|
||||||
cfv.assert_type_str(config.LOG_PATH)
|
cfv.assert_type_str(config.LOG_PATH)
|
||||||
cfv.assert_type_int(config.LOG_MODE)
|
cfv.assert_type_int(config.LOG_MODE)
|
||||||
|
cfv.assert_type_bool(config.LOG_DEBUG)
|
||||||
|
|
||||||
assert(cfv.valid(), "bad config file: missing/invalid fields")
|
assert(cfv.valid(), "bad config file: missing/invalid fields")
|
||||||
|
|
||||||
@ -43,7 +44,7 @@ assert(cfv.valid(), "bad config file: missing/invalid fields")
|
|||||||
-- log init
|
-- log init
|
||||||
----------------------------------------
|
----------------------------------------
|
||||||
|
|
||||||
log.init(config.LOG_PATH, config.LOG_MODE)
|
log.init(config.LOG_PATH, config.LOG_MODE, config.LOG_DEBUG)
|
||||||
|
|
||||||
log.info("========================================")
|
log.info("========================================")
|
||||||
log.info("BOOTING pocket.startup " .. POCKET_VERSION)
|
log.info("BOOTING pocket.startup " .. POCKET_VERSION)
|
||||||
|
@ -24,5 +24,7 @@ config.LOG_PATH = "/log.txt"
|
|||||||
-- 0 = APPEND (adds to existing file on start)
|
-- 0 = APPEND (adds to existing file on start)
|
||||||
-- 1 = NEW (replaces existing file on start)
|
-- 1 = NEW (replaces existing file on start)
|
||||||
config.LOG_MODE = 0
|
config.LOG_MODE = 0
|
||||||
|
-- true to log verbose debug messages
|
||||||
|
config.LOG_DEBUG = false
|
||||||
|
|
||||||
return config
|
return config
|
||||||
|
@ -38,6 +38,7 @@ cfv.assert_type_num(config.COMMS_TIMEOUT)
|
|||||||
cfv.assert_min(config.COMMS_TIMEOUT, 2)
|
cfv.assert_min(config.COMMS_TIMEOUT, 2)
|
||||||
cfv.assert_type_str(config.LOG_PATH)
|
cfv.assert_type_str(config.LOG_PATH)
|
||||||
cfv.assert_type_int(config.LOG_MODE)
|
cfv.assert_type_int(config.LOG_MODE)
|
||||||
|
cfv.assert_type_bool(config.LOG_DEBUG)
|
||||||
|
|
||||||
assert(cfv.valid(), "bad config file: missing/invalid fields")
|
assert(cfv.valid(), "bad config file: missing/invalid fields")
|
||||||
|
|
||||||
@ -54,7 +55,7 @@ end
|
|||||||
-- log init
|
-- log init
|
||||||
----------------------------------------
|
----------------------------------------
|
||||||
|
|
||||||
log.init(config.LOG_PATH, config.LOG_MODE)
|
log.init(config.LOG_PATH, config.LOG_MODE, config.LOG_DEBUG)
|
||||||
|
|
||||||
log.info("========================================")
|
log.info("========================================")
|
||||||
log.info("BOOTING reactor-plc.startup " .. R_PLC_VERSION)
|
log.info("BOOTING reactor-plc.startup " .. R_PLC_VERSION)
|
||||||
|
@ -17,6 +17,8 @@ config.LOG_PATH = "/log.txt"
|
|||||||
-- 0 = APPEND (adds to existing file on start)
|
-- 0 = APPEND (adds to existing file on start)
|
||||||
-- 1 = NEW (replaces existing file on start)
|
-- 1 = NEW (replaces existing file on start)
|
||||||
config.LOG_MODE = 0
|
config.LOG_MODE = 0
|
||||||
|
-- true to log verbose debug messages
|
||||||
|
config.LOG_DEBUG = false
|
||||||
|
|
||||||
-- RTU peripheral devices (named: side/network device name)
|
-- RTU peripheral devices (named: side/network device name)
|
||||||
config.RTU_DEVICES = {
|
config.RTU_DEVICES = {
|
||||||
|
@ -49,6 +49,7 @@ cfv.assert_type_num(config.COMMS_TIMEOUT)
|
|||||||
cfv.assert_min(config.COMMS_TIMEOUT, 2)
|
cfv.assert_min(config.COMMS_TIMEOUT, 2)
|
||||||
cfv.assert_type_str(config.LOG_PATH)
|
cfv.assert_type_str(config.LOG_PATH)
|
||||||
cfv.assert_type_int(config.LOG_MODE)
|
cfv.assert_type_int(config.LOG_MODE)
|
||||||
|
cfv.assert_type_bool(config.LOG_DEBUG)
|
||||||
cfv.assert_type_table(config.RTU_DEVICES)
|
cfv.assert_type_table(config.RTU_DEVICES)
|
||||||
cfv.assert_type_table(config.RTU_REDSTONE)
|
cfv.assert_type_table(config.RTU_REDSTONE)
|
||||||
assert(cfv.valid(), "bad config file: missing/invalid fields")
|
assert(cfv.valid(), "bad config file: missing/invalid fields")
|
||||||
@ -57,7 +58,7 @@ assert(cfv.valid(), "bad config file: missing/invalid fields")
|
|||||||
-- log init
|
-- log init
|
||||||
----------------------------------------
|
----------------------------------------
|
||||||
|
|
||||||
log.init(config.LOG_PATH, config.LOG_MODE)
|
log.init(config.LOG_PATH, config.LOG_MODE, config.LOG_DEBUG)
|
||||||
|
|
||||||
log.info("========================================")
|
log.info("========================================")
|
||||||
log.info("BOOTING rtu.startup " .. RTU_VERSION)
|
log.info("BOOTING rtu.startup " .. RTU_VERSION)
|
||||||
|
@ -15,12 +15,10 @@ local MODE = {
|
|||||||
|
|
||||||
log.MODE = MODE
|
log.MODE = MODE
|
||||||
|
|
||||||
-- whether to log debug messages or not
|
local logger = {
|
||||||
local LOG_DEBUG = true
|
|
||||||
|
|
||||||
local log_sys = {
|
|
||||||
path = "/log.txt",
|
path = "/log.txt",
|
||||||
mode = MODE.APPEND,
|
mode = MODE.APPEND,
|
||||||
|
debug = false,
|
||||||
file = nil,
|
file = nil,
|
||||||
dmesg_out = nil
|
dmesg_out = nil
|
||||||
}
|
}
|
||||||
@ -41,8 +39,8 @@ local function _log(msg)
|
|||||||
|
|
||||||
-- attempt to write log
|
-- attempt to write log
|
||||||
local status, result = pcall(function ()
|
local status, result = pcall(function ()
|
||||||
log_sys.file.writeLine(stamped)
|
logger.file.writeLine(stamped)
|
||||||
log_sys.file.flush()
|
logger.file.flush()
|
||||||
end)
|
end)
|
||||||
|
|
||||||
-- if we don't have space, we need to create a new log file
|
-- if we don't have space, we need to create a new log file
|
||||||
@ -57,18 +55,18 @@ local function _log(msg)
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
if out_of_space or (free_space(log_sys.path) < 100) then
|
if out_of_space or (free_space(logger.path) < 100) then
|
||||||
-- delete the old log file before opening a new one
|
-- delete the old log file before opening a new one
|
||||||
log_sys.file.close()
|
logger.file.close()
|
||||||
fs.delete(log_sys.path)
|
fs.delete(logger.path)
|
||||||
|
|
||||||
-- re-init logger and pass dmesg_out so that it doesn't change
|
-- re-init logger and pass dmesg_out so that it doesn't change
|
||||||
log.init(log_sys.path, log_sys.mode, log_sys.dmesg_out)
|
log.init(logger.path, logger.mode, logger.debug, logger.dmesg_out)
|
||||||
|
|
||||||
-- leave a message
|
-- leave a message
|
||||||
log_sys.file.writeLine(time_stamp .. "recycled log file")
|
logger.file.writeLine(time_stamp .. "recycled log file")
|
||||||
log_sys.file.writeLine(stamped)
|
logger.file.writeLine(stamped)
|
||||||
log_sys.file.flush()
|
logger.file.flush()
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -78,33 +76,35 @@ end
|
|||||||
|
|
||||||
-- initialize logger
|
-- initialize logger
|
||||||
---@param path string file path
|
---@param path string file path
|
||||||
---@param write_mode MODE
|
---@param write_mode MODE file write mode
|
||||||
|
---@param include_debug boolean whether or not to include debug logs
|
||||||
---@param dmesg_redirect? table terminal/window to direct dmesg to
|
---@param dmesg_redirect? table terminal/window to direct dmesg to
|
||||||
function log.init(path, write_mode, dmesg_redirect)
|
function log.init(path, write_mode, include_debug, dmesg_redirect)
|
||||||
log_sys.path = path
|
logger.path = path
|
||||||
log_sys.mode = write_mode
|
logger.mode = write_mode
|
||||||
|
logger.debug = include_debug
|
||||||
|
|
||||||
if log_sys.mode == MODE.APPEND then
|
if logger.mode == MODE.APPEND then
|
||||||
log_sys.file = fs.open(path, "a")
|
logger.file = fs.open(path, "a")
|
||||||
else
|
else
|
||||||
log_sys.file = fs.open(path, "w")
|
logger.file = fs.open(path, "w")
|
||||||
end
|
end
|
||||||
|
|
||||||
if dmesg_redirect then
|
if dmesg_redirect then
|
||||||
log_sys.dmesg_out = dmesg_redirect
|
logger.dmesg_out = dmesg_redirect
|
||||||
else
|
else
|
||||||
log_sys.dmesg_out = term.current()
|
logger.dmesg_out = term.current()
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
-- close the log file handle
|
-- close the log file handle
|
||||||
function log.close()
|
function log.close()
|
||||||
log_sys.file.close()
|
logger.file.close()
|
||||||
end
|
end
|
||||||
|
|
||||||
-- direct dmesg output to a monitor/window
|
-- direct dmesg output to a monitor/window
|
||||||
---@param window table window or terminal reference
|
---@param window table window or terminal reference
|
||||||
function log.direct_dmesg(window) log_sys.dmesg_out = window end
|
function log.direct_dmesg(window) logger.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
|
||||||
@ -120,7 +120,7 @@ function log.dmesg(msg, tag, tag_color)
|
|||||||
tag = util.strval(tag)
|
tag = util.strval(tag)
|
||||||
|
|
||||||
local t_stamp = string.format("%12.2f", os.clock())
|
local t_stamp = string.format("%12.2f", os.clock())
|
||||||
local out = log_sys.dmesg_out
|
local out = logger.dmesg_out
|
||||||
|
|
||||||
if out ~= nil then
|
if out ~= nil then
|
||||||
local out_w, out_h = out.getSize()
|
local out_w, out_h = out.getSize()
|
||||||
@ -216,7 +216,7 @@ end
|
|||||||
function log.dmesg_working(msg, tag, tag_color)
|
function log.dmesg_working(msg, tag, tag_color)
|
||||||
local ts_coord = log.dmesg(msg, tag, tag_color)
|
local ts_coord = log.dmesg(msg, tag, tag_color)
|
||||||
|
|
||||||
local out = log_sys.dmesg_out
|
local out = logger.dmesg_out
|
||||||
local width = (ts_coord.x2 - ts_coord.x1) + 1
|
local width = (ts_coord.x2 - ts_coord.x1) + 1
|
||||||
|
|
||||||
if out ~= nil then
|
if out ~= nil then
|
||||||
@ -275,7 +275,7 @@ end
|
|||||||
---@param msg string message
|
---@param msg string message
|
||||||
---@param trace? boolean include file trace
|
---@param trace? boolean include file trace
|
||||||
function log.debug(msg, trace)
|
function log.debug(msg, trace)
|
||||||
if LOG_DEBUG then
|
if logger.debug then
|
||||||
local dbg_info = ""
|
local dbg_info = ""
|
||||||
|
|
||||||
if trace then
|
if trace then
|
||||||
|
@ -28,5 +28,7 @@ config.LOG_PATH = "/log.txt"
|
|||||||
-- 0 = APPEND (adds to existing file on start)
|
-- 0 = APPEND (adds to existing file on start)
|
||||||
-- 1 = NEW (replaces existing file on start)
|
-- 1 = NEW (replaces existing file on start)
|
||||||
config.LOG_MODE = 0
|
config.LOG_MODE = 0
|
||||||
|
-- true to log verbose debug messages
|
||||||
|
config.LOG_DEBUG = false
|
||||||
|
|
||||||
return config
|
return config
|
||||||
|
@ -40,6 +40,7 @@ cfv.assert_type_int(config.NUM_REACTORS)
|
|||||||
cfv.assert_type_table(config.REACTOR_COOLING)
|
cfv.assert_type_table(config.REACTOR_COOLING)
|
||||||
cfv.assert_type_str(config.LOG_PATH)
|
cfv.assert_type_str(config.LOG_PATH)
|
||||||
cfv.assert_type_int(config.LOG_MODE)
|
cfv.assert_type_int(config.LOG_MODE)
|
||||||
|
cfv.assert_type_bool(config.LOG_DEBUG)
|
||||||
|
|
||||||
assert(cfv.valid(), "bad config file: missing/invalid fields")
|
assert(cfv.valid(), "bad config file: missing/invalid fields")
|
||||||
|
|
||||||
@ -61,7 +62,7 @@ end
|
|||||||
-- log init
|
-- log init
|
||||||
----------------------------------------
|
----------------------------------------
|
||||||
|
|
||||||
log.init(config.LOG_PATH, config.LOG_MODE)
|
log.init(config.LOG_PATH, config.LOG_MODE, config.LOG_DEBUG)
|
||||||
|
|
||||||
log.info("========================================")
|
log.info("========================================")
|
||||||
log.info("BOOTING supervisor.startup " .. SUPERVISOR_VERSION)
|
log.info("BOOTING supervisor.startup " .. SUPERVISOR_VERSION)
|
||||||
|
Loading…
Reference in New Issue
Block a user