Search in sources :

Example 61 with Handler

use of java.util.logging.Handler in project jgnash by ccavanaugh.

the class ConsoleDialog method init.

/* Only need to initialize one time.  After that the output
     * streams are static and will only pipe output to the window
     * if it exists.
     */
private static void init() {
    if (!init) {
        init = true;
        try {
            final PrintStream oldOut = System.out;
            PrintStream outStream = new PrintStream(new ConsoleStream(oldOut), false, Charset.defaultCharset().name());
            System.setOut(outStream);
        } catch (UnsupportedEncodingException ex) {
            Logger.getLogger(ConsoleDialog.class.getName()).log(Level.SEVERE, null, ex);
        }
        try {
            final PrintStream oldErr = System.err;
            PrintStream errStream = new PrintStream(new ConsoleStream(oldErr), false, Charset.defaultCharset().name());
            System.setErr(errStream);
        } catch (UnsupportedEncodingException ex) {
            Logger.getLogger(ConsoleDialog.class.getName()).log(Level.SEVERE, null, ex);
        }
        // capture the engine log
        Engine.getLogger().addHandler(new Handler() {

            @Override
            public void close() throws SecurityException {
            }

            @Override
            public void flush() {
            }

            @Override
            public void publish(final LogRecord record) {
                // update on the event thread to prevent display corruption
                EventQueue.invokeLater(() -> {
                    synchronized (consoleLock) {
                        if (console != null) {
                            console.append(record.getMessage() + "\n");
                        }
                    }
                });
            }
        });
    }
}
Also used : PrintStream(java.io.PrintStream) LogRecord(java.util.logging.LogRecord) UnsupportedEncodingException(java.io.UnsupportedEncodingException) Handler(java.util.logging.Handler)

Example 62 with Handler

use of java.util.logging.Handler in project jgnash by ccavanaugh.

the class Main method configureLogging.

private static void configureLogging() {
    final Handler[] handlers = Logger.getLogger("").getHandlers();
    for (Handler handler : handlers) {
        handler.setLevel(Level.ALL);
    }
    Engine.getLogger().setLevel(Level.ALL);
    MainFrame.logger.setLevel(Level.ALL);
    OpenAction.logger.setLevel(Level.ALL);
    YahooParser.logger.setLevel(Level.ALL);
}
Also used : Handler(java.util.logging.Handler)

Example 63 with Handler

use of java.util.logging.Handler in project jgnash by ccavanaugh.

the class jGnashFx method configureLogging.

private static void configureLogging() {
    final Handler[] handlers = Logger.getLogger("").getHandlers();
    for (final Handler handler : handlers) {
        handler.setLevel(Level.ALL);
    }
    Engine.getLogger().setLevel(Level.ALL);
    YahooParser.logger.setLevel(Level.ALL);
}
Also used : Handler(java.util.logging.Handler)

Example 64 with Handler

use of java.util.logging.Handler 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 65 with Handler

use of java.util.logging.Handler in project grpc-java by grpc.

the class ContextTest method detachingNonCurrentLogsSevereMessage.

@Test
public void detachingNonCurrentLogsSevereMessage() {
    final AtomicReference<LogRecord> logRef = new AtomicReference<LogRecord>();
    Handler handler = new Handler() {

        @Override
        public void publish(LogRecord record) {
            logRef.set(record);
        }

        @Override
        public void flush() {
        }

        @Override
        public void close() throws SecurityException {
        }
    };
    Logger logger = Logger.getLogger(Context.storage().getClass().getName());
    try {
        logger.addHandler(handler);
        Context initial = Context.current();
        Context base = initial.withValue(PET, "dog");
        // Base is not attached
        base.detach(initial);
        assertSame(initial, Context.current());
        assertNotNull(logRef.get());
        assertEquals(Level.SEVERE, logRef.get().getLevel());
    } finally {
        logger.removeHandler(handler);
    }
}
Also used : LogRecord(java.util.logging.LogRecord) Handler(java.util.logging.Handler) AtomicReference(java.util.concurrent.atomic.AtomicReference) Logger(java.util.logging.Logger) Test(org.junit.Test)

Aggregations

Handler (java.util.logging.Handler)135 Logger (java.util.logging.Logger)52 ConsoleHandler (java.util.logging.ConsoleHandler)30 LogRecord (java.util.logging.LogRecord)24 Test (org.junit.Test)22 FileHandler (java.util.logging.FileHandler)17 File (java.io.File)14 IOException (java.io.IOException)13 Level (java.util.logging.Level)11 SimpleFormatter (java.util.logging.SimpleFormatter)8 Formatter (java.util.logging.Formatter)7 LogManager (java.util.logging.LogManager)6 PrintStream (java.io.PrintStream)5 ArrayList (java.util.ArrayList)5 SLF4JBridgeHandler (org.slf4j.bridge.SLF4JBridgeHandler)4 ByteArrayOutputStream (java.io.ByteArrayOutputStream)3 FileInputStream (java.io.FileInputStream)3 InputStream (java.io.InputStream)3 StringTokenizer (java.util.StringTokenizer)3 StdOutConsoleHandler (alma.acs.logging.StdOutConsoleHandler)2