C Configure Logging for the Java Card Development Kit Tools

  1. Logging mechanism overview

    The Java Card Development Kit Tools output messages can be configured by users to select the level of details displayed, redirect, reformat or fully customize the messages.

    The tools are using the Java Logging API for all messages. More detailed documentation about logging configuration can be found at this link: https://docs.oracle.com/en/java/javase/17/core/java-logging-overview.html#GUID-B83B652C-17EA-48D9-93D2-563AE1FF8EDA__HANDLERS-4D023767

    By default, if no other configuration is provided, the tools are using the properties from logging.properties found inside <tools>/lib/tools.jar:

    handlers=java.util.logging.ConsoleHandler
    java.util.logging.ConsoleHandler.level=INFO
    java.util.logging.ConsoleHandler.formatter=java.util.logging.SimpleFormatter
    java.util.logging.SimpleFormatter.format=[ %4$s ] %5$s%6$s%n
    

    The standard ConsoleHandler is writing messages in stderr. All the messages produced by the tools are defined in the MessageBundle.properties files contained also in <tools>/lib/tools.jar, one for each tool (converter, verifier etc.).

  2. How to customize logging

    The default logging can be configured differently by providing other logging properties when running the tools using the following parameter on the command line “-Djava.util.logging.config.file=<path to config file>”.

    Choose LEVEL of messages displayed

    To just select the level of messages displayed, you can use a copy of the default logging.properties and just change the level as follows:

    java.util.logging.ConsoleHandler.level=WARNING

    Redirect output (e.g. to a file)

    To redirect the output to a specific file, you can use a copy of the default logging.properties and change the level as follows:

    handlers=java.util.logging.FileHandler

    Reformat output

    To reformat the output, you can use a copy of the default logging.properties and change the level as follows:

    java.util.logging.SimpleFormatter.format=<define your format>

    Filter messages displayed

    To choose messages to display, you can create a filter as follows:

    1. Use a copy of the default logging.properties and add a filter:
      java.util.logging.ConsoleHandler.filter=com.oracle.javacard.logging.logfilter.LogFilter
    2. Create your filter.

      Example:

      package com.oracle.javacard.logging.logfilter;
       import java.util.logging.Filter;
       import java.util.logging.LogRecord;
      
       public class LogFilter implements Filter{
         @Override
         public boolean isLoggable(LogRecord record) {
           // Skip the output message when there is 0 error(s) and 0 warning(s)
           return !(record.getMessage().equals("out.1")
             && (Integer.parseInt((String)record.getParameters()[0]) == 0)
             && (Integer.parseInt((String)record.getParameters()[1]) == 0));
         }
      }
    3. Include the LogFilter in classpath and use the new logging.properties.

    Customize fully the message

    Finally, if you need even more customization, you can define your own class implementing java.util.logging.Handler interface