use of java.util.logging.SimpleFormatter 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.SimpleFormatter 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.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;
}
IndexCreator indexCreator = new IndexCreator(workDir);
boolean worldMaps = rName.toLowerCase().contains("world");
if (srtmDir != null && (rdata == null || rdata.indexSRTM) && !worldMaps) {
indexCreator.setSRTMData(srtmDir);
}
indexCreator.setDialects(osmDb, osmDb);
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;
}
indexCreator.setIndexAddress(indAddr);
indexCreator.setIndexPOI(indPoi);
indexCreator.setIndexTransport(indTransport);
indexCreator.setIndexMap(indMap);
indexCreator.setIndexRouting(indRouting);
indexCreator.setLastModifiedDate(file.lastModified());
indexCreator.setRegionName(rName);
if (rdata != null && rdata.cityAdminLevel != null) {
indexCreator.setCityAdminLevel(rdata.cityAdminLevel);
}
if (zoomWaySmoothness != null) {
indexCreator.setZoomWaySmoothness(zoomWaySmoothness);
}
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 jgnash by ccavanaugh.
the class ImportQifAction method importQif.
private static void importQif() {
final ResourceBundle rb = ResourceUtils.getBundle();
final Preferences pref = Preferences.userNodeForPackage(ImportQifAction.class);
final Logger logger = Logger.getLogger("qifimport");
if (debug) {
try {
Handler fh = new FileHandler("%h/jgnash%g.log");
fh.setFormatter(new SimpleFormatter());
logger.addHandler(fh);
logger.setLevel(Level.FINEST);
} catch (IOException ioe) {
logger.log(Level.SEVERE, "Could not install file handler", ioe);
}
}
final Engine engine = EngineFactory.getEngine(EngineFactory.DEFAULT);
Objects.requireNonNull(engine);
if (engine.getRootAccount() == null) {
StaticUIMethods.displayError(rb.getString("Message.Error.CreateBasicAccounts"));
return;
}
final JFileChooser chooser = new JFileChooser(pref.get(QIFDIR, null));
chooser.setMultiSelectionEnabled(false);
chooser.addChoosableFileFilter(new FileNameExtensionFilter("Qif Files (*.qif)", "qif"));
if (chooser.showOpenDialog(null) == JFileChooser.APPROVE_OPTION) {
pref.put(QIFDIR, chooser.getCurrentDirectory().getAbsolutePath());
boolean fullFile = QifUtils.isFullFile(chooser.getSelectedFile());
if (fullFile) {
// prompt for date format
final DateFormat dateFormat = getQIFDateFormat();
class ImportFile extends SwingWorker<Void, Void> {
@Override
protected Void doInBackground() throws Exception {
UIApplication.getFrame().displayWaitMessage(rb.getString("Message.ImportWait"));
QifImport imp = new QifImport();
try {
imp.doFullParse(chooser.getSelectedFile(), dateFormat);
} catch (NoAccountException e) {
logger.log(Level.SEVERE, "Mistook partial qif file as a full qif file", e);
}
imp.dumpStats();
imp.doFullImport();
if (imp.getDuplicateCount() > 0) {
String message = imp.getDuplicateCount() + " duplicate transactions were found";
logger.info(message);
}
return null;
}
@Override
protected void done() {
UIApplication.getFrame().stopWaitMessage();
}
}
new ImportFile().execute();
} else {
final QifImport imp = new QifImport();
if (!imp.doPartialParse(chooser.getSelectedFile())) {
StaticUIMethods.displayError(rb.getString("Message.Error.ParseTransactions"));
return;
}
imp.dumpStats();
if (imp.getParser().accountList.isEmpty()) {
StaticUIMethods.displayError(rb.getString("Message.Error.ParseTransactions"));
return;
}
PartialDialog dlg = new PartialDialog(imp.getParser());
DialogUtils.addBoundsListener(dlg);
dlg.setVisible(true);
if (dlg.isWizardValid()) {
imp.doPartialImport(dlg.getAccount());
if (imp.getDuplicateCount() > 0) {
if (YesNoDialog.showYesNoDialog(UIApplication.getFrame(), new MultiLineLabel(TextResource.getString("DupeTransImport.txt")), rb.getString("Title.DuplicateTransactionsFound"), YesNoDialog.WARNING_MESSAGE)) {
Transaction[] t = imp.getDuplicates();
for (Transaction element : t) {
engine.addTransaction(element);
}
}
}
}
}
}
}
use of java.util.logging.SimpleFormatter in project sis by apache.
the class IndexedResourceBundleTest method testGetLogRecord.
/**
* Tests the {@link IndexedResourceBundle#getLogRecord(Level, short, Object)} method.
*/
@Test
@DependsOnMethod("testGetResources")
public void testGetLogRecord() {
testing = Errors.getResources(Locale.ENGLISH);
final LogRecord record = testing.getLogRecord(Level.FINE, Errors.Keys.NullArgument_1, "CRS");
assertEquals("NullArgument_1", record.getMessage());
final SimpleFormatter formatter = new SimpleFormatter();
final String message = formatter.format(record);
assertTrue(message.contains("Argument ‘CRS’ shall not be null."));
testing = null;
}
Aggregations