Poco::Data

class SQLChannel

File Information

Library: Data
Package: Logging
Header: Poco/Data/SQLChannel.h

Description

This Channel implements logging to a SQL database. The channel is dependent on the schema. The DDL for table creation (subject to target DDL dialect dependent modifications) is:

"CREATE TABLE T_POCO_LOG (Source VARCHAR, Name VARCHAR, ProcessId INTEGER, Thread VARCHAR, ThreadId INTEGER, Priority INTEGER, Text VARCHAR, DateTime DATE)"

The table name is configurable through "table" property. Other than DateTime filed name used for optional time-based archiving purposes, currently the field names are not mandated. However, it is recomended to use names as specified above.

To provide as non-intrusive operation as possbile, the log entries are cached and inserted into the target database asynchronously by default. The blocking, however, will occur before the next entry insertion with default timeout of 1 second. The default settings can be overridden (see async, timeout and throw properties for details). If throw property is false, insertion timeouts are ignored, otherwise a TimeoutException is thrown. To force insertion of every entry, set timeout to 0. This setting, however, introduces a risk of long blocking periods in case of remote server communication delays.

Inheritance

Direct Base Classes: Poco::Channel

All Base Classes: Poco::Channel, Poco::Configurable, Poco::RefCountedObject

Member Summary

Member Functions: close, getProperty, log, open, registerChannel, setProperty, wait

Inherited Functions: close, duplicate, getProperty, log, open, referenceCount, release, setProperty

Types Aliases

Ptr

using Ptr = Poco::AutoPtr < SQLChannel >;

Constructors

SQLChannel

SQLChannel();

Creates SQLChannel.

SQLChannel

SQLChannel(
    const std::string & connector,
    const std::string & connect,
    const std::string & name = "-"
);

Creates a SQLChannel with the given connector, connect string, timeout, table and name. The connector must be already registered.

Destructor

~SQLChannel protected virtual

~SQLChannel();

Member Functions

close virtual

void close();

Closes the SQLChannel.

getProperty virtual

std::string getProperty(
    const std::string & name
) const;

Returns the value of the property with the given name.

log virtual

void log(
    const Message & msg
);

Writes the log message to the database.

open virtual

void open();

Opens the SQLChannel.

registerChannel static

static void registerChannel();

Registers the channel with the global LoggingFactory.

setProperty virtual

void setProperty(
    const std::string & name,
    const std::string & value
);

Sets the property with the given value.

The following properties are supported:

  • name: The name used to identify the source of log messages. Defaults to "-".
  • connector: The target data storage connector name.
  • connect: The target data storage connection string.
  • table: Destination log table name. Defaults to "T_POCO_LOG". Table must exist in the target database.
  • keep: Max row age for the log table. To disable archiving, set this property to empty string or "forever".
  • archive: Archive table name. Defaults to "T_POCO_LOG_ARCHIVE". Table must exist in the target database. To disable archiving, set this property to empty string.
  • async: Indicates asynchronous execution. When excuting asynchronously, messages are sent to the target using asyncronous execution. However, prior to the next message being processed and sent to the target, the previous operation must have been either completed or timed out (see timeout and throw properties for details on how abnormal conditos are handled).
  • timeout: Timeout (ms) to wait for previous log operation completion. Values "0" and "" mean no timeout. Only valid when logging is asynchronous, otherwise ignored.
  • throw: Boolean value indicating whether to throw in case of timeout. Setting this property to false may result in log entries being lost. True values are (case insensitive) "true", "t", "yes", "y". Anything else yields false.

wait inline

std::size_t wait();

Waits for the completion of the previous operation and returns the result. If chanel is in synchronous mode, returns 0 immediately.

Variables

PROP_ARCHIVE_TABLE static

static const std::string PROP_ARCHIVE_TABLE;

PROP_ASYNC static

static const std::string PROP_ASYNC;

PROP_CONNECT static

static const std::string PROP_CONNECT;

PROP_CONNECTOR static

static const std::string PROP_CONNECTOR;

PROP_MAX_AGE static

static const std::string PROP_MAX_AGE;

PROP_NAME static

static const std::string PROP_NAME;

PROP_TABLE static

static const std::string PROP_TABLE;

PROP_THROW static

static const std::string PROP_THROW;

PROP_TIMEOUT static

static const std::string PROP_TIMEOUT;

Securely control IoT edge devices from anywhere   Connect a Device