From 816f9c1802728fdacc18b43dadc8ff9d7027f77a Mon Sep 17 00:00:00 2001 From: ChewingBever Date: Mon, 28 Dec 2020 15:54:05 +0100 Subject: [PATCH] Updated treefarm to new logger syntax --- jlib/log.lua | 7 +------ treefarm.lua | 16 ++++++++-------- 2 files changed, 9 insertions(+), 14 deletions(-) diff --git a/jlib/log.lua b/jlib/log.lua index aa7a6e2..c39d0dc 100644 --- a/jlib/log.lua +++ b/jlib/log.lua @@ -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 diff --git a/treefarm.lua b/treefarm.lua index d869d77..e71e079 100644 --- a/treefarm.lua +++ b/treefarm.lua @@ -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 })