---
title: "The Logger Facet"
url: https://docs.zeroc.com/ice/3.8/administration/administrative-facility/logger-facet
language: cpp
docs_index: https://docs.zeroc.com/llms.txt
---

> For an index of every page, see [llms.txt](https://docs.zeroc.com/llms.txt).

# The Logger Facet

Programming language: C++. Other languages: [C#](https://docs.zeroc.com/ice/3.8/administration/administrative-facility/logger-facet/csharp.md), [Java](https://docs.zeroc.com/ice/3.8/administration/administrative-facility/logger-facet/java.md), [JavaScript](https://docs.zeroc.com/ice/3.8/administration/administrative-facility/logger-facet/js.md), [MATLAB](https://docs.zeroc.com/ice/3.8/administration/administrative-facility/logger-facet/matlab.md), [PHP](https://docs.zeroc.com/ice/3.8/administration/administrative-facility/logger-facet/php.md), [Python](https://docs.zeroc.com/ice/3.8/administration/administrative-facility/logger-facet/python.md), [Ruby](https://docs.zeroc.com/ice/3.8/administration/administrative-facility/logger-facet/ruby.md), [Swift](https://docs.zeroc.com/ice/3.8/administration/administrative-facility/logger-facet/swift.md).

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](https://docs.zeroc.com/ice/3.8/administration/logger-facility/cpp.md), 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](https://en.wikipedia.org/wiki/Unix_time), a trace category, and the message text.

## Filtering Log Messages

The `Logger` facet implements the [`Ice::LoggerAdmin`](https://code.zeroc.com/ice/3.8/api/cpp/classIce_1_1LoggerAdminPrx.html) interface. Its `getLog` and `attachRemoteLogger` operations take the same three filters:

- `messageTypes` selects the types of messages; an empty sequence selects all types.
- `traceCategories` selects the categories of trace messages; an empty sequence selects all categories. Other message types pass this filter.
- `messageMax` is 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, and `0` selects 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:

```cpp
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::RemoteLogger`](https://code.zeroc.com/ice/3.8/api/cpp/classIce_1_1RemoteLogger.html) 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.

`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`:

```cpp
Ice::RemoteLoggerPrx remoteLogger = ...
loggerAdmin->attachRemoteLogger(remoteLogger, Ice::LogMessageTypeSeq{}, Ice::StringSeq{}, 10);
```

> **Note**
>
> The `Logger` facet can call `log` on a remote logger before it calls `init`, even though the messages passed to `init` are older. This is common in programs that log many messages. A remote logger must handle this order: for example, it can queue the messages it receives before `init` and append them to the messages that `init` delivers.

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

[Ice.Admin.Logger.KeepLogs](https://docs.zeroc.com/ice/3.8/property-reference/ice-admin-properties/cpp.md#ice.admin.logger.keeplogs) sets the number of print, warning, and error messages that the `Logger` facet caches, and [Ice.Admin.Logger.KeepTraces](https://docs.zeroc.com/ice/3.8/property-reference/ice-admin-properties/cpp.md#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](https://docs.zeroc.com/ice/3.8/property-reference/ice-admin-properties/cpp.md#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](https://docs.zeroc.com/ice/3.8/property-reference/ice-trace-properties/cpp.md#ice.trace.admin.logger) to trace the attachment and detachment of remote loggers and the sending of messages to them.

## See Also

- [Logger Facility](https://docs.zeroc.com/ice/3.8/administration/logger-facility/cpp.md)
- [Using the admin Object](https://docs.zeroc.com/ice/3.8/administration/administrative-facility/using-the-admin-object/cpp.md)
