commonlib.log

advanced log function

Title advanced log function
Author(s) LiXizhi
Date  
File script/ide/log.lua

Description

TIP Sample Code

NPL.load("(gl)script/ide/log.lua");
commonlib.log("hello %s \n", "paraengine")
commonlib.log({"anything"})
local fromPos = commonlib.log.GetLogPos()
log(fromPos.." babababa...\n");
local text = commonlib.log.GetLog(fromPos, nil)
log(tostring(text).." is retrieved\n")

Member Functions

commonlib.log.log_long


log file class

logging with no limit to size and with formatting. support formatting: commonlib.log("hello %s \n", "paraengine") commonlib.log = setmetatable({}, {__call = function(self, input, ...) if(type(input) == "string") then local args = {...}; if(#args == 0) then commonlib.log.log_long(input) else commonlib.log.log_long(string.format(input, ...)); end elseif(type(input) == "table") then commonlib.log.log_long(commonlib.serialize(input)); else commonlib.log.log_long(tostring(input)); end end});

it support logging string longer than 1024 bytes by deviding input into multiple sections. By default: log(string) longer than 1024 is cut. Use this function if u want to log something really long

  • param str : the string to log.
  • param maxLength : if nil it is unlimited.

syntax

function commonlib.log.log_long(str, maxLength)

parameters

str the string to log.
maxLength  

commonlib.log.GetLogPos

get the current log file position. it is equavalent to the log file size in bytes. one can later get log text between two Log positions.

syntax

function commonlib.log.GetLogPos()

commonlib.log.GetLog

get log text between two Log positions.

  • param fromPos : position in bytes. if nil, it defaults to 0
  • param nCount : count in bytes. if nil, it defaults to end of log file.
  • return string : returned.

syntax

function commonlib.log.GetLog(fromPos, nCount)

parameters

fromPos position in bytes. if nil, it defaults to 0
nCount  
return returned.
Topic revision: r1 - 2008-02-29 - LiXizhi
 
This site is powered by the TWiki collaboration platform Powered by PerlCopyright © 2008-2021 by the contributing authors. All material on this collaboration platform is the property of the contributing authors.
Ideas, requests, problems regarding TWiki? Send feedback