Search in sources :

Example 31 with SimpleFormatter

use of java.util.logging.SimpleFormatter in project malmo by Microsoft.

the class TCPSocketHelper method setLogging.

static void setLogging(boolean log) {
    logging = log;
    if (log == true && filehandler == null) {
        try {
            filehandler = new FileHandler("TCPLog.txt");
            filehandler.setFormatter(new SimpleFormatter());
        } catch (SecurityException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        } catch (IOException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
        logger.addHandler(filehandler);
    }
}
Also used : SimpleFormatter(java.util.logging.SimpleFormatter) IOException(java.io.IOException) FileHandler(java.util.logging.FileHandler)

Example 32 with SimpleFormatter

use of java.util.logging.SimpleFormatter in project jreversepro by akkumar.

the class CustomLoggerFactory method createLogger.

public static Logger createLogger() {
    final Logger logger = Logger.getLogger("JReversePro");
    final SimpleFormatter formatter = new SimpleFormatter();
    final StreamHandler handler = new StreamHandler(System.out, formatter);
    logger.addHandler(handler);
    logger.setLevel(Level.FINER);
    return logger;
}
Also used : SimpleFormatter(java.util.logging.SimpleFormatter) StreamHandler(java.util.logging.StreamHandler) Logger(java.util.logging.Logger)

Example 33 with SimpleFormatter

use of java.util.logging.SimpleFormatter in project heron by twitter.

the class LoggingHelper method getFileHandler.

/**
   * Initialize a <tt>FileHandler</tt> to write to a set of files
   * with optional append.  When (approximately) the given limit has
   * been written to one file, another file will be opened.  The
   * output will cycle through a set of count files.
   * The pattern of file name should be: ${processId}.log.index
   * <p>
   * The <tt>FileHandler</tt> is configured based on <tt>LogManager</tt>
   * properties (or their default values) except that the given pattern
   * argument is used as the filename pattern, the file limit is
   * set to the limit argument, and the file count is set to the
   * given count argument, and the append mode is set to the given
   * <tt>append</tt> argument.
   * <p>
   * The count must be at least 1.
   *
   * @param limit the maximum number of bytes to write to any one file
   * @param count the number of files to use
   * @param append specifies append mode
   * @throws IOException if there are IO problems opening the files.
   * @throws SecurityException if a security manager exists and if
   * the caller does not have <tt>LoggingPermission("control")</tt>.
   * @throws IllegalArgumentException if {@code limit < 0}, or {@code count < 1}.
   * @throws IllegalArgumentException if pattern is an empty string
   */
public static FileHandler getFileHandler(String processId, String loggingDir, boolean append, int limit, int count) throws IOException, SecurityException {
    String pattern = loggingDir + "/" + processId + ".log.%g";
    FileHandler fileHandler = new FileHandler(pattern, limit, count, append);
    fileHandler.setFormatter(new SimpleFormatter());
    fileHandler.setEncoding("UTF-8");
    return fileHandler;
}
Also used : SimpleFormatter(java.util.logging.SimpleFormatter) FileHandler(java.util.logging.FileHandler)

Example 34 with SimpleFormatter

use of java.util.logging.SimpleFormatter in project CoreNLP by stanfordnlp.

the class MachineReading method setConsoleLevel.

public static void setConsoleLevel(Level level) {
    // get the top Logger:
    Logger topLogger = java.util.logging.Logger.getLogger("");
    // Handler for console (reuse it if it already exists)
    Handler consoleHandler = null;
    // see if there is already a console handler
    for (Handler handler : topLogger.getHandlers()) {
        if (handler instanceof ConsoleHandler) {
            // found the console handler
            consoleHandler = handler;
            break;
        }
    }
    if (consoleHandler == null) {
        // there was no console handler found, create a new one
        consoleHandler = new ConsoleHandler();
        topLogger.addHandler(consoleHandler);
    }
    // set the console handler level:
    consoleHandler.setLevel(level);
    consoleHandler.setFormatter(new SimpleFormatter());
}
Also used : SimpleFormatter(java.util.logging.SimpleFormatter) ConsoleHandler(java.util.logging.ConsoleHandler) Handler(java.util.logging.Handler) Logger(java.util.logging.Logger) ConsoleHandler(java.util.logging.ConsoleHandler)

Example 35 with SimpleFormatter

use of java.util.logging.SimpleFormatter in project okhttp by square.

the class Main method enableHttp2FrameLogging.

private static void enableHttp2FrameLogging() {
    frameLogger = Logger.getLogger(Http2.class.getName());
    frameLogger.setLevel(Level.FINE);
    ConsoleHandler handler = new ConsoleHandler();
    handler.setLevel(Level.FINE);
    handler.setFormatter(new SimpleFormatter() {

        @Override
        public String format(LogRecord record) {
            return Util.format("%s%n", record.getMessage());
        }
    });
    frameLogger.addHandler(handler);
}
Also used : LogRecord(java.util.logging.LogRecord) SimpleFormatter(java.util.logging.SimpleFormatter) ConsoleHandler(java.util.logging.ConsoleHandler)

Aggregations

SimpleFormatter (java.util.logging.SimpleFormatter)42 StreamHandler (java.util.logging.StreamHandler)15 ByteArrayOutputStream (java.io.ByteArrayOutputStream)13 Logger (java.util.logging.Logger)13 FileHandler (java.util.logging.FileHandler)11 Handler (java.util.logging.Handler)8 LogRecord (java.util.logging.LogRecord)8 IOException (java.io.IOException)7 MockResponse (com.google.mockwebserver.MockResponse)6 HttpClient (org.apache.http.client.HttpClient)6 HttpGet (org.apache.http.client.methods.HttpGet)6 DefaultHttpClient (org.apache.http.impl.client.DefaultHttpClient)6 ConsoleHandler (java.util.logging.ConsoleHandler)4 File (java.io.File)3 Level (java.util.logging.Level)3 Test (org.junit.Test)3 Config (edu.neu.ccs.pyramid.configuration.Config)2 Properties (java.util.Properties)2 Formatter (java.util.logging.Formatter)2 MemoryHandler (java.util.logging.MemoryHandler)2