Addon Details

Watch - Add Favorite


Loglib ScreenShot

Does this version work for you?
8
w00ts
w00t!2

Loglib - Version 1.0.1

posted on 2008-05-17 10:37:34
by Errant



Description

[size=18][color=blue]Loglib: universal logging[/color][/size] I'm using this simple module on my clans server and I thought I would share it here. Basically is sits in the _libs/python. directory and provides a universal interface to log files. :arrow: [size=16][color=blue]Features[/color][/size] Loglib currently supports logging for addons and players. It also supports log levels (so on production servers you can set the level low to avoid logging anythign except errors). It supports auto-logging by date (so the default addon log file is date-stamped) as well as custom files (eg: yourname.log). Each addon has a unique class for logging: anything accessing the logs uses the single class which removes the possiblity of read/write clashes! :arrow: [size=16][color=blue]Configuration[/color][/size] There are 2 server cvars that control loglib: [list] [*] loglib_level: The level you wish to log too: the lower you set it the less is logged (def: 1) [*] loglib_directory: Location for loglib to store it's logs below your game directory (def: logs/loglib) [b]Note: you cna ONLY set in server.cfg or autoexe.cfg before loglib loads. NOT via console[/b] [/list] :arrow: [size=16][color=blue]Usage: Addons[/color][/size] The key of course is for addons to use loglib! It's very simple to use: [syntax="python"] import loglib # start the logging class log = loglib.addonLog("myaddonname") # we can write like this # this will write to the default (date stamped) file log.write(0,"A message") # this will write to a custom file # ideal for creating an error log! log["mylog"].(0,"This writes to my own custom file") [/syntax] Here's an example logfile, the file header is auto generated: [code] ############## Log File Started 05/17/08 15:20:15 ############## [15:20:15] A quick test [15:30:16] A quick test [15:32:16] A quick test [15:32:34] A quick test [/code] [u]Loglib addons API[/u] A list of the methods provided for addon logging [syntax="python"] isLogged(addon) # returns TRUE if the addon has a logging class created log(addon,lvl,messages) # log message with level to addon log (messages can be a list addonLog(addon) # return the addons logging class # the addon class has the following public methods AddonLogfile.addFile(filename) # add another log file to the addon class AddonLogfile.setDefault(filename) # set the deafult filename (note: this will auto-change daily so you need to reset it regularly!) AddonLogfile.write(lvl,messages) # a list of messages (or a string) to write to the logfile [/syntax] :arrow: [size=16][color=blue]Usage: Players[/color][/size] Loglib also supports advanced tools for logging players [u]Marking players to be logged[/u] For loglib to be able to log a player somethign has to mark them as "to be logged", unless this is done calling the player logging methods simply raises an error. This is so that a script cant just log EVERY player that joins by accident! Toggle player toggles the players log status: so if they are being logged they are removed and if they aren't beign logged they are added. # isLogged reutrns whether a steamid is beign logged or not. [syntax="python"] import loglib # toggle them to be logged loglib.togglePlayer("STEAMID TO LOG") # are they beign logged? islogged = loglib.isLogged("STEAMID") loglib.plog("STEAMID",0,"message") [/syntax] [u]Player logging[/u] Once toggled you can log a player very easily. The logs are stored in the "player_logs" sub directory in the format: "STEAM_0-0-3513656313.log" [syntax="python"] import loglib # toggle them to be logged if not loglib.isLogged("STEAMID"): loglib.togglePlayer("STEAMID TO LOG") # write a log message loglib.plog("STEAMID",0,"message") # or return the player log class # has ALL the same methods as the addon class playerlog = loglib.playerLog("STEAMID") [/syntax] [u]Player API[/u] The followign methods are provided by the class [syntax="python"] isLogged(uniqueid) # returns TRUE if the uniqueid has a logging class created plog(uniqueid,lvl,messages) # log message with level to uniqueid log (messages can be a list) playerLog(uniqueid) # return the players logging class # the addon class has the following public methods PlayerLogfile.addFile(filename) # add another log file to the addon class PlayerLogfile.setDefault(filename) # set the deafult filename (note: this will auto-change daily so you need to reset it regularly!) PlayerLogfile.write(lvl,messages) # a list of messages (or a string) to write to the logfile [/syntax] Download here: [url]http://addons.eventscripts.com/addons/download/loglib[/url]

Version Notes For 1.0.1

Updated on: 2009-04-19 13:59:05 EST by Errant (View Zip Contents)
Fix a syntax error

( Previous Versions )