use of java.util.logging.SimpleFormatter in project neo4j by neo4j.
the class SuppressOutput method java_util_logging.
private static Suppressible java_util_logging(final ByteArrayOutputStream redirectTo, Level level) {
final Handler replacement = redirectTo == null ? null : new StreamHandler(redirectTo, new SimpleFormatter());
if (replacement != null && level != null) {
replacement.setLevel(level);
}
return new Suppressible() {
@Override
public Voice suppress() {
final Logger logger = LogManager.getLogManager().getLogger("");
final Level level = logger.getLevel();
final Handler[] handlers = logger.getHandlers();
for (Handler handler : handlers) {
logger.removeHandler(handler);
}
if (replacement != null) {
logger.addHandler(replacement);
logger.setLevel(Level.ALL);
}
return new Voice(this, redirectTo) {
@Override
void restore(boolean failure) {
for (Handler handler : handlers) {
logger.addHandler(handler);
}
logger.setLevel(level);
if (replacement != null) {
logger.removeHandler(replacement);
}
}
};
}
};
}
use of java.util.logging.SimpleFormatter in project mysql_perf_analyzer by yahoo.
the class MyPerfContext method configureLogging.
private void configureLogging() {
Logger logger = Logger.getLogger("");
try {
logger.setLevel(Level.parse(getLogLevel()));
} catch (Exception ex) {
logger.setLevel(Level.INFO);
}
try {
for (Handler h : logger.getHandlers()) {
if (h instanceof java.util.logging.ConsoleHandler)
h.setLevel(Level.SEVERE);
}
String logRoot = System.getProperty("logPath", ".");
java.util.logging.FileHandler fileHandler = new java.util.logging.FileHandler(logRoot + File.separatorChar + getLogPath(), this.logFileSize, this.logFileCount);
fileHandler.setLevel(logger.getLevel());
fileHandler.setFormatter(new SimpleFormatter());
logger.addHandler(fileHandler);
} catch (Exception ex) {
ex.printStackTrace();
}
}
use of java.util.logging.SimpleFormatter in project OsmAnd-tools by osmandapp.
the class IndexBatchCreator method generateIndex.
protected void generateIndex(File file, String rName, RegionSpecificData rdata, Set<String> alreadyGeneratedFiles) {
try {
// be independent of previous results
RTree.clearCache();
String regionName = file.getName();
log.warn("-------------------------------------------");
log.warn("----------- Generate " + file.getName() + "\n\n\n");
int i = file.getName().indexOf('.');
if (i > -1) {
regionName = Algorithms.capitalizeFirstLetterAndLowercase(file.getName().substring(0, i));
}
if (Algorithms.isEmpty(rName)) {
rName = regionName;
} else {
rName = Algorithms.capitalizeFirstLetterAndLowercase(rName);
}
DBDialect osmDb = this.osmDbDialect;
if (file.length() / 1024 / 1024 > INMEM_LIMIT && osmDb == DBDialect.SQLITE_IN_MEMORY) {
log.warn("Switching SQLITE in memory dialect to SQLITE");
osmDb = DBDialect.SQLITE;
}
final boolean indAddr = indexAddress && (rdata == null || rdata.indexAddress);
final boolean indPoi = indexPOI && (rdata == null || rdata.indexPOI);
final boolean indTransport = indexTransport && (rdata == null || rdata.indexTransport);
final boolean indMap = indexMap && (rdata == null || rdata.indexMap);
final boolean indRouting = indexRouting && (rdata == null || rdata.indexRouting);
if (!indAddr && !indPoi && !indTransport && !indMap && !indRouting) {
log.warn("! Skip country because nothing to index !");
file.delete();
return;
}
IndexCreatorSettings settings = new IndexCreatorSettings();
settings.indexMap = indMap;
settings.indexAddress = indAddr;
settings.indexPOI = indPoi;
settings.indexTransport = indTransport;
settings.indexRouting = indRouting;
if (zoomWaySmoothness != null) {
settings.zoomWaySmoothness = zoomWaySmoothness;
}
boolean worldMaps = rName.toLowerCase().contains("world");
if (worldMaps) {
if (rName.toLowerCase().contains("basemap")) {
return;
}
if (rName.toLowerCase().contains("seamarks")) {
settings.keepOnlySeaObjects = true;
settings.indexTransport = false;
settings.indexAddress = false;
}
} else {
if (srtmDir != null && (rdata == null || rdata.indexSRTM)) {
settings.srtmDataFolder = srtmDir;
}
}
IndexCreator indexCreator = new IndexCreator(workDir, settings);
indexCreator.setDialects(osmDb, osmDb);
indexCreator.setLastModifiedDate(file.lastModified());
indexCreator.setRegionName(rName);
String mapFileName = regionName + "_" + IndexConstants.BINARY_MAP_VERSION + IndexConstants.BINARY_MAP_INDEX_EXT;
indexCreator.setMapFileName(mapFileName);
try {
alreadyGeneratedFiles.add(file.getName());
Log warningsAboutMapData = null;
File logFileName = new File(workDir, mapFileName + GEN_LOG_EXT);
FileHandler fh = null;
// configure log path
try {
FileOutputStream fout = new FileOutputStream(logFileName);
fout.write((new Date() + "\n").getBytes());
fout.write((MapCreatorVersion.APP_MAP_CREATOR_FULL_NAME + "\n").getBytes());
fout.close();
fh = new FileHandler(logFileName.getAbsolutePath(), 10 * 1000 * 1000, 1, true);
fh.setFormatter(new SimpleFormatter());
fh.setLevel(Level.ALL);
Jdk14Logger jdk14Logger = new Jdk14Logger("tempLogger");
jdk14Logger.getLogger().setLevel(Level.ALL);
jdk14Logger.getLogger().setUseParentHandlers(false);
jdk14Logger.getLogger().addHandler(fh);
warningsAboutMapData = jdk14Logger;
} catch (SecurityException e1) {
e1.printStackTrace();
} catch (IOException e1) {
e1.printStackTrace();
}
if (fh != null) {
LogManager.getLogManager().getLogger("").addHandler(fh);
}
try {
indexCreator.generateIndexes(file, new ConsoleProgressImplementation(1), null, mapZooms, new MapRenderingTypesEncoder(renderingTypesFile, file.getName()), warningsAboutMapData);
} finally {
if (fh != null) {
fh.close();
LogManager.getLogManager().getLogger("").removeHandler(fh);
}
}
File generated = new File(workDir, mapFileName);
File dest = new File(indexDirFiles, generated.getName());
if (!generated.renameTo(dest)) {
FileOutputStream fout = new FileOutputStream(dest);
FileInputStream fin = new FileInputStream(generated);
Algorithms.streamCopy(fin, fout);
fin.close();
fout.close();
}
File copyLog = new File(indexDirFiles, logFileName.getName());
FileOutputStream fout = new FileOutputStream(copyLog);
FileInputStream fin = new FileInputStream(logFileName);
Algorithms.streamCopy(fin, fout);
fin.close();
fout.close();
// logFileName.renameTo(new File(indexDirFiles, logFileName.getName()));
} catch (Exception e) {
// $NON-NLS-1$
log.error("Exception generating indexes for " + file.getName(), e);
}
} catch (OutOfMemoryError e) {
System.gc();
log.error("OutOfMemory", e);
}
System.gc();
}
use of java.util.logging.SimpleFormatter in project OsmAnd-tools by osmandapp.
the class OsmExtractionUI method configLogFile.
public static void configLogFile() {
new File(LOG_PATH).getParentFile().mkdirs();
try {
FileHandler fh = new FileHandler(LOG_PATH, 5000000, 1, true);
fh.setFormatter(new SimpleFormatter());
LogManager.getLogManager().getLogger("").addHandler(fh);
} catch (SecurityException e1) {
e1.printStackTrace();
} catch (IOException e1) {
e1.printStackTrace();
}
}
use of java.util.logging.SimpleFormatter in project BlocklyArduinoIDEPlugin by technologiescollege.
the class AbstractLauncher method setupLogFile.
/**
* 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);
}
Aggregations