ES Recruitment Drive
Original Post
Logging module
I wrote a little logging utility and thought that maybe there are people who find it quite usefull, so I'm posting it now.

What it does:
Logging stuff, duh! You can create a logger, tell it where to save your log and then it will log everything you tell it to. The difference to normal io? You can tell it to log only certain level of events. That's quite useful if you're debugging your script and have a lot of control output, but you are only intereseted in major errors but don't want to delete every single line that outputs something.

I'm terrible at explaining stuff, so I'll give an example later.

Usage:
1. Save in "data/scripts/modules".
2. In the script you want to log type 'require "Logger".
3. Create a new logger with
logger = Logger.new(<filename>, [logLevel]) -- filename is a must, logLevel is optional, defaut is ALWAYS
4. Log stuff with
logger:log(<message>, <lvl>)
5. Levels are: FINE, WARNING, SEVERE and ALWAYS
6. Change loglevel with
logger:setLogLevel(<logLevel>)
7. Clear log with
logger:clear()
8. Multiple loggers (for what ever reason) are supported.
9. Usually it appends stuff. If you don't want that, simply use clear().

Example:
require "Logger"

logger = Logger.new("testlog.txt")
logger:clear()
logger:setLogLevel(Logger.LEVEL.FINE)
logger:log("test", Logger.LEVEL.FINE)
logger:log("Warning!", Logger.LEVEL.WARNING)
logger:log("Setting loglevel to SEVERE", Logger.LEVEL.FINE)
logger:setLogLevel(Logger.LEVEL.SEVERE)
logger:log("test", Logger.LEVEL.FINE) -- won't be printed
logger:log("ksdfak", Logger.LEVEL.SEVERE)
output:
04/28/12 18:11:24


18:11:24 FINE: 
test
18:11:24 WARNING: 
Warning!
18:11:24 FINE: 
Setting loglevel to SEVERE
18:11:24 SEVERE: 
ksdfak
Don't care about opening/flushing/closing files, everything is done automatically.

To whoever finds it useful: Have fun with it.
Attached Files
Logger.lua (2.1 KB, 7 views)
Signature temporarily out of order.