PEDN> Main Web>NPL>AdvancedLog (2008-02-29, LiXizhi) Change language en zh-cn? EditAttach

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 - 15:26:12 - LiXizhi
 

ParaEngine Developer Network

This site is powered by the TWiki collaboration platformCopyright © 2004-2008 ParaEngine Corporation
Ideas, requests, problems regarding ParaEngine platform Send feedback