The Logger Facet
4 min read
4 min read
4 min read
4 min read
4 min read
4 min read
4 min read
4 min read
4 min read
The Logger facet lets an administrative client read the log of a running program: it retrieves the recent log messages, or it attaches a remote logger that receives each new message. The facet intercepts the messages sent to the program's logger, caches the most recent ones, and forwards each new message to the attached remote loggers.
Each message is an Ice::LogMessage with a type (print, trace, warning, or error), a timestamp in microseconds since the Unix epoch, a trace category, and the message text.
Filtering Log Messages
The Logger facet implements the Ice::LoggerAdminIce::LoggerAdminIce::LoggerAdminIce::LoggerAdminIce::LoggerAdminIce::LoggerAdminIce::LoggerAdminIce::LoggerAdmin interface. Its getLog and attachRemoteLogger operations take the same three filters:
messageTypesselects the types of messages; an empty sequence selects all types.traceCategoriesselects the categories of trace messages; an empty sequence selects all categories. Other message types pass this filter.messageMaxis the maximum number of cached messages to select, starting with the most recent; a negative value selects all the cached messages that match the other filters, and0selects none.
Retrieving Recent Log Messages
getLog returns the cached messages that match the filters, and the prefix of the program's logger. For example, the following C++ code retrieves the 10 most recent errors and Network trace messages:
Ice::ObjectPrx admin = ...auto loggerAdmin = admin.ice_facet<Ice::LoggerAdminPrx>("Logger");
Ice::LogMessageTypeSeq messageTypes{ Ice::LogMessageType::ErrorMessage, Ice::LogMessageType::TraceMessage};Ice::StringSeq traceCategories{"Network"};
string prefix;auto logMessages = loggerAdmin->getLog(messageTypes, traceCategories, 10, prefix);Attaching a Remote Logger
A remote logger is an Ice object with the Ice::RemoteLoggerIce::RemoteLoggerIce::RemoteLoggerIce::RemoteLoggerIce::RemoteLoggerIce::RemoteLoggerIce::RemoteLogger interface, typically provided by the administrative client. Its init operation receives the prefix of the program's logger and the cached messages that match the filters, and its log operation receives each new message that matches the filters. Swift maps the init operation to initialize.
attachRemoteLogger attaches a remote logger with its filters. For example, the following C++ code attaches a remote logger that receives every message, with the 10 most recent cached messages passed to init:
Ice::RemoteLoggerPrx remoteLogger = ...loggerAdmin->attachRemoteLogger(remoteLogger, Ice::LogMessageTypeSeq{}, Ice::StringSeq{}, 10);The Logger facet identifies a remote logger by the identity in its proxy: a remote logger can be attached only once, and detachRemoteLogger detaches the remote logger with the identity of the proxy it receives. The facet also detaches a remote logger when a call to this remote logger fails.
Configuring the Logger Facet
Logger FacetIce.Admin.Logger.KeepLogs sets the number of print, warning, and error messages that the Logger facet caches, and Ice.Admin.Logger.KeepTraces the number of trace messages. Both default to 100.
The Logger facet sends messages to remote loggers with a communicator of its own, which you configure with Ice.Admin.Logger.Properties, and not over the connection that delivered the attachRemoteLogger request. The remote logger must therefore be reachable from the monitored program. Set Ice.Trace.Admin.Logger to trace the attachment and detachment of remote loggers and the sending of messages to them.
Ice for Python does not expose the built-in Logger facet as a local object: communicator.findAdminFacet("Logger") returns None. To interact with the Logger facet of your own communicator, use a proxy, as shown for a remote facet.
Ice for Swift does not expose the built-in Logger facet as a local LoggerAdmin object. To interact with the Logger facet of your own communicator, use a proxy, as shown for a remote facet.