get_log_service

The get_log_service function obtains a LuaLogService object, from which you can obtain a LuaLog object that you can use to write messages to a log file.

IMPORTANT:

To obtain a LuaLog object for writing to a standard log stream, call the function without any arguments or use the function get_log instead. Set the config argument only when you want to write to a custom log file that is not controlled by the ACI Server.

Syntax

get_log_service( [config] )

Arguments

Argument Description
config

(LuaConfig) A LuaConfig object that represents the configuration file which contains the logging settings. You can obtain a LuaConfig object using the function get_config.

Returns

(LuaLogService). A LuaLogService object.

Example

The following example shows how to use the get_log_service function to obtain a LuaLogService object. From this you can obtain a LuaLog object. The LuaLog object has a method, write_line, that writes messages to the log file.

local logService = get_log_service()
-- import is a standard log stream for CFS
local log = logService:get_log("import")
log:write_line( log_level_error() , "The log message")

The get_log function provides an easier way to accomplish the same task:

local log = get_log("import")
-- import is a standard log stream for CFS
log:write_line( log_level_error() , "The log message")

The following example demonstrates how to write messages to a custom log file. Declare the log service globally to avoid a LuaLogService object being created every time the script runs. For example, if you are writing a Lua script to use with a connector or CFS, call the get_log_service function outside the handler function.

local luaConfigString = [===[
[Logging]
LogLevel=FULL
0=LuaLogStream

[LuaLogStream]
LogTypeCSVs=lua
LogFile=lua.log
]===]
    
local config = LuaConfig:new(luaConfigString)

-- global log service instance for Lua log stream
luaLogService = get_log_service(config)

local luaLog = luaLogService:get_log("lua")
luaLog:write_line(log_level_normal(), "running Lua script")

_HP_HTML5_bannerTitle.htm