O'Reilly logo

Java 9 Concurrency Cookbook - Second Edition by Javier Fernández González

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

How to do it...

Follow these steps to implement the example:

  1. Create a class named MyFormatter that extends the java.util.logging.Formatter class. Implement the abstract format() method. It receives a LogRecord object as a parameter and returns a String object with a log message:
        public class MyFormatter extends Formatter {           @Override           public String format(LogRecord record) {              StringBuilder sb=new StringBuilder();             sb.append("["+record.getLevel()+"] - ");             sb.append(new Date(record.getMillis())+" : ");             sb.append(record.getSourceClassName()+ "."                      +record.getSourceMethodName()+" : ");             sb.append(record.getMessage()+"\n");.             return sb.toString();           }
  1. Create a class named MyLoggerFactory:
        public class MyLoggerFactory {
  1. Declare a private ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required