Example usage for java.util.logging Logger Logger

List of usage examples for java.util.logging Logger Logger

Introduction

In this page you can find the example usage for java.util.logging Logger Logger.

Prototype

protected Logger(String name, String resourceBundleName) 

Source Link

Document

Protected method to construct a logger for a named subsystem.

Usage

From source file:SerialLogger.java

public SerialLogger()
        throws IOException, NoSuchPortException, PortInUseException, UnsupportedCommOperationException {

    // get list of ports available on this particular computer,
    // by calling static method in CommPortIdentifier.
    Enumeration pList = CommPortIdentifier.getPortIdentifiers();

    // Process the list, processing only serial ports.
    while (pList.hasMoreElements()) {
        CommPortIdentifier cpi = (CommPortIdentifier) pList.nextElement();
        String name = cpi.getName();
        System.out.print("Port " + name + " ");
        if (cpi.getPortType() == CommPortIdentifier.PORT_SERIAL) {
            System.out.println("is a Serial Port: " + cpi);

            SerialPort thePort;//from w w  w .j  a v  a 2s . c  o  m
            try {
                thePort = (SerialPort) cpi.open("Logger", 1000);
            } catch (PortInUseException ev) {
                System.err.println("Port in use: " + name);
                continue;
            }

            // Tell the Comm API that we want serial events.
            thePort.notifyOnDataAvailable(true);
            try {
                thePort.addEventListener(new Logger(cpi.getName(), thePort));
            } catch (TooManyListenersException ev) {
                // "CantHappen" error
                System.err.println("Too many listeners(!) " + ev);
                System.exit(0);
            }
        }
    }
}