Updated treefarm to new logger syntax

develop
Jef Roosens 2020-12-28 15:54:05 +01:00
parent 122f873015
commit 816f9c1802
2 changed files with 9 additions and 14 deletions

View File

@ -15,7 +15,6 @@ local Logger = {
prefixes = { "CRIT", "ERROR", "WARN", "INFO", "DEBUG" },
filename = nil
}
Logger.__index = Logger
-- Return a new logger 'object'.
@ -34,11 +33,7 @@ Logger.__index = Logger
function Logger:new(o)
o = o or {}
setmetatable(o, self)
-- Fill in default values where needed
-- TODO find out if this is needed or not
-- for k, v in pairs(Logger) do
-- o[k] = o[k] or Logger[k]
-- end
self.__index = self
-- Open file handler
if o.filename then

View File

@ -1,5 +1,5 @@
-- Created by Jef Roosens
local logger = require('jlib.log').init_logger(3, nil, "treefarm.log")
local logger = require('jlib.log').Logger:new{level=3, filename="treefarm.log"}
local fuel = require('jlib.fuel')
fuel.logger = logger
local move = require('jlib.move').move
@ -43,7 +43,7 @@ local function chop(max_height, log_name)
-- Return the new height if it's greater than the old
max_height = math.max(max_height, height)
logger:log(4, "Max height: " .. max_height)
logger:debug("Max height: " .. max_height)
return max_height
end
@ -75,7 +75,7 @@ end
-- @return new height of tallest known tree
local function cycle(width, depth, max_height, sapling_name, log_name,
spacing)
logger:log(3, "Starting cycle")
logger:info("Starting cycle")
for i = 1, width do
-- Check for fuel to go through entire row
@ -129,7 +129,7 @@ end
-- Do maintenance stuff: drop off items, and restock on saplings
local function maintenance(width, depth, sapling_name, log_name)
logger:log(3, "Doing maintenance")
logger:info("Doing maintenance")
fuel.check(6, { log_name })
-- Move towards sapling chest
@ -163,14 +163,14 @@ local function maintenance(width, depth, sapling_name, log_name)
turtle.turnRight()
move('f', 2)
logger:log(3, "Maintenance finished")
logger:info("Maintenance finished")
end
local function main()
-- Load the settings, or quit if it fails
if not settings.load(".treefarm.conf") then
return logger:log(1, "Couldn't load configuration file. Please make sure it exists and doesn't contain syntax errors.")
return logger:critical("Couldn't load configuration file. Please make sure it exists and doesn't contain syntax errors.")
end
-- Get all variables (API calls are slow)
@ -180,10 +180,10 @@ local function main()
settings.get("sapling_name"), settings.get("delay")
local max_height = 0
logger:log(3, "Settings loaded")
logger:info("Settings loaded")
-- Start the main loop
logger:log(3, "Starting main loop")
logger:info("Starting main loop")
while true do
-- Get into start position for cycle
fuel.check(2, { log_name })