This is a read-only snapshot of the ComputerCraft forums, taken in April 2020.
cant_delete_account's profile picture

[API][1.33+] Logger v1.1

Started by cant_delete_account, 26 August 2012 - 04:21 PM
cant_delete_account #1
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:

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
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+):

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")
ardera #2
Posted 26 August 2012 - 06:28 PM
I read in your code (Im sorry if Im not allowed to do that, but I couldn't find anything that disallowed me that) that you open a log with the mode w, that means you replace the whole file! Please fix that!
cant_delete_account #3
Posted 26 August 2012 - 10:45 PM
I read in your code (Im sorry if Im not allowed to do that, but I couldn't find anything that disallowed me that) that you open a log with the mode w, that means you replace the whole file! Please fix that!
Have you tested?
ardera #4
Posted 29 August 2012 - 09:26 PM
yes i did
cant_delete_account #5
Posted 02 September 2012 - 01:00 AM
Update!
Now uses append mode so it doesn't overwrite,
Changed storage method
Added logger.exists
FuzzyPurp #6
Posted 02 September 2012 - 10:42 AM
Wrong section. Please read and follow the forum guidelines.
cant_delete_account #7
Posted 17 September 2012 - 04:36 AM
Wrong section. Please read and follow the forum guidelines.
That was on accident. I didn't want to post two times in different sections. So I asked for staff to move it…
Blockeh #8
Posted 18 September 2012 - 08:29 AM
So to use this you have to put it into the API's folder… would there be any other way that I could do this on a server? (which i don't need access to the Console)
cant_delete_account #9
Posted 23 September 2012 - 06:06 AM
So to use this you have to put it into the API's folder… would there be any other way that I could do this on a server? (which i don't need access to the Console)
No, you can just put it in your computer then add:

os.loadAPI('pathToAPI')
at the top of your program. (where pathToAPI is where you put the API)