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);
}
}
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);
}
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"));
}
}
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);
}
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;
}
Aggregations