ODBC Connector 24.2

# 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")

Copyright 2024 Open Text
Version 24.2 | Last updated March 2024

Send documentation feedback

Close

Send documentation feedback

To send feedback using your default email client, open an email window.

Otherwise, send your feedback and the information below to MFI-swpdl.idoldocsfeedback@opentext.com.

We appreciate your feedback!

Product: IDOL ODBC Connector 24.2

Topic Title: get_log_service