[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: Is it possible to disable function arguments evaluation?
- From: "Robert G. Jakabosky" <bobby@...>
- Date: Thu, 30 Jun 2011 19:52:16 -0700
On Thursday 30, Han Zhao wrote:
> hi,
>
> In the debug mode of my project, I did a lot log using print().
> There're many string concats and other calculation in the
> arguments of print func.
>
> In release mode, I assign the print to:
> function dumb_print() end
> to hide the logs.
>
> But the arguments for print are still evaluated, is it possible
> to avoid this overhead?
The latest release (1.2.0) of LuaLogging [1] has support for delayed log
message creation to deal with this overhead.
There are two styles:
* Use string.format() style formatting:
logger:debug("Error format string: str=%s, num=%d", str, num)
* For more complex log message formatting:
-- define a "dump" function
local function log_dump(obj)
-- dump error/obj to a string
return str
end
function some_function_with_log_statements(...)
-- pass a dump function as the first parameter.
logger:debug(log_dump, error_obj)
end
In both cases creation of the log message will not happen unless the log level
is set to level "DEBUG".
This doesn't disable the evaluation of the parameters (i.e. they are still
passed to the method), but it does allow you to disable the processing of the
parameter into a log message.
1. http://neopallium.github.com/lualogging/
--
Robert G. Jakabosky