---
title: "Custom Logger Plug-in"
url: https://docs.zeroc.com/ice/3.8/plugins/custom-logger-plug-in
docs_index: https://docs.zeroc.com/llms.txt
---

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

# Custom Logger Plug-in

Parts of this page are for some programming languages only, and name them. For one language's text alone, see [C++](https://docs.zeroc.com/ice/3.8/plugins/custom-logger-plug-in/cpp.md), [C#](https://docs.zeroc.com/ice/3.8/plugins/custom-logger-plug-in/csharp.md), [Java](https://docs.zeroc.com/ice/3.8/plugins/custom-logger-plug-in/java.md), [JavaScript](https://docs.zeroc.com/ice/3.8/plugins/custom-logger-plug-in/js.md), [MATLAB](https://docs.zeroc.com/ice/3.8/plugins/custom-logger-plug-in/matlab.md), [PHP](https://docs.zeroc.com/ice/3.8/plugins/custom-logger-plug-in/php.md), [Python](https://docs.zeroc.com/ice/3.8/plugins/custom-logger-plug-in/python.md), [Ruby](https://docs.zeroc.com/ice/3.8/plugins/custom-logger-plug-in/ruby.md), and [Swift](https://docs.zeroc.com/ice/3.8/plugins/custom-logger-plug-in/swift.md).

> **C++, C#, Java, JavaScript, Python, and Swift**
>
> When you create a communicator in your own code, install a custom logger by setting `InitializationData.logger`.

A logger plug-in installs a custom logger through configuration, during communicator initialization. Use a logger plug-in when you don't create the communicator yourself, for example in an IceBox service, or when you want to install a custom logger without changing any source code.

> **C++, C#, and Java**
>
> Adding a logger plug-in factory to `InitializationData.pluginFactories` works too, but it is more work for the same result as setting `InitializationData.logger`.

## Installing a Custom Logger

> **C++**
>
> Ice provides [`Ice::LoggerPlugin`](https://code.zeroc.com/ice/3.8/api/cpp/classIce_1_1LoggerPlugin.html), a plug-in that installs a logger into the communicator. Assuming you wrote a `CustomLogger` class that implements `Ice::Logger`, create a plug-in factory function that returns a `LoggerPlugin` for your logger:
>
> ```cpp
> extern "C" ICE_DECLSPEC_EXPORT Ice::Plugin* createCustomLoggerPlugin(
>     const Ice::CommunicatorPtr& communicator,
>     const std::string&,
>     const Ice::StringSeq&)
> {
>     return new Ice::LoggerPlugin(communicator, std::make_shared<CustomLogger>());
> }
> ```
>
> Then, package your `CustomLogger` implementation and `createCustomLoggerPlugin` in a shared library or DLL, and configure your communicator to load it at runtime. For example:
>
> ```config
> Ice.Plugin.CustomLogger=customlogger,0:createCustomLoggerPlugin
> ```
>
> With `customlogger,0`, Ice loads `customlogger0.dll` on Windows, `libcustomlogger.so.0` on Linux, and `libcustomlogger.0.dylib` on macOS. See [Ice.Plugin.name](https://docs.zeroc.com/ice/3.8/property-reference/ice-plugin-properties/cpp.md#ice.plugin.name) for the format of this entry point.

> **C#**
>
> Ice provides [`Ice.LoggerPlugin`](https://code.zeroc.com/ice/3.8/api/csharp/api/Ice.LoggerPlugin.html), a plug-in that installs a logger into the communicator. The communicator takes ownership of the logger and disposes it when the communicator is destroyed.
>
> Assuming you wrote a `CustomLogger` class that implements `Ice.Logger`, create a plug-in factory that returns a `LoggerPlugin` for your logger:
>
> ```csharp
> namespace ClearSky;
>
> public class CustomLoggerPluginFactory : Ice.PluginFactory
> {
>     public string pluginName => "CustomLogger";
>
>     public Ice.Plugin create(
>         Ice.Communicator communicator,
>         string name,
>         string[] args) =>
>         new Ice.LoggerPlugin(communicator, new CustomLogger());
> }
> ```
>
> Then, package your `CustomLogger` implementation and `CustomLoggerPluginFactory` in a .NET assembly, and configure your communicator to load it at runtime. For example:
>
> ```config
> Ice.Plugin.CustomLogger=CustomLogger.dll:ClearSky.CustomLoggerPluginFactory
> ```

> **Java**
>
> Ice provides [`com.zeroc.Ice.LoggerPlugin`](https://code.zeroc.com/ice/3.8/api/java/com.zeroc.ice/com/zeroc/Ice/LoggerPlugin.html), a plug-in that installs a logger into the communicator. The communicator takes ownership of the logger and closes it when the communicator is destroyed.
>
> Assuming you wrote a `CustomLogger` class that implements `com.zeroc.Ice.Logger`, create a plug-in factory that returns a `LoggerPlugin` for your logger:
>
> ```java
> package com.example.clearsky;
>
> import com.zeroc.Ice.Communicator;
> import com.zeroc.Ice.LoggerPlugin;
> import com.zeroc.Ice.Plugin;
> import com.zeroc.Ice.PluginFactory;
>
> public class CustomLoggerPluginFactory implements PluginFactory {
>     @Override
>     public String getPluginName() {
>         return "CustomLogger";
>     }
>
>     @Override
>     public Plugin create(Communicator communicator, String name, String[] args) {
>         return new LoggerPlugin(communicator, new CustomLogger());
>     }
> }
> ```
>
> Then, package your `CustomLogger` implementation and `CustomLoggerPluginFactory` in a JAR file, and configure your communicator to load it at runtime. For example:
>
> ```config
> Ice.Plugin.CustomLogger=customlogger.jar:com.example.clearsky.CustomLoggerPluginFactory
> ```

> **JavaScript**
>
> > **Note**
> >
> > JavaScript installs a custom logger through InitializationData.logger.

> **MATLAB**
>
> You implement a logger plug-in in C++, as shown in the [C++ version of this page](https://docs.zeroc.com/ice/3.8/plugins/custom-logger-plug-in/cpp.md), and load its shared library through configuration:
>
> ```config
> Ice.Plugin.CustomLogger=customlogger,0:createCustomLoggerPlugin
> ```
>
> With `customlogger,0`, Ice loads `customlogger0.dll` on Windows and `libcustomlogger.so.0` on Linux. See [Ice.Plugin.name](https://docs.zeroc.com/ice/3.8/property-reference/ice-plugin-properties/matlab.md#ice.plugin.name) for the format of this entry point.

> **PHP and Ruby**
>
> You implement a logger plug-in in C++, as shown in the [C++ version of this page](https://docs.zeroc.com/ice/3.8/plugins/custom-logger-plug-in/cpp.md), and load its shared library through configuration:
>
> ```config
> Ice.Plugin.CustomLogger=customlogger,0:createCustomLoggerPlugin
> ```
>
> With `customlogger,0`, Ice loads `libcustomlogger.so.0` on Linux and `libcustomlogger.0.dylib` on macOS. See [Ice.Plugin.name](https://docs.zeroc.com/ice/3.8/property-reference/ice-plugin-properties.md#ice.plugin.name) for the format of this entry point.

> **Python**
>
> You implement a logger plug-in in C++, as shown in the [C++ version of this page](https://docs.zeroc.com/ice/3.8/plugins/custom-logger-plug-in/cpp.md), and load its shared library through configuration:
>
> ```config
> Ice.Plugin.CustomLogger=customlogger,0:createCustomLoggerPlugin
> ```
>
> With `customlogger,0`, Ice loads `customlogger0.dll` on Windows, `libcustomlogger.so.0` on Linux, and `libcustomlogger.0.dylib` on macOS. See [Ice.Plugin.name](https://docs.zeroc.com/ice/3.8/property-reference/ice-plugin-properties/python.md#ice.plugin.name) for the format of this entry point.

> **Swift**
>
> You implement a logger plug-in in C++, as shown in the [C++ version of this page](https://docs.zeroc.com/ice/3.8/plugins/custom-logger-plug-in/cpp.md), and load its shared library through configuration:
>
> ```config
> Ice.Plugin.CustomLogger=customlogger,0:createCustomLoggerPlugin
> ```
>
> With `customlogger,0`, Ice loads `libcustomlogger.0.dylib`. See [Ice.Plugin.name](https://docs.zeroc.com/ice/3.8/property-reference/ice-plugin-properties/swift.md#ice.plugin.name) for the format of this entry point.

## See Also

- [Custom Loggers](https://docs.zeroc.com/ice/3.8/administration/logger-facility/custom-loggers.md)
- [The Per-Process Logger](https://docs.zeroc.com/ice/3.8/administration/logger-facility/per-process-logger.md)
- [Plug-in Facility](https://docs.zeroc.com/ice/3.8/plugins/plug-in-facility.md)
- [Ice.Plugin.\*](https://docs.zeroc.com/ice/3.8/property-reference/ice-plugin-properties.md)
