Search in sources :

Example 76 with FileHandler

use of java.util.logging.FileHandler in project jdk8u_jdk by JetBrains.

the class CheckZombieLockTest method testFileHandlerCreate.

private static void testFileHandlerCreate(File writableDir, boolean first) throws IOException {
    List<File> before = listLocks(writableDir, true);
    System.out.println("before: " + before.size() + " locks found");
    try {
        if (first && !before.isEmpty()) {
            throw new RuntimeException("Expected no lock file! Found: " + before);
        } else if (!first && before.size() != 1) {
            throw new RuntimeException("Expected a single lock file! Found: " + before);
        }
    } finally {
        before.stream().forEach(CheckZombieLockTest::delete);
    }
    FileHandler handler = createFileHandler(writableDir);
    System.out.println("handler created: " + handler);
    List<File> after = listLocks(writableDir, true);
    System.out.println("after creating handler: " + after.size() + " locks found");
    if (after.size() != 1) {
        throw new RuntimeException("Unexpected number of lock files found for " + handler + ": " + after);
    }
}
Also used : File(java.io.File) FileHandler(java.util.logging.FileHandler)

Example 77 with FileHandler

use of java.util.logging.FileHandler in project jdk8u_jdk by JetBrains.

the class FileHandlerPath method test.

public static void test(String name, Properties props) throws Exception {
    System.out.println("Testing: " + name);
    String file = props.getProperty("test.file.name");
    // create the lock files first - in order to take the path that
    // used to trigger the NPE
    Files.createFile(Paths.get(file + ".lck"));
    Files.createFile(Paths.get(file + ".1.lck"));
    final FileHandler f1 = new FileHandler();
    final FileHandler f2 = new FileHandler();
    f1.close();
    f2.close();
    System.out.println("Success for " + name);
}
Also used : FileHandler(java.util.logging.FileHandler)

Example 78 with FileHandler

use of java.util.logging.FileHandler in project jgnash by ccavanaugh.

the class OfxV2Parser method enableDetailedLogFile.

static void enableDetailedLogFile() {
    try {
        final Handler fh = new FileHandler("%h/jgnash-ofx.log", false);
        fh.setFormatter(new SimpleFormatter());
        logger.addHandler(fh);
        logger.setLevel(Level.ALL);
    } catch (final IOException ioe) {
        logger.severe(ResourceUtils.getString("Message.Error.LogFileHandler"));
    }
}
Also used : SimpleFormatter(java.util.logging.SimpleFormatter) FileHandler(java.util.logging.FileHandler) Handler(java.util.logging.Handler) IOException(java.io.IOException) FileHandler(java.util.logging.FileHandler)

Example 79 with FileHandler

use of java.util.logging.FileHandler in project pyramid by cheng-li.

the class App3 method main.

public static void main(String[] args) throws Exception {
    if (args.length != 1) {
        throw new IllegalArgumentException("Please specify a properties file.");
    }
    Config config = new Config(args[0]);
    Logger logger = Logger.getAnonymousLogger();
    String logFile = config.getString("output.log");
    FileHandler fileHandler = null;
    if (!logFile.isEmpty()) {
        new File(logFile).getParentFile().mkdirs();
        //todo should append?
        fileHandler = new FileHandler(logFile, true);
        java.util.logging.Formatter formatter = new SimpleFormatter();
        fileHandler.setFormatter(formatter);
        logger.addHandler(fileHandler);
        logger.setUseParentHandlers(false);
    }
    logger.info(config.toString());
    if (fileHandler != null) {
        fileHandler.close();
    }
    File output = new File(config.getString("output.folder"));
    output.mkdirs();
    Config app1Config = createApp1Config(config);
    Config app2Config = createApp2Config(config);
    App1.main(app1Config);
    App2.main(app2Config);
}
Also used : Config(edu.neu.ccs.pyramid.configuration.Config) SimpleFormatter(java.util.logging.SimpleFormatter) Logger(java.util.logging.Logger) File(java.io.File) FileHandler(java.util.logging.FileHandler)

Example 80 with FileHandler

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

the class LoggerUtil method initLogger.

public static String initLogger(String logpath, Level filelevel, Level consolelevel) throws IOException {
    if (logpath != null) {
        File jlp = new File(logpath);
        if (!jlp.exists() && !jlp.mkdirs()) {
            throw new RuntimeException("could not make logpath: " + jlp.getAbsolutePath());
        }
        if (!jlp.canWrite() && !Level.OFF.equals(filelevel)) {
            throw new IOException("logpath not writeable " + jlp.getAbsolutePath());
        }
    }
    Logger.getGlobal().setLevel(Level.OFF);
    getBaseLogger().setLevel(Level.ALL);
    StringBuilder logfile = new StringBuilder();
    logfile.append(logpath == null ? "%t" : logpath);
    logfile.append(File.separatorChar).append("opengrok%g.%u.log");
    try {
        FileHandler fh = new FileHandler(logfile.toString(), loggerIntProperty("java.util.logging.FileHandler.limit", DEFAULT_FILEHANDLER_LIMIT), loggerIntProperty("java.util.logging.FileHandler.count", DEFAULT_FILEHANDLER_COUNT));
        fh.setLevel(filelevel);
        String formatter = LogManager.getLogManager().getProperty("java.util.logging.FileHandler.formatter");
        try {
            fh.setFormatter((Formatter) Class.forName(formatter).getDeclaredConstructor().newInstance());
        } catch (InstantiationException | IllegalAccessException | ClassNotFoundException | NoSuchMethodException | InvocationTargetException e) {
            fh.setFormatter(new FileLogFormatter());
        }
        getBaseLogger().addHandler(fh);
        loggerFile = logfile.toString();
        ConsoleHandler ch = new ConsoleHandler();
        ch.setLevel(consolelevel);
        ch.setFormatter(new ConsoleFormatter());
        getBaseLogger().addHandler(ch);
    } catch (IOException | SecurityException ex1) {
        LOGGER.log(Level.SEVERE, "Exception logging", ex1);
        throw new IOException("Exception setting up logging " + ex1);
    }
    return logpath;
}
Also used : FileLogFormatter(org.opensolaris.opengrok.logger.formatter.FileLogFormatter) IOException(java.io.IOException) ConsoleHandler(java.util.logging.ConsoleHandler) InvocationTargetException(java.lang.reflect.InvocationTargetException) FileHandler(java.util.logging.FileHandler) ConsoleFormatter(org.opensolaris.opengrok.logger.formatter.ConsoleFormatter) File(java.io.File)

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