Search in sources :

Example 46 with FileHandler

use of java.util.logging.FileHandler in project 360-Engine-for-Android by 360.

the class LogUtils method enableLogcat.

/**
 * Enable logging.
 */
public static void enableLogcat() {
    mEnabled = true;
    /**
     * Enable the SD Card logger *
     */
    sLogger = Logger.getLogger(APP_NAME_PREFIX);
    try {
        FileHandler fileHandler = new FileHandler(APP_FILE_NAME, LOG_FILE_LIMIT, LOG_FILE_COUNT);
        fileHandler.setFormatter(new Formatter() {

            @Override
            public String format(final LogRecord logRecord) {
                StringBuilder sb = new StringBuilder();
                sb.append(DATE_FORMAT.format(new Date(logRecord.getMillis())));
                sb.append(" ");
                sb.append(logRecord.getMessage());
                sb.append("\n");
                return sb.toString();
            }
        });
        sLogger.addHandler(fileHandler);
    } catch (IOException e) {
        logE("LogUtils.logToFile() IOException, data will not be logged " + "to file", e);
        sLogger = null;
    }
    if (Settings.ENABLED_PROFILE_ENGINES) {
        /**
         * Enable the SD Card profiler *
         */
        sProfileLogger = Logger.getLogger("profiler");
        try {
            FileHandler fileHandler = new FileHandler("/sdcard/engineprofiler.log", LOG_FILE_LIMIT, LOG_FILE_COUNT);
            fileHandler.setFormatter(new Formatter() {

                @Override
                public String format(final LogRecord logRecord) {
                    StringBuilder sb = new StringBuilder();
                    sb.append(DATE_FORMAT.format(new Date(logRecord.getMillis())));
                    sb.append("|");
                    sb.append(logRecord.getMessage());
                    sb.append("\n");
                    return sb.toString();
                }
            });
            sProfileLogger.addHandler(fileHandler);
        } catch (IOException e) {
            logE("LogUtils.logToFile() IOException, data will not be logged " + "to file", e);
            sProfileLogger = null;
        }
    }
}
Also used : LogRecord(java.util.logging.LogRecord) Formatter(java.util.logging.Formatter) IOException(java.io.IOException) Date(java.util.Date) FileHandler(java.util.logging.FileHandler)

Example 47 with FileHandler

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

the class TCPUtils method setLogging.

public static void setLogging(SeverityLevel slevel) {
    logging = slevel != SeverityLevel.LOG_NONE;
    if (logging == true && filehandler == null) {
        try {
            Date d = new Date();
            String filename = "TCP" + DateFormatUtils.format(d, "yyyy-MM-dd HH-mm-ss") + ".log";
            filehandler = new FileHandler("logs" + File.separator + filename);
            filehandler.setFormatter(new UTCFormatter());
        } catch (SecurityException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        } catch (IOException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
        // Don't flood the parent log.
        logger.setUseParentHandlers(false);
        logger.addHandler(filehandler);
    }
    logger.setLevel(slevel.getLevel());
    loggingSeverityLevel = slevel;
}
Also used : IOException(java.io.IOException) Date(java.util.Date) FileHandler(java.util.logging.FileHandler)

Example 48 with FileHandler

use of java.util.logging.FileHandler in project MyPet by xXKeyleXx.

the class MyPetLogger method setupDebugLogger.

protected boolean setupDebugLogger() {
    if (getHandlers().length > 0) {
        for (Handler h : getHandlers()) {
            if (h.toString().equals("MyPet-Debug-Logger-FileHandler")) {
                if (Configuration.Log.LEVEL.equalsIgnoreCase("OFF")) {
                    removeHandler(h);
                    h.close();
                    return false;
                }
                debugLogFileHandler = (FileHandler) h;
                return true;
            }
        }
    }
    if (Configuration.Log.LEVEL.equalsIgnoreCase("OFF")) {
        return false;
    }
    if (debugLogFileHandler != null) {
        addHandler(debugLogFileHandler);
        return true;
    }
    try {
        File logsFolder = new File(MyPetApi.getPlugin().getDataFolder(), "logs");
        logsFolder.mkdirs();
        File logFile = new File(logsFolder, File.separator + "MyPet.log");
        FileHandler fileHandler = new FileHandler(logFile.getAbsolutePath(), true) {

            @Override
            public String toString() {
                return "MyPet-Debug-Logger-FileHandler";
            }
        };
        Level level;
        try {
            level = Level.parse(Configuration.Log.LEVEL);
        } catch (IllegalArgumentException e) {
            level = Level.OFF;
            this.warning(e.getMessage());
        }
        fileHandler.setLevel(level);
        System.out.println("Level: " + level);
        fileHandler.setFormatter(new LogFormat());
        addHandler(fileHandler);
        debugLogFileHandler = fileHandler;
        return true;
    } catch (IOException e) {
        e.printStackTrace();
        return false;
    }
}
Also used : LogFormat(de.Keyle.MyPet.api.util.LogFormat) FileHandler(java.util.logging.FileHandler) Handler(java.util.logging.Handler) Level(java.util.logging.Level) IOException(java.io.IOException) File(java.io.File) FileHandler(java.util.logging.FileHandler)

Example 49 with FileHandler

use of java.util.logging.FileHandler in project Payara by payara.

the class LoggingAnnotationsTest method initializeLoggingAnnotationsTest.

@BeforeClass
public static void initializeLoggingAnnotationsTest() throws Exception {
    File basePath = new File(BASE_PATH);
    basePath.mkdirs();
    // Add a file handler with UniformLogFormatter
    uniformFormatHandler = new FileHandler(ULF_LOG);
    uniformFormatHandler.setLevel(Level.FINE);
    uniformFormatHandler.setFormatter(new UniformLogFormatter());
    // Add a file handler with ODLLogFormatter
    odlFormatHandler = new FileHandler(ODL_LOG);
    odlFormatHandler.setLevel(Level.FINE);
    odlFormatHandler.setFormatter(new ODLLogFormatter());
    consoleHandler = new ConsoleHandler();
    consoleHandler.setFormatter(new UniformLogFormatter());
    LOGGER.addHandler(uniformFormatHandler);
    LOGGER.addHandler(odlFormatHandler);
    Boolean enableConsoleHandler = Boolean.getBoolean(LoggingAnnotationsTest.class.getName() + ".enableConsoleHandler");
    if (enableConsoleHandler) {
        LOGGER.addHandler(consoleHandler);
    }
    LOGGER.setUseParentHandlers(false);
    LOGGER.setLevel(Level.FINE);
}
Also used : File(java.io.File) ConsoleHandler(java.util.logging.ConsoleHandler) FileHandler(java.util.logging.FileHandler) BeforeClass(org.junit.BeforeClass)

Aggregations

FileHandler (java.util.logging.FileHandler)49 IOException (java.io.IOException)22 File (java.io.File)15 SimpleFormatter (java.util.logging.SimpleFormatter)11 Handler (java.util.logging.Handler)10 ConsoleHandler (java.util.logging.ConsoleHandler)5 LogRecord (java.util.logging.LogRecord)5 Formatter (java.util.logging.Formatter)4 Logger (java.util.logging.Logger)3 Config (edu.neu.ccs.pyramid.configuration.Config)2 Date (java.util.Date)2 Setup (org.openjdk.jmh.annotations.Setup)2 LogFormatter (com.facebook.buck.log.LogFormatter)1 HumanReadableException (com.facebook.buck.util.HumanReadableException)1 NaviLogFormatter (com.google.security.zynamics.binnavi.Log.NaviLogFormatter)1 FileReadException (com.google.security.zynamics.binnavi.config.FileReadException)1 LogFormat (de.Keyle.MyPet.api.util.LogFormat)1 RcvrExceptionHandler (edu.cmu.cs.hcii.cogtool.ui.RcvrExceptionHandler)1 RuntimeIOException (edu.stanford.nlp.io.RuntimeIOException)1 NewlineLogFormatter (edu.stanford.nlp.util.logging.NewlineLogFormatter)1