Actions
Logging guidelines » History » Revision 1
Revision 1/4
| Next »
Moritz Horsch, 06/13/2012 11:20 AM
Logging guidelines¶
- Table of contents
- Logging guidelines
Framework¶
SLF4J (Simple Logging Facade for Java)¶
Maven¶
No dependency SHOULD be added to the module POM. The dependencies are already defined in the ecard client POM.
Preamble¶
import org.slf4j.Logger; import org.slf4j.LoggerFactory; private static final Logger logger = LoggerFactory.getLogger(MYCLASS.class);
SLF4J with java.util.logging backend¶
This code SHOULD only be using in JUnit tests.
// Reset configuration to avoid multiple log entries. java.util.logging.LogManager.getLogManager().reset(); // Add new console handler ConsoleHandler ch = new ConsoleHandler(); ch.setLevel(Level.ALL); // Set logging level LogManager.getLogger(MYCLASS.class.getName()).setLevel(Level.FINE); // Log message as jdk logging level INFO logger.info(LoggingConstants.FINE, "Log my message: {}", message); // Log message as jdk logging level FINE logger.debug(LoggingConstants.FINE, "Log my message: {}", message); // Log message as jdk logging level WARNING logger.warn(LoggingConstants.FINE, "Log my message: {}", message); // Log message as jdk logging level SEVERE logger.error(LoggingConstants.FINE, "Log my message: {}", message);
Levels¶
Overview¶
Marker are specified in org.openecard.client.common.logging.LoggingConstants
- THROWING: Exceptions
- SEVERE:
- INFO:
- CONFIG:
- FINE: Messages
- FINER: Events
- FINEST:
Exceptions¶
import org.openecard.client.common.logging.LoggingConstants; import org.slf4j.Logger; import org.slf4j.LoggerFactory; private static final Logger logger = LoggerFactory.getLogger(MYCLASS.class); try{ ... } catch (Exception e){ // <editor-fold defaultstate="collapsed" desc="log exception"> logger.error(LoggingConstants.THROWING, "Exception", e); // </editor-fold> }
Messages¶
Messages including APDUs, eCard-API messages, PAOS messages.
import org.openecard.client.common.logging.LoggingConstants; import org.slf4j.Logger; import org.slf4j.LoggerFactory; private static final Logger logger = LoggerFactory.getLogger(MYCLASS.class); // <editor-fold defaultstate="collapsed" desc="log message"> logger.debug(LoggingConstants.FINE, "Message received:\n{}", message); // </editor-fold> // <editor-fold defaultstate="collapsed" desc="log message"> logger.debug(LoggingConstants.FINE, "Message sent:\n{}", message); // </editor-fold>
Events¶
E.g. GUI events.
import org.openecard.client.common.logging.LoggingConstants; import org.slf4j.Logger; import org.slf4j.LoggerFactory; private static final Logger logger = LoggerFactory.getLogger(MYCLASS.class); // <editor-fold defaultstate="collapsed" desc="log event"> logger.debug(LoggingConstants.FINER, "Event: {}", event); // </editor-fold>
Notes¶
Trace statements are omitted¶
logger.trace("Trace a message: {}", message);
Will be replaced by slf4j extension.
Examples¶
APDU logging¶
import org.openecard.client.common.ECardConstants; import org.openecard.client.common.logging.LogManager; java.util.logging.LogManager.getLogManager().reset(); ConsoleHandler ch = new ConsoleHandler(); ch.setLevel(Level.ALL); LogManager.getLogger("org.openecard.client.ifd.scio.wrapper").addHandler(ch); LogManager.getLogger("org.openecard.client.ifd.scio.wrapper").setLevel(Level.FINE);
Updated by Moritz Horsch over 12 years ago · 1 revisions