AnnaBelle Posted May 7, 2017 Share Posted May 7, 2017 -- Server Log = {} local cover = "========================================" function Log:Time ( ) local _time = getRealTime ( ) local _second = _time.second local _minute = _time.minute local _hour = _time.hour local _date = _time.monthday local _month = getMonthName ( _time.month + 1 ) local _year = _time.year + 1900 return _year, _month, _date, _hour, _minute, _second end function Log:Write ( _str ) local _year, _month, _date, _hour, _minute, _second = Log:Time ( ) local filePath = "logs/" .. _year .. "/" .. _month .. "/" .. _date .. ".log" if not ( fileExists ( filePath ) ) then fileCreate ( filePath ) local file = fileOpen ( filePath ) fileWrite ( file, cover .. "\n=Log generated on " .. _date .. " of " .. _month .. ", " .. _year .. "=\n" .. cover .. "\n" ) fileClose ( file ) end local file = fileOpen ( filePath ) fileSetPos ( file, fileGetSize ( file ) ) local _str = tostring ( _str ) fileWrite ( file, "\n[" .. _hour .. ":" .. _minute .. ":" .. _second .. "] " .. _str ) fileFlush ( file ) fileClose ( file ) end months = {"January","February","March","April","May","June","July","August","September","October","November","December"} function getMonthName ( _month ) return months [ _month ] end function outputLog ( _str ) Log:Write ( _str ) end debugTypes = {"INFO","ERROR","WARNING","INFO"} function getDebugLevelFromID ( id ) return debugTypes [ id + 1 ] end addEventHandler("onDebugMessage", root, function ( _msg, _level, _file, _line ) if not _line then _line = "" Log:Write ( getDebugLevelFromID ( _level ) .. ": " .. _file .. ": " .. _line .. ": " .. _msg ) end end ) addEventHandler("onPlayerLogin", root, function ( _, _acc ) local _acc = getAccountName ( _acc ) local _clan = getIPFromName ( getElementData ( source,"Group" ) ) Log:Write ( "LOGIN: " .. getPlayerName(source) .. " successfully logged in as '" .. _acc .. "' (CLAN: ".._clan")" ) end ) function getIPFromName ( str ) return playerIPs [ str ] end -- Meta <script src = "Server.lua" type = "server" /> <export function = "outputLog" type = "server" /> Is not logging per day. Link to comment
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now