Example usage for java.util.logging Logger getLogger

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

Introduction

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

Prototype




@CallerSensitive
public static Logger getLogger(String name) 

Source Link

Document

Find or create a logger for a named subsystem.

Usage

From source file:MainClass.java

public static void main(String[] args) {
    Logger logger = Logger.getLogger("DeviceLog");

    logger.info("<Device id=\"99\"/>");
}

From source file:Logging.java

public static void main(String[] args) {
    Logger log = Logger.getLogger("global");

    log.finest("A");
    log.finer("B");
    log.fine("C");
    log.config("D");
    log.info("E");
    log.warning("O");
    log.severe("A");
}

From source file:MainClass.java

public static void main(String[] args) {
    Logger logger = Logger.getLogger("com.java2s.log");

    logger.severe("severe");
    logger.warning("warning");
    logger.info("info");
    logger.config("config");
    logger.fine("fine");
    logger.finer("finer");
    logger.finest("value =" + 42);
}

From source file:Main.java

public static void main(String[] argv) throws Exception {
    Logger logger = Logger.getLogger("com.mycompany");

    // Stop forwarding log records to ancestor handlers
    logger.setUseParentHandlers(false);/*  w w  w .  j a  v a 2  s .c  o m*/

    // Start forwarding log records to ancestor handlers
    logger.setUseParentHandlers(true);
}

From source file:Main.java

public static void main(String[] argv) throws Exception {

    Logger logger = Logger.getLogger("com.mycompany.MyClass");

    // Check if the message will be logged
    if (logger.isLoggable(Level.FINEST)) {
        logger.finest("my finest message");
    }/*www . ja va 2s .  c  o  m*/
}

From source file:Main.java

public static void main(String[] argv) {
    Logger logger = Logger.getLogger("com.mycompany.MyClass");
    try {//  ww w . j a  v  a 2s.  c  o  m
        throw new IOException();
    } catch (Throwable e) {
        logger.log(Level.SEVERE, "Uncaught exception", e);
    }
    Exception ex = new IllegalStateException();
    logger.throwing("Main class", "myMethod", ex);
}

From source file:Main.java

public static void main(String[] argv) throws Exception {
    Logger logger = Logger.getLogger("com.mycompany");
    FileHandler fh = new FileHandler("mylog.txt");
    fh.setFormatter(new SimpleFormatter());
    logger.addHandler(fh);/*from   w  w  w  .j a  v  a2  s  .c om*/

    // fh = new FileHandler("mylog.xml");
    // fh.setFormatter(new XMLFormatter());
    // logger.addHandler(fh);

    // Log a few messages
    logger.severe("my severe message");
    logger.warning("my warning message");
    logger.info("my info message");
    logger.config("my config message");
    logger.fine("my fine message");
    logger.finer("my finer message");
    logger.finest("my finest message");
}

From source file:Main.java

public static void main(String args[]) throws Exception {
    Logger logger = Logger.getLogger("your.logging");
    ConsoleHandler handler = new ConsoleHandler();
    MemoryHandler mHandler = new MemoryHandler(handler, 10, Level.ALL);
    logger.addHandler(mHandler);/*from   w w  w  .j  a  v  a2 s  .  com*/
    logger.setUseParentHandlers(false);
    LogRecord record1 = new LogRecord(Level.SEVERE, "This is SEVERE level message");
    LogRecord record2 = new LogRecord(Level.WARNING, "This is WARNING level message");
    logger.log(record1);
    logger.log(record2);
}

From source file:MainClass.java

public static void main(String args[]) {

    Logger logger = Logger.getLogger("my.log");

    Handler handler = null;//from  w  w w  .j a va  2s .co  m

    try {
        handler = new FileHandler("messages.log");
    } catch (IOException e) {
        System.out.println("Could not create file. Using the console handler");
        handler = new ConsoleHandler();
    }

    logger.addHandler(handler);

    handler.setFormatter(new XMLFormatter());

    logger.info("Our first logging message");
    logger.severe("Something terrible happened");
}

From source file:MyLevel.java

public static void main(String[] argv) throws Exception {
    Logger logger = Logger.getLogger("com.mycompany");
    logger.log(MyLevel.DISASTER, "my disaster message");

    Level disaster = Level.parse("DISASTER");
    logger.log(disaster, "my disaster message");
}