use of java.util.logging.FileHandler in project ignite by apache.
the class JavaLogger method fileName.
/**
* {@inheritDoc}
*/
@Nullable
@Override
public String fileName() {
JavaLoggerFileHandler gridFileHnd = findHandler(impl, JavaLoggerFileHandler.class);
if (gridFileHnd != null)
return gridFileHnd.fileName();
FileHandler fileHnd = findHandler(impl, FileHandler.class);
return fileName(fileHnd);
}
use of java.util.logging.FileHandler in project Payara by payara.
the class ACCLogger method createHandler.
/**
* Creates a logging handler to send logging to the specified file, using
* the indicated level.
* @param filePath path to the log file to which to log
* @param level level at which to log
* @return logging Handler if filePath is specified and valid; null otherwise
*/
private static Handler createHandler(final LogService logService, final Level level) throws IOException {
Handler handler = null;
final String filePath = (logService == null) ? null : logService.getFile();
if (filePath == null || filePath.equals("")) {
return null;
}
handler = new FileHandler(filePath, true);
handler.setFormatter(new SimpleFormatter());
handler.setLevel(level);
File lockFile = new File(filePath + ".lck");
lockFile.deleteOnExit();
return handler;
}
use of java.util.logging.FileHandler in project Payara by payara.
the class LoggerFactoryJDK14 method configureFileHandler.
/**
* This method throws SecurityException if a security manager exists and if
* the caller does not have <tt>LoggingPermission("control"))</tt> or the
* calling code is not placed in the doPrivileged() block.
*/
protected void configureFileHandler(LoggerJDK14 logger) {
String name = logger.getName();
// NOI18N
String baseName = name + ".FileHandler";
LogManager logManager = LogManager.getLogManager();
// NOI18N
String pattern = logManager.getProperty(baseName + ".pattern");
if (pattern != null) {
// If pattern != null, create and attach a FileHandler to logger.
// Look various properties . If not found, fall back to
// defaults
int defaultLimit = 0;
// NOI18N
String limit = logManager.getProperty(baseName + ".limit");
if (limit != null) {
try {
defaultLimit = Integer.parseInt(limit);
if (defaultLimit < 0)
defaultLimit = 0;
} catch (NumberFormatException e) {
}
}
int defaultCount = 1;
// NOI18N
String count = logManager.getProperty(baseName + ".count");
if (count != null) {
try {
defaultCount = Integer.parseInt(count);
if (defaultCount < 1)
defaultCount = 1;
} catch (NumberFormatException e) {
}
}
boolean defaultAppend = false;
// NOI18N
String append = logManager.getProperty(baseName + ".append");
if (append != null) {
defaultAppend = Boolean.valueOf(append).booleanValue();
}
FileHandler fileHandler = null;
try {
fileHandler = new FileHandler(pattern, defaultLimit, defaultCount, defaultAppend);
} catch (Exception e) {
MessageFormat messageFormat = new MessageFormat(getMessages().getString(// NOI18N
"errorlogger.filehandler.initialize.exception"));
getErrorLogger().log(Logger.WARNING, messageFormat.format(new String[] { name }), e);
}
if (fileHandler != null) {
// Initialize various attributes for the new fileHandler
// --Level
// NOI18N
String level = logManager.getProperty(baseName + ".level");
if (level != null) {
try {
fileHandler.setLevel(Level.parse(level));
} catch (IllegalArgumentException e) {
}
}
// --Formatter
Formatter defaultFormatter = null;
// Initialize various attributes for the new fileHandler
// NOI18N
String formatter = logManager.getProperty(baseName + ".formatter");
if (formatter != null) {
try {
Class clz = ClassLoader.getSystemClassLoader().loadClass(formatter);
defaultFormatter = (Formatter) clz.newInstance();
} catch (Exception e) {
// We got one of a variety of exceptions in creating the
// class or creating an instance.
// Drop through.
MessageFormat messageFormat = new MessageFormat(getMessages().getString("errorlogger.formatter.initialize.exception"));
getErrorLogger().log(Logger.WARNING, messageFormat.format(new String[] { name }), e);
}
}
if (defaultFormatter == null) {
defaultFormatter = new SimpleFormatter();
}
try {
fileHandler.setFormatter(defaultFormatter);
} catch (IllegalArgumentException e) {
}
logger.addHandler(fileHandler);
}
// if(fileHandler != null)
}
// if(pattern != null)
}
use of java.util.logging.FileHandler 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.FileHandler in project buck by facebook.
the class DiffRuleKeysScriptIntegrationTest method enableVerboseRuleKeys.
@Before
public void enableVerboseRuleKeys() throws Exception {
lastPositionInLog = 0;
ruleKeyBuilderLogger = Logger.get(RuleKeyBuilder.class);
previousRuleKeyBuilderLevel = ruleKeyBuilderLogger.getLevel();
ruleKeyBuilderLogger.setLevel(Level.FINER);
Path fullLogFilePath = tmp.getRoot().resolve(getLogFilePath());
Files.createDirectories(fullLogFilePath.getParent());
FileHandler handler = new FileHandler(fullLogFilePath.toString());
handler.setFormatter(new LogFormatter());
ruleKeyBuilderLogger.addHandler(handler);
}
Aggregations