Skip to main content
Skip table of contents

Custom Logger Plug-in

The preferred way to install a custom logger into a communicator is by setting the logger field of the communicator's IntializationData.

However, in some situations, you have no access to InitalizationData, for example:

  • you are writing an IceBox service

  • you want to install a custom logger without changing any source code

The plug-in facility allows you to inject your custom logger into the communicator at runtime, during communicator initialization.

Installing a Custom Logger

Ice provides a plug-in class, com.zeroc.Ice.LoggerPlugin, that installs a logger into the communicator in its constructor:

JAVA
package com.zeroc.Ice;

public class LoggerPlugin implements Plugin
{
    public LoggerPlugin(Communicator communicator, Logger logger) {
       ...
    }
  
    @Override
    public void initialize() {}
    
    @Override
    public void destroy() {}
}

The implementation of initialize and destroy in LoggerPlugin are no-op.

Now, assuming you wrote a CustomLogger class that implements com.zeroc.Ice.Logger, you can easily create a plug-in factory that creates a LoggerPlugin and installs your logger into the communicator:

JAVA
package com.example.clearsky;

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:

CODE
Ice.Plugin.CustomLogger=customlogger.jar:com.example.clearsky.CustomLoggerPluginFactory

Even though you didn’t implement the plug-in class (LoggerPlugin), you are in effect creating a new plug-in since you choose the logger given to the LoggerPlugin constructor. As a result, you can pick any name for the plug-in factory and the plug-in itself.

See Also
JavaScript errors detected

Please note, these errors can depend on your browser setup.

If this problem persists, please contact our support.