Posted 26 August 2012 - 06:22 PM
Attention: In v1.1 I changed the way logs are stored, to upgrade your logs, make it so .logsLOGNAME is called just LOGNAME and move LOGNAME to /.logs.
I've made a simple API to log text. Here's all of the functions of it:
Download: https://raw.github.c...s/master/logger
Place into /rom/apis as logger or just place into the root path of the computer.
Here's a script for putting it into the root of the computer (requires 1.4+):
I've made a simple API to log text. Here's all of the functions of it:
logger.create("logname") -- Creates a logger called logname
logger.log("logname", "[INFO] Something happened") -- Will log "[INFO] Something happened" to the logger logname
logger.read("logname") -- Will return the contents of the log logname (see examples for an example)
logger.exists("logname") -- Returns true if log exists, false if it doesn't
-- Would you like to see anymore functions? Reply with your idea!
Examples:Spoiler
--This will listen for rednet messages and log them readlog to read the log and log to start logging CTRL+T to quit (not tested, but should work)
logger.create("rnetd")
print("Command readlog or log: ")
local command = read()
if command == "log" then
while true do
sleep(0) -- Eh eh! Don't crash.
local tID, tMsg, tDistance = rednet.receive() -- Receive the messages
logger.log("rnetd", "[INFO] Message received from ID "..tID.." from "..tDistance.." blocks away: "..tMsg)
end
elseif command == "readlog" then
print(logger.read("rnetd"))
end
Place into /rom/apis as logger or just place into the root path of the computer.
Here's a script for putting it into the root of the computer (requires 1.4+):
local req = http.get("https://raw.github.com/ops99/LuaPrograms/master/logger")
local file = io.open("/logger", "w")
file:write(req:readAll())
file:close()
req:close()
Then just add this at the top of your program:
os.loadAPI("/logger")