log init function to set path and write mode

This commit is contained in:
Mikayla Fischler 2022-04-29 13:32:37 -04:00
parent 3587352219
commit c805b6e0c5
5 changed files with 46 additions and 14 deletions

View File

@ -10,18 +10,27 @@ os.loadAPI("scada-common/comms.lua")
os.loadAPI("coordinator/config.lua")
os.loadAPI("coordinator/coordinator.lua")
local COORDINATOR_VERSION = "alpha-v0.1.0"
local COORDINATOR_VERSION = "alpha-v0.1.1"
local print = util.print
local println = util.println
local print_ts = util.print_ts
local println_ts = util.println_ts
log.init("/log.txt", log.MODE.APPEND)
log._info("========================================")
log._info("BOOTING coordinator.startup " .. COORDINATOR_VERSION)
log._info("========================================")
println(">> RTU " .. COORDINATOR_VERSION .. " <<")
-- mount connected devices
ppm.mount_all()
local modem = ppm.get_device("modem")
print("| SCADA Coordinator - " .. COORDINATOR_VERSION .. " |")
local modem = ppm.get_wireless_modem()
-- we need a modem
if modem == nil then
print("Please connect a modem.")
println("please connect a wireless modem")
return
end

View File

@ -12,13 +12,15 @@ os.loadAPI("config.lua")
os.loadAPI("plc.lua")
os.loadAPI("threads.lua")
local R_PLC_VERSION = "alpha-v0.4.10"
local R_PLC_VERSION = "alpha-v0.4.11"
local print = util.print
local println = util.println
local print_ts = util.print_ts
local println_ts = util.println_ts
log.init("/log.txt", log.MODE.APPEND)
log._info("========================================")
log._info("BOOTING reactor-plc.startup " .. R_PLC_VERSION)
log._info("========================================")

View File

@ -19,13 +19,15 @@ os.loadAPI("dev/boiler_rtu.lua")
os.loadAPI("dev/imatrix_rtu.lua")
os.loadAPI("dev/turbine_rtu.lua")
local RTU_VERSION = "alpha-v0.4.8"
local RTU_VERSION = "alpha-v0.4.9"
local print = util.print
local println = util.println
local print_ts = util.print_ts
local println_ts = util.println_ts
log.init("/log.txt", log.MODE.APPEND)
log._info("========================================")
log._info("BOOTING rtu.startup " .. RTU_VERSION)
log._info("========================================")

View File

@ -5,10 +5,16 @@
-- we use extra short abbreviations since computer craft screens are very small
-- underscores are used since some of these names are used elsewhere (e.g. 'debug' is a lua table)
local LOG_DEBUG = true
local LOG_PATH = "/log.txt"
MODE = {
APPEND = 0,
NEW = 1
}
local file_handle = fs.open(LOG_PATH, "a")
local LOG_DEBUG = true
local log_path = "/log.txt"
local mode = MODE.APPEND
local file_handle = nil
local _log = function (msg)
local stamped = os.date("[%c] ") .. msg
@ -20,7 +26,7 @@ local _log = function (msg)
end)
-- if we don't have much space, we need to create a new log file
local delete_log = fs.getFreeSpace(LOG_PATH) < 100
local delete_log = fs.getFreeSpace(log_path) < 100
if not status then
if result == "Out of space" then
@ -33,8 +39,8 @@ local _log = function (msg)
if delete_log then
-- delete the old log file and open a new one
file_handle.close()
fs.delete(LOG_PATH)
file_handle = fs.open(LOG_PATH, "a")
fs.delete(log_path)
init(log_path, mode)
-- leave a message
local notif = os.date("[%c] ") .. "recycled log file"
@ -44,6 +50,17 @@ local _log = function (msg)
end
end
function init(path, write_mode)
log_path = path
mode = write_mode
if mode == MODE.APPEND then
file_handle = fs.open(path, "a")
else
file_handle = fs.open(path, "w+")
end
end
function _debug(msg, trace)
if LOG_DEBUG then
local dbg_info = ""

View File

@ -18,13 +18,15 @@ os.loadAPI("session/svsessions.lua")
os.loadAPI("supervisor.lua")
local SUPERVISOR_VERSION = "alpha-v0.1.8"
local SUPERVISOR_VERSION = "alpha-v0.1.9"
local print = util.print
local println = util.println
local print_ts = util.print_ts
local println_ts = util.println_ts
log.init("/log.txt", log.MODE.APPEND)
log._info("========================================")
log._info("BOOTING supervisor.startup " .. SUPERVISOR_VERSION)
log._info("========================================")