Search in sources :

Example 61 with FileHandler

use of java.util.logging.FileHandler in project buck by facebook.

the class JavaUtilsLoggingBuildListener method ensureLogFileIsWritten.

public static void ensureLogFileIsWritten(ProjectFilesystem filesystem) {
    if (!filesystem.exists(filesystem.getBuckPaths().getScratchDir())) {
        try {
            filesystem.mkdirs(filesystem.getBuckPaths().getScratchDir());
        } catch (IOException e) {
            throw new HumanReadableException(e, "Unable to create output directory: %s: %s: %s", filesystem.getBuckPaths().getScratchDir(), e.getClass(), e.getMessage());
        }
    }
    try {
        FileHandler handler = new FileHandler(filesystem.resolve(filesystem.getBuckPaths().getScratchDir()).resolve("build.log").toString(), /* append */
        false);
        Formatter formatter = new BuildEventFormatter();
        handler.setFormatter(formatter);
        LOG.setUseParentHandlers(false);
        LOG.addHandler(handler);
        LOG.setLevel(LEVEL);
    } catch (IOException e) {
        throw new RuntimeException(e);
    }
}
Also used : HumanReadableException(com.facebook.buck.util.HumanReadableException) Formatter(java.util.logging.Formatter) IOException(java.io.IOException) FileHandler(java.util.logging.FileHandler)

Example 62 with FileHandler

use of java.util.logging.FileHandler in project buck by facebook.

the class JavaUtilsLoggingBuildListener method closeLogFile.

public static void closeLogFile() {
    for (Handler handler : LOG.getHandlers()) {
        if (handler instanceof FileHandler) {
            LOG.removeHandler(handler);
            handler.close();
        }
    }
}
Also used : FileHandler(java.util.logging.FileHandler) Handler(java.util.logging.Handler) FileHandler(java.util.logging.FileHandler)

Example 63 with FileHandler

use of java.util.logging.FileHandler in project cogtool by cogtool.

the class CogTool method enableLogging.

public static void enableLogging(boolean value) {
    if (value) {
        logger.setLevel(Level.ALL);
        for (Handler h : logger.getHandlers()) {
            if (h instanceof FileHandler) {
                return;
            }
        }
        FileHandler fh = null;
        try {
            fh = new FileHandler((CogToolPref.LOG_DIRECTORY.getString() + LOG_FILE_PATTERN), LOG_FILE_MAX_SIZE, LOG_FILES_MAX_COUNT, true);
        } catch (IOException ex) {
            logger.warning("Couldn't create log file: " + ex);
            return;
        }
        fh.setFormatter(new Formatter() {

            @Override
            public String format(LogRecord r) {
                long ms = r.getMillis();
                return String.format("%tF %tT.%tL\t%s\n", ms, ms, ms, r.getMessage());
            }
        });
        logger.addHandler(fh);
    } else {
        logger.setLevel(DEFAULT_LOG_LEVEL);
        for (Handler h : logger.getHandlers()) {
            if (!(h instanceof ConsoleHandler)) {
                logger.removeHandler(h);
            }
        }
    }
}
Also used : LogRecord(java.util.logging.LogRecord) Formatter(java.util.logging.Formatter) FileHandler(java.util.logging.FileHandler) RcvrExceptionHandler(edu.cmu.cs.hcii.cogtool.ui.RcvrExceptionHandler) ConsoleHandler(java.util.logging.ConsoleHandler) Handler(java.util.logging.Handler) IOException(java.io.IOException) ConsoleHandler(java.util.logging.ConsoleHandler) FileHandler(java.util.logging.FileHandler)

Example 64 with FileHandler

use of java.util.logging.FileHandler 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 65 with FileHandler

use of java.util.logging.FileHandler 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)

Aggregations

FileHandler (java.util.logging.FileHandler)139 SimpleFormatter (java.util.logging.SimpleFormatter)59 IOException (java.io.IOException)49 File (java.io.File)48 Logger (java.util.logging.Logger)36 Handler (java.util.logging.Handler)34 ConsoleHandler (java.util.logging.ConsoleHandler)15 Properties (java.util.Properties)14 BalancerRunner (org.mobicents.tools.sip.balancer.BalancerRunner)13 Formatter (java.util.logging.Formatter)12 Config (edu.neu.ccs.pyramid.configuration.Config)11 Date (java.util.Date)11 LogRecord (java.util.logging.LogRecord)10 InvocationTargetException (java.lang.reflect.InvocationTargetException)4 Level (java.util.logging.Level)4 Pair (edu.neu.ccs.pyramid.util.Pair)3 FileInputStream (java.io.FileInputStream)3 FileNotFoundException (java.io.FileNotFoundException)3 LogFormat (de.Keyle.MyPet.api.util.LogFormat)2 CTFT (edu.neu.ccs.pyramid.calibration.CTFT)2