java.util.logging.FileHandler Java Examples
The following examples show how to use
java.util.logging.FileHandler.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: DefaultDatabaseConfigurator.java From aceql-http with GNU Lesser General Public License v2.1 | 6 votes |
/** * Creates a static {@code Logger} instance. * * @return a static {@code Logger} with properties: * <ul> * <li>Name: {@code "DefaultDatabaseConfigurator"}.</li> * <li>Output file pattern: * {@code user.home/.kawansoft/log/AceQL.log}.</li> * <li>Formatter: {@code SimpleFormatter}.</li> * <li>Limit: 200Mb.</li> * <li>Count (number of files to use): 2.</li> * </ul> */ @Override public Logger getLogger() throws IOException { if (ACEQL_LOGGER != null) { return ACEQL_LOGGER; } File logDir = new File(SystemUtils.USER_HOME + File.separator + ".kawansoft" + File.separator + "log"); logDir.mkdirs(); String pattern = logDir.toString() + File.separator + "AceQL.log"; ACEQL_LOGGER = Logger.getLogger(DefaultDatabaseConfigurator.class.getName()); Handler fh = new FileHandler(pattern, 200 * 1024 * 1024, 2, true); fh.setFormatter(new NoFormatter()); ACEQL_LOGGER.addHandler(fh); return ACEQL_LOGGER; }
Example #2
Source File: CheckZombieLockTest.java From dragonwell8_jdk with GNU General Public License v2.0 | 6 votes |
private static void testFileHandlerClose(File writableDir) throws IOException { File fakeLock = new File(writableDir, "log.log.lck"); if (!createFile(fakeLock, false)) { throw new IOException("Can't create fake lock file: " + fakeLock); } try { List<File> before = listLocks(writableDir, true); System.out.println("before: " + before.size() + " locks found"); 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"); handler.close(); System.out.println("handler closed: " + handler); List<File> afterClose = listLocks(writableDir, true); System.out.println("after closing handler: " + afterClose.size() + " locks found"); afterClose.removeAll(before); if (!afterClose.isEmpty()) { throw new RuntimeException("Zombie lock file detected: " + afterClose); } } finally { if (fakeLock.canRead()) delete(fakeLock); } List<File> finalLocks = listLocks(writableDir, false); System.out.println("After cleanup: " + finalLocks.size() + " locks found"); }
Example #3
Source File: TestClass.java From OCA-Java-SE-7-Programmer-I with MIT License | 6 votes |
public static void main(String[] args) throws IOException { /* Ensure directory has been created */ new File("logs").mkdir(); /* Get the date to be used in the filename */ DateFormat df = new SimpleDateFormat("yyyyMMddhhmmss"); Date now = new Date(); String date = df.format(now); /* Set up the filename in the logs directory */ String logFileName = "logs/testlog-" + date + ".txt"; /* Set up logger */ FileHandler myFileHandler = new FileHandler(logFileName); myFileHandler.setFormatter(new SimpleFormatter()); Logger ocajLogger = Logger.getLogger("OCAJ Logger"); ocajLogger.setLevel(Level.ALL); ocajLogger.addHandler(myFileHandler); /* Log Message */ ocajLogger.info("\nThis is a logged information message."); /* Close the file */ myFileHandler.close(); }
Example #4
Source File: FileHandlerMaxLocksTest.java From dragonwell8_jdk with GNU General Public License v2.0 | 6 votes |
public static void main(String[] args) throws Exception { String maxLocksSet = System.getProperty(MX_LCK_SYS_PROPERTY); File loggerDir = createLoggerDir(); List<FileHandler> fileHandlers = new ArrayList<>(); try { // 200 raises the default limit of 100, we try 102 times for (int i = 0; i < 102; i++) { fileHandlers.add(new FileHandler(loggerDir.getPath() + File.separator + "test_%u.log")); } } catch (IOException ie) { if (maxLocksSet.equals("200ab") && ie.getMessage().contains("get lock for")) { // Ignore: Expected exception while passing bad value- 200ab } else { throw new RuntimeException("Test Failed: " + ie.getMessage()); } } finally { for (FileHandler fh : fileHandlers) { fh.close(); } FileUtils.deleteFileTreeWithRetry(Paths.get(loggerDir.getPath())); } }
Example #5
Source File: CommandHandler.java From ignite with Apache License 2.0 | 6 votes |
/** * @return prepared JULs logger. */ private Logger setupJavaLogger() { Logger result = initLogger(CommandHandler.class.getName() + "Log"); // Adding logging to file. try { String absPathPattern = new File(JavaLoggerFileHandler.logDirectory(U.defaultWorkDirectory()), "control-utility-%g.log").getAbsolutePath(); FileHandler fileHandler = new FileHandler(absPathPattern, 5 * 1024 * 1024, 5); fileHandler.setFormatter(new JavaLoggerFormatter()); result.addHandler(fileHandler); } catch (Exception e) { System.out.println("Failed to configure logging to file"); } // Adding logging to console. result.addHandler(setupStreamHandler()); return result; }
Example #6
Source File: Main.java From RegexGenerator with GNU General Public License v3.0 | 6 votes |
/** * @param args the command line arguments */ public static void main(String[] args) throws TreeEvaluationException, IOException, Exception { if (args.length < 1) { printUsage(); System.exit(0); } Configuration configuration = Configurator.configure(args[0]); //Configuration configuration = new Configuration(); Logger.getLogger("").addHandler(new FileHandler(new File(configuration.getOutputFolder(), "log.xml").getCanonicalPath())); Results results = new Results(configuration); results.setMachineHardwareSpecifications(Utils.cpuInfo()); ExecutionStrategy strategy = configuration.getStrategy(); long startTime = System.currentTimeMillis(); strategy.execute(configuration, new CoolTextualExecutionListener(args[0], configuration, results)); if (configuration.getPostProcessor() != null) { startTime = System.currentTimeMillis() - startTime; configuration.getPostProcessor().elaborate(configuration, results, startTime); } }
Example #7
Source File: CheckZombieLockTest.java From TencentKona-8 with GNU General Public License v2.0 | 6 votes |
private static void testFileHandlerClose(File writableDir) throws IOException { File fakeLock = new File(writableDir, "log.log.lck"); if (!createFile(fakeLock, false)) { throw new IOException("Can't create fake lock file: " + fakeLock); } try { List<File> before = listLocks(writableDir, true); System.out.println("before: " + before.size() + " locks found"); 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"); handler.close(); System.out.println("handler closed: " + handler); List<File> afterClose = listLocks(writableDir, true); System.out.println("after closing handler: " + afterClose.size() + " locks found"); afterClose.removeAll(before); if (!afterClose.isEmpty()) { throw new RuntimeException("Zombie lock file detected: " + afterClose); } } finally { if (fakeLock.canRead()) delete(fakeLock); } List<File> finalLocks = listLocks(writableDir, false); System.out.println("After cleanup: " + finalLocks.size() + " locks found"); }
Example #8
Source File: CheckZombieLockTest.java From TencentKona-8 with GNU General Public License v2.0 | 6 votes |
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); } }
Example #9
Source File: FileHandlerMaxLocksTest.java From jdk8u_jdk with GNU General Public License v2.0 | 6 votes |
public static void main(String[] args) throws Exception { String maxLocksSet = System.getProperty(MX_LCK_SYS_PROPERTY); File loggerDir = createLoggerDir(); List<FileHandler> fileHandlers = new ArrayList<>(); try { // 200 raises the default limit of 100, we try 102 times for (int i = 0; i < 102; i++) { fileHandlers.add(new FileHandler(loggerDir.getPath() + File.separator + "test_%u.log")); } } catch (IOException ie) { if (maxLocksSet.equals("200ab") && ie.getMessage().contains("get lock for")) { // Ignore: Expected exception while passing bad value- 200ab } else { throw new RuntimeException("Test Failed: " + ie.getMessage()); } } finally { for (FileHandler fh : fileHandlers) { fh.close(); } FileUtils.deleteFileTreeWithRetry(Paths.get(loggerDir.getPath())); } }
Example #10
Source File: AuditFileWriter.java From Analyze with Eclipse Public License 1.0 | 6 votes |
/** * Create and configure a FileHandler to use for writing to the audit log. * @param config configuration properties. * @throws RuntimeException if the log file cannot be opened for writing. */ private FileHandler createFileHandler(final FileConfiguration config) { try { // Specify append mode to avoid previous audit logs being overwritten. return new FileHandler(config.getFileName(), config.getSizeLimit(), config.getFileCount(), true); } catch (SecurityException | IOException ex) { throw new RuntimeException("Failed to open log file: " + config.getFileName(), ex); } }
Example #11
Source File: CheckZombieLockTest.java From jdk8u60 with GNU General Public License v2.0 | 6 votes |
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); } }
Example #12
Source File: FileHandlerLongLimit.java From openjdk-jdk9 with GNU General Public License v2.0 | 6 votes |
public static void test(String name, Properties props, long limit) throws Exception { System.out.println("Testing: " + name); Class<? extends Exception> expectedException = null; if (userDirWritable || expectedException != null) { // These calls will create files in user.dir. // The file name contain a random UUID (PREFIX) which identifies them // and allow us to remove them cleanly at the end (see finally block // in main()). checkException(expectedException, () -> new FileHandler()); checkException(expectedException, () -> { final FileHandler fh = new FileHandler(); assertEquals(limit, getLimit(fh), "limit"); return fh; }); checkException(expectedException, () -> testFileHandlerLimit( () -> new FileHandler(), limit)); checkException(expectedException, () -> testFileHandlerLimit( () -> new FileHandler(PREFIX, Long.MAX_VALUE, 1, true), Long.MAX_VALUE)); } }
Example #13
Source File: CheckZombieLockTest.java From openjdk-jdk9 with GNU General Public License v2.0 | 6 votes |
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); } }
Example #14
Source File: CheckZombieLockTest.java From jdk8u-dev-jdk with GNU General Public License v2.0 | 6 votes |
private static void testFileHandlerClose(File writableDir) throws IOException { File fakeLock = new File(writableDir, "log.log.lck"); if (!createFile(fakeLock, false)) { throw new IOException("Can't create fake lock file: " + fakeLock); } try { List<File> before = listLocks(writableDir, true); System.out.println("before: " + before.size() + " locks found"); 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"); handler.close(); System.out.println("handler closed: " + handler); List<File> afterClose = listLocks(writableDir, true); System.out.println("after closing handler: " + afterClose.size() + " locks found"); afterClose.removeAll(before); if (!afterClose.isEmpty()) { throw new RuntimeException("Zombie lock file detected: " + afterClose); } } finally { if (fakeLock.canRead()) delete(fakeLock); } List<File> finalLocks = listLocks(writableDir, false); System.out.println("After cleanup: " + finalLocks.size() + " locks found"); }
Example #15
Source File: CheckZombieLockTest.java From openjdk-jdk8u with GNU General Public License v2.0 | 6 votes |
private static void testFileHandlerClose(File writableDir) throws IOException { File fakeLock = new File(writableDir, "log.log.lck"); if (!createFile(fakeLock, false)) { throw new IOException("Can't create fake lock file: " + fakeLock); } try { List<File> before = listLocks(writableDir, true); System.out.println("before: " + before.size() + " locks found"); 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"); handler.close(); System.out.println("handler closed: " + handler); List<File> afterClose = listLocks(writableDir, true); System.out.println("after closing handler: " + afterClose.size() + " locks found"); afterClose.removeAll(before); if (!afterClose.isEmpty()) { throw new RuntimeException("Zombie lock file detected: " + afterClose); } } finally { if (fakeLock.canRead()) delete(fakeLock); } List<File> finalLocks = listLocks(writableDir, false); System.out.println("After cleanup: " + finalLocks.size() + " locks found"); }
Example #16
Source File: CheckZombieLockTest.java From jdk8u_jdk with GNU General Public License v2.0 | 6 votes |
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); } }
Example #17
Source File: PMController.java From uima-uimaj with Apache License 2.0 | 6 votes |
/** * Enables/disables PM log file. By default, the log file is disabled. * * @param enable * if <code>true</code>, the log file is enabled, otherwise it is disabled. */ public static void setLogFileEnabled(boolean enable) { if (enable) { Handler[] handlers = getLogger().getHandlers(); if (handlers == null || handlers.length == 0) { // add default file handler try { FileHandler fileHandler = new FileHandler(LOG_FILE, false); fileHandler.setLevel(Level.ALL); fileHandler.setFormatter(new PMLogFormatter()); getLogger().addHandler(fileHandler); } catch (Throwable err) { System.err.println("Error initializing log file " + PMController.class.getName() + ": " + err.toString()); } } } __logFileEnabled = enable; }
Example #18
Source File: CheckZombieLockTest.java From jdk8u-dev-jdk with GNU General Public License v2.0 | 6 votes |
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); } }
Example #19
Source File: GemFireXDDataExtractorImpl.java From gemfirexd-oss with Apache License 2.0 | 6 votes |
protected void configureLogger() throws SecurityException, IOException { if (logger == null) { logger = Logger.getLogger(LOGGER_NAME); } logger.setUseParentHandlers(false); logFileHandler = new FileHandler(logFilePath); logFileHandler.setFormatter(new SimpleFormatter()); Level logLevel = Level.INFO; try { logLevel = Level.parse(logLevelString); } catch (IllegalArgumentException e) { logInfo("Unrecognized log level :" + logLevelString + " defaulting to :" + logLevel); } logFileHandler.setLevel(logLevel); logger.addHandler(logFileHandler); }
Example #20
Source File: IncrementalActionGraphIntegrationTest.java From buck with Apache License 2.0 | 5 votes |
@Before public void setUp() throws IOException { incrementalActionGraphGeneratorLogger = Logger.get(IncrementalActionGraphGenerator.class); incrementalActionGraphGeneratorLogger.setLevel(Level.FINER); Path fullLogFilePath = tmp.getRoot().resolve(getLogFilePath()); Files.createDirectories(fullLogFilePath.getParent()); FileHandler handler = new FileHandler(fullLogFilePath.toString()); handler.setFormatter(new LogFormatter()); incrementalActionGraphGeneratorLogger.addHandler(handler); workspace = TestDataHelper.createProjectWorkspaceForScenarioWithoutDefaultCell( this, "incremental_action_graph", tmp); workspace.setUp(); }
Example #21
Source File: FileHandlerPath.java From jdk8u-jdk with GNU General Public License v2.0 | 5 votes |
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); }
Example #22
Source File: OgarServer.java From Ogar2-Server with GNU General Public License v3.0 | 5 votes |
private void setupLogging() { log.setUseParentHandlers(false); LogFormatter formatter = new LogFormatter(); ConsoleHandler ch = new ConsoleHandler(); ch.setFormatter(formatter); if (isDebugging()) { log.setLevel(Level.FINEST); ch.setLevel(Level.FINEST); } else { log.setLevel(Level.INFO); ch.setLevel(Level.INFO); } log.addHandler(ch); try { FileHandler fh = new FileHandler("server.log"); fh.setFormatter(formatter); if (isDebugging()) { fh.setLevel(Level.FINEST); } else { ch.setLevel(Level.INFO); } log.addHandler(fh); } catch (IOException ex) { log.log(Level.SEVERE, "Error while adding FileHandler to logger. Logs will not be output to a file.", ex); } }
Example #23
Source File: CheckZombieLockTest.java From jdk8u-jdk with GNU General Public License v2.0 | 5 votes |
private static FileHandler createFileHandler(File writableDir) throws SecurityException, RuntimeException, IOException { // Test 1: make sure we can create FileHandler in writable directory try { FileHandler handler = new FileHandler("%t/" + WRITABLE_DIR + "/log.log"); handler.publish(new LogRecord(Level.INFO, handler.toString())); handler.flush(); return handler; } catch (IOException ex) { throw new RuntimeException("Test failed: should have been able" + " to create FileHandler for " + "%t/" + WRITABLE_DIR + "/log.log in writable directory.", ex); } }
Example #24
Source File: Main.java From fabric-installer with Apache License 2.0 | 5 votes |
public static void setDebugLevel(Level newLvl) { Logger rootLogger = LogManager.getLogManager().getLogger(""); java.util.logging.Handler[] handlers = rootLogger.getHandlers(); rootLogger.setLevel(newLvl); for (java.util.logging.Handler h : handlers) { if (h instanceof FileHandler) h.setLevel(newLvl); } }
Example #25
Source File: DeconvolutionLogger.java From systemsgenetics with GNU General Public License v3.0 | 5 votes |
static public void setup(String outputDir, Boolean noConsole) throws IOException { // get the global logger to configure it LogManager.getLogManager().reset(); log.setLevel(Level.INFO); DateFormat dateFormat = new SimpleDateFormat("yyyyMMdd"); Date date = new Date(); File file = new File(outputDir+"/DeconvolutionLog_"+dateFormat.format(date)+".txt"); File parent = file.getParentFile(); if (!parent.exists() && !parent.mkdirs()) { throw new IllegalStateException("Couldn't create dir: " + parent); } Files.deleteIfExists(file.toPath()); setOutfilePath(new FileHandler(outputDir+"/DeconvolutionLog_"+dateFormat.format(date)+".txt")); CustomRecordFormatter customFormatter = new CustomRecordFormatter(); ConsoleHandler consoleHandler = new ConsoleHandler(); consoleHandler.setFormatter(customFormatter); outfilePath.setFormatter(customFormatter); log.setUseParentHandlers(false); if (!noConsole){ log.addHandler(consoleHandler); } log.addHandler(outfilePath); }
Example #26
Source File: FileAppenderThrowableBenchmark.java From logging-log4j2 with Apache License 2.0 | 5 votes |
@Override void setUp() throws Exception { julFileHandler = new FileHandler("target/testJulLog.log"); logger = java.util.logging.Logger.getLogger(getClass().getName()); logger.setUseParentHandlers(false); logger.addHandler(julFileHandler); logger.setLevel(Level.ALL); }
Example #27
Source File: NotificationResource.java From sample-acmegifts with Eclipse Public License 1.0 | 5 votes |
@PostConstruct public void init() { try { File log = new File(logFile); File parentDir = log.getParentFile(); if (!parentDir.exists()) { parentDir.mkdirs(); } FileHandler fh = new FileHandler(logFile); logger.addHandler(fh); SimpleFormatter formatter = new SimpleFormatter(); fh.setFormatter(formatter); File fbLog = new File(fallbackLogFile); File fbParentDir = fbLog.getParentFile(); if (!fbParentDir.exists()) { fbParentDir.mkdirs(); } FileHandler fbFh = new FileHandler(fallbackLogFile); fbLogger.addHandler(fbFh); SimpleFormatter fbFormatter = new SimpleFormatter(); fbFh.setFormatter(fbFormatter); ConfigurationBuilder cb = new ConfigurationBuilder(); cb.setDebugEnabled(true); cb.setTweetModeExtended(true); cb.setOAuthConsumerKey(consumerKey); cb.setOAuthConsumerSecret(consumeSecret); cb.setOAuthAccessToken(accessToken); cb.setOAuthAccessTokenSecret(acessSecret); TwitterFactory tf = new TwitterFactory(cb.build()); twitter = tf.getInstance(); } catch (Exception e) { throw new WebApplicationException(e, Response.Status.INTERNAL_SERVER_ERROR); } }
Example #28
Source File: LoggingContext.java From twister2 with Apache License 2.0 | 5 votes |
public static boolean fileLoggingRequested() { String handlers = loggingProperties.getProperty("handlers", ""); for (String className : handlers.split(",")) { if (className.equals(FileHandler.class.getCanonicalName()) || className.equals(Twister2FileLogHandler.class.getCanonicalName())) { return true; } } return false; }
Example #29
Source File: AbstractLauncher.java From fxlauncher with Apache License 2.0 | 5 votes |
/** * Make java.util.logger log to a file. Default it will log to $TMPDIR/fxlauncher.log. This can be overriden by using * comman line parameter <code>--logfile=logfile</code> * * @throws IOException */ protected void setupLogFile() throws IOException { String filename = System.getProperty("java.io.tmpdir") + File.separator + "fxlauncher.log"; if (getParameters().getNamed().containsKey("logfile")) filename = getParameters().getNamed().get("logfile"); System.out.println("logging to " + filename); FileHandler handler = new FileHandler(filename); handler.setFormatter(new SimpleFormatter()); log.addHandler(handler); }
Example #30
Source File: ErrorLog.java From VanetSim with GNU General Public License v3.0 | 5 votes |
/** * Sets the parameters for the static class. * * @param level the minimum level for error messages. If the severity of an error is lower than this value, nothing is logged. * @param dir the directory where the error log files are located * @param format the format of the log files (<code>txt</code> or <code>xml</code>) */ public static void setParameters(int level, String dir, String format) { switch (level) { case 2: logger.setLevel(Level.FINER); break; case 3: logger.setLevel(Level.FINE); break; case 4: logger.setLevel(Level.CONFIG); break; case 5: logger.setLevel(Level.INFO); break; case 6: logger.setLevel(Level.WARNING); break; case 7: logger.setLevel(Level.SEVERE); break; default: logger.setLevel(Level.FINEST); } java.util.Date dt = new java.util.Date(); SimpleDateFormat df = new SimpleDateFormat("dd.MM.yyyy_HH.mm.ss"); //$NON-NLS-1$ try { FileHandler handler = new FileHandler(dir + "log_" + df.format(dt) + "." + format, true);//$NON-NLS-1$ //$NON-NLS-2$ logger.addHandler(handler); logger.setUseParentHandlers(false); // don't log to console if (format.equals("txt")) //$NON-NLS-1$ handler.setFormatter(new SimpleFormatter()); else handler.setFormatter(new XMLFormatter()); } catch (Exception e) { ErrorLog.log(Messages.getString("ErrorLog.whileSetting"), 7, ErrorLog.class.getName(), "setParameters", e); //$NON-NLS-1$ //$NON-NLS-2$ System.exit(1); } }