Search in sources :

Example 36 with SimpleFormatter

use of java.util.logging.SimpleFormatter in project android_frameworks_base by DirtyUnicorns.

the class CookiesTest method testCookiesAreNotLogged.

/**
     * Test that we don't log potentially sensitive cookie values.
     * http://b/3095990
     */
public void testCookiesAreNotLogged() throws IOException, URISyntaxException {
    // enqueue an HTTP response with a cookie that will be rejected
    server.enqueue(new MockResponse().addHeader("Set-Cookie: password=secret; Domain=fake.domain"));
    server.play();
    ByteArrayOutputStream out = new ByteArrayOutputStream();
    Logger logger = Logger.getLogger("org.apache.http");
    StreamHandler handler = new StreamHandler(out, new SimpleFormatter());
    logger.addHandler(handler);
    try {
        HttpClient client = new DefaultHttpClient();
        client.execute(new HttpGet(server.getUrl("/").toURI()));
        handler.close();
        String log = out.toString("UTF-8");
        assertTrue(log, log.contains("password"));
        assertTrue(log, log.contains("fake.domain"));
        assertFalse(log, log.contains("secret"));
    } finally {
        logger.removeHandler(handler);
    }
}
Also used : MockResponse(com.google.mockwebserver.MockResponse) StreamHandler(java.util.logging.StreamHandler) SimpleFormatter(java.util.logging.SimpleFormatter) DefaultHttpClient(org.apache.http.impl.client.DefaultHttpClient) HttpClient(org.apache.http.client.HttpClient) HttpGet(org.apache.http.client.methods.HttpGet) ByteArrayOutputStream(java.io.ByteArrayOutputStream) Logger(java.util.logging.Logger) DefaultHttpClient(org.apache.http.impl.client.DefaultHttpClient)

Example 37 with SimpleFormatter

use of java.util.logging.SimpleFormatter in project tomee by apache.

the class FileHandler method configure.

/**
     * Configure from <code>LogManager</code> properties.
     */
private void configure() {
    final Timestamp ts = new Timestamp(System.currentTimeMillis());
    final String tsString = ts.toString().substring(0, 19);
    date = tsString.substring(0, 10);
    //allow classes to override
    final String className = this.getClass().getName();
    final ClassLoader cl = Thread.currentThread().getContextClassLoader();
    // Retrieve configuration of logging file name
    rotatable = Boolean.parseBoolean(getProperty(className + ".rotatable", "true"));
    if (directory == null) {
        directory = getProperty(className + ".directory", "logs");
    }
    if (prefix == null) {
        prefix = getProperty(className + ".prefix", "juli.");
    }
    if (suffix == null) {
        suffix = getProperty(className + ".suffix", ".log");
    }
    final String sBufferSize = getProperty(className + ".bufferSize", String.valueOf(bufferSize));
    try {
        bufferSize = Integer.parseInt(sBufferSize);
    } catch (final NumberFormatException ignore) {
    //no op
    }
    // Get encoding for the logging file
    final String encoding = getProperty(className + ".encoding", null);
    if (encoding != null && encoding.length() > 0) {
        try {
            setEncoding(encoding);
        } catch (final UnsupportedEncodingException ex) {
        // Ignore
        }
    }
    // Get logging level for the handler
    setLevel(Level.parse(getProperty(className + ".level", String.valueOf(Level.ALL))));
    // Get filter configuration
    final String filterName = getProperty(className + ".filter", null);
    if (filterName != null) {
        try {
            setFilter((Filter) cl.loadClass(filterName).newInstance());
        } catch (final Exception e) {
        // Ignore
        }
    }
    // Set formatter
    final String formatterName = getProperty(className + ".formatter", null);
    if (formatterName != null) {
        try {
            setFormatter((Formatter) cl.loadClass(formatterName).newInstance());
        } catch (final Exception e) {
            // Ignore and fallback to defaults
            setFormatter(new SimpleFormatter());
        }
    } else {
        setFormatter(new SimpleFormatter());
    }
    // Set error manager
    setErrorManager(new ErrorManager());
}
Also used : ErrorManager(java.util.logging.ErrorManager) SimpleFormatter(java.util.logging.SimpleFormatter) UnsupportedEncodingException(java.io.UnsupportedEncodingException) Timestamp(java.sql.Timestamp) UnsupportedEncodingException(java.io.UnsupportedEncodingException)

Example 38 with SimpleFormatter

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);
}
Also used : Config(edu.neu.ccs.pyramid.configuration.Config) SimpleFormatter(java.util.logging.SimpleFormatter) Logger(java.util.logging.Logger) File(java.io.File) FileHandler(java.util.logging.FileHandler)

Example 39 with SimpleFormatter

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);
                        }
                    }
                }
            }
        }
    }
}
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 40 with SimpleFormatter

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

Aggregations

SimpleFormatter (java.util.logging.SimpleFormatter)40 StreamHandler (java.util.logging.StreamHandler)15 ByteArrayOutputStream (java.io.ByteArrayOutputStream)13 Logger (java.util.logging.Logger)13 FileHandler (java.util.logging.FileHandler)9 LogRecord (java.util.logging.LogRecord)8 Handler (java.util.logging.Handler)7 MockResponse (com.google.mockwebserver.MockResponse)6 IOException (java.io.IOException)6 HttpClient (org.apache.http.client.HttpClient)6 HttpGet (org.apache.http.client.methods.HttpGet)6 DefaultHttpClient (org.apache.http.impl.client.DefaultHttpClient)6 ConsoleHandler (java.util.logging.ConsoleHandler)4 Level (java.util.logging.Level)3 Test (org.junit.Test)3 Config (edu.neu.ccs.pyramid.configuration.Config)2 File (java.io.File)2 Properties (java.util.Properties)2 MemoryHandler (java.util.logging.MemoryHandler)2 MockResponse (okhttp3.mockwebserver.MockResponse)2