Updated treefarm to new logger syntax
parent
122f873015
commit
816f9c1802
|
@ -15,7 +15,6 @@ local Logger = {
|
||||||
prefixes = { "CRIT", "ERROR", "WARN", "INFO", "DEBUG" },
|
prefixes = { "CRIT", "ERROR", "WARN", "INFO", "DEBUG" },
|
||||||
filename = nil
|
filename = nil
|
||||||
}
|
}
|
||||||
Logger.__index = Logger
|
|
||||||
|
|
||||||
|
|
||||||
-- Return a new logger 'object'.
|
-- Return a new logger 'object'.
|
||||||
|
@ -34,11 +33,7 @@ Logger.__index = Logger
|
||||||
function Logger:new(o)
|
function Logger:new(o)
|
||||||
o = o or {}
|
o = o or {}
|
||||||
setmetatable(o, self)
|
setmetatable(o, self)
|
||||||
-- Fill in default values where needed
|
self.__index = self
|
||||||
-- TODO find out if this is needed or not
|
|
||||||
-- for k, v in pairs(Logger) do
|
|
||||||
-- o[k] = o[k] or Logger[k]
|
|
||||||
-- end
|
|
||||||
|
|
||||||
-- Open file handler
|
-- Open file handler
|
||||||
if o.filename then
|
if o.filename then
|
||||||
|
|
16
treefarm.lua
16
treefarm.lua
|
@ -1,5 +1,5 @@
|
||||||
-- Created by Jef Roosens
|
-- 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')
|
local fuel = require('jlib.fuel')
|
||||||
fuel.logger = logger
|
fuel.logger = logger
|
||||||
local move = require('jlib.move').move
|
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
|
-- Return the new height if it's greater than the old
|
||||||
|
|
||||||
max_height = math.max(max_height, height)
|
max_height = math.max(max_height, height)
|
||||||
logger:log(4, "Max height: " .. max_height)
|
logger:debug("Max height: " .. max_height)
|
||||||
|
|
||||||
return max_height
|
return max_height
|
||||||
end
|
end
|
||||||
|
@ -75,7 +75,7 @@ end
|
||||||
-- @return new height of tallest known tree
|
-- @return new height of tallest known tree
|
||||||
local function cycle(width, depth, max_height, sapling_name, log_name,
|
local function cycle(width, depth, max_height, sapling_name, log_name,
|
||||||
spacing)
|
spacing)
|
||||||
logger:log(3, "Starting cycle")
|
logger:info("Starting cycle")
|
||||||
|
|
||||||
for i = 1, width do
|
for i = 1, width do
|
||||||
-- Check for fuel to go through entire row
|
-- Check for fuel to go through entire row
|
||||||
|
@ -129,7 +129,7 @@ end
|
||||||
|
|
||||||
-- Do maintenance stuff: drop off items, and restock on saplings
|
-- Do maintenance stuff: drop off items, and restock on saplings
|
||||||
local function maintenance(width, depth, sapling_name, log_name)
|
local function maintenance(width, depth, sapling_name, log_name)
|
||||||
logger:log(3, "Doing maintenance")
|
logger:info("Doing maintenance")
|
||||||
fuel.check(6, { log_name })
|
fuel.check(6, { log_name })
|
||||||
|
|
||||||
-- Move towards sapling chest
|
-- Move towards sapling chest
|
||||||
|
@ -163,14 +163,14 @@ local function maintenance(width, depth, sapling_name, log_name)
|
||||||
turtle.turnRight()
|
turtle.turnRight()
|
||||||
move('f', 2)
|
move('f', 2)
|
||||||
|
|
||||||
logger:log(3, "Maintenance finished")
|
logger:info("Maintenance finished")
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
local function main()
|
local function main()
|
||||||
-- Load the settings, or quit if it fails
|
-- Load the settings, or quit if it fails
|
||||||
if not settings.load(".treefarm.conf") then
|
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
|
end
|
||||||
|
|
||||||
-- Get all variables (API calls are slow)
|
-- Get all variables (API calls are slow)
|
||||||
|
@ -180,10 +180,10 @@ local function main()
|
||||||
settings.get("sapling_name"), settings.get("delay")
|
settings.get("sapling_name"), settings.get("delay")
|
||||||
local max_height = 0
|
local max_height = 0
|
||||||
|
|
||||||
logger:log(3, "Settings loaded")
|
logger:info("Settings loaded")
|
||||||
|
|
||||||
-- Start the main loop
|
-- Start the main loop
|
||||||
logger:log(3, "Starting main loop")
|
logger:info("Starting main loop")
|
||||||
while true do
|
while true do
|
||||||
-- Get into start position for cycle
|
-- Get into start position for cycle
|
||||||
fuel.check(2, { log_name })
|
fuel.check(2, { log_name })
|
||||||
|
|
Loading…
Reference in New Issue