Search in sources :

Example 16 with FileHandler

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);
}
Also used : FileHandler(java.util.logging.FileHandler) Nullable(org.jetbrains.annotations.Nullable)

Example 17 with FileHandler

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;
}
Also used : SimpleFormatter(java.util.logging.SimpleFormatter) FileHandler(java.util.logging.FileHandler) Handler(java.util.logging.Handler) File(java.io.File) FileHandler(java.util.logging.FileHandler)

Example 18 with FileHandler

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)
}
Also used : MessageFormat(java.text.MessageFormat) SimpleFormatter(java.util.logging.SimpleFormatter) Formatter(java.util.logging.Formatter) SimpleFormatter(java.util.logging.SimpleFormatter) LogManager(java.util.logging.LogManager) IOException(java.io.IOException) FileHandler(java.util.logging.FileHandler)

Example 19 with FileHandler

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);
                        }
                    }
                }
            }
        }
    }
}
Also used : SimpleFormatter(java.util.logging.SimpleFormatter) FileHandler(java.util.logging.FileHandler) Handler(java.util.logging.Handler) PartialDialog(jgnash.ui.wizards.imports.qif.PartialDialog) IOException(java.io.IOException) Logger(java.util.logging.Logger) FileNameExtensionFilter(javax.swing.filechooser.FileNameExtensionFilter) FileHandler(java.util.logging.FileHandler) NoAccountException(jgnash.convert.imports.qif.NoAccountException) JFileChooser(javax.swing.JFileChooser) Transaction(jgnash.engine.Transaction) DateFormat(jgnash.convert.imports.DateFormat) QifImport(jgnash.convert.imports.qif.QifImport) SwingWorker(javax.swing.SwingWorker) ResourceBundle(java.util.ResourceBundle) Preferences(java.util.prefs.Preferences) Engine(jgnash.engine.Engine) MultiLineLabel(jgnash.ui.components.MultiLineLabel)

Example 20 with FileHandler

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);
}
Also used : Path(java.nio.file.Path) LogFormatter(com.facebook.buck.log.LogFormatter) FileHandler(java.util.logging.FileHandler) Before(org.junit.Before)

Aggregations

FileHandler (java.util.logging.FileHandler)49 IOException (java.io.IOException)22 File (java.io.File)15 SimpleFormatter (java.util.logging.SimpleFormatter)11 Handler (java.util.logging.Handler)10 ConsoleHandler (java.util.logging.ConsoleHandler)5 LogRecord (java.util.logging.LogRecord)5 Formatter (java.util.logging.Formatter)4 Logger (java.util.logging.Logger)3 Config (edu.neu.ccs.pyramid.configuration.Config)2 Date (java.util.Date)2 Setup (org.openjdk.jmh.annotations.Setup)2 LogFormatter (com.facebook.buck.log.LogFormatter)1 HumanReadableException (com.facebook.buck.util.HumanReadableException)1 NaviLogFormatter (com.google.security.zynamics.binnavi.Log.NaviLogFormatter)1 FileReadException (com.google.security.zynamics.binnavi.config.FileReadException)1 LogFormat (de.Keyle.MyPet.api.util.LogFormat)1 RcvrExceptionHandler (edu.cmu.cs.hcii.cogtool.ui.RcvrExceptionHandler)1 RuntimeIOException (edu.stanford.nlp.io.RuntimeIOException)1 NewlineLogFormatter (edu.stanford.nlp.util.logging.NewlineLogFormatter)1