Example usage for java.util.logging FileHandler setFormatter

List of usage examples for java.util.logging FileHandler setFormatter

Introduction

In this page you can find the example usage for java.util.logging FileHandler setFormatter.

Prototype

public synchronized void setFormatter(Formatter newFormatter) throws SecurityException 

Source Link

Document

Set a Formatter .

Usage

From source file:regextester.RegexTester.java

public RegexTester() throws Exception {
    RegexTester.application = this;

    // First setup our logger
    this.checkSettingsDirExists();
    logger.setLevel(Level.SEVERE);
    FileHandler fh = new FileHandler(this.settingsDirname + File.separator + "debug.log", 8096, 1, true);
    logger.addHandler(fh);/* w ww.  j  av a2s  .c o m*/
    SimpleFormatter formatter = new SimpleFormatter();
    fh.setFormatter(formatter);
    logger.info("Starting RegexTester");

    // Load our properties and attach the database, creating it if it doesn't exist
    this.loadProperties();

    // Create our GUI
    UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
    window = new MainWindow(this);
    window.setLocationRelativeTo(null);
    window.setTitle("RegexTester");
    window.setVisible(true);
}

From source file:namedatabasescraper.NameDatabaseScraper.java

public NameDatabaseScraper() throws Exception {
    NameDatabaseScraper.application = this;

    // First setup our logger
    this.checkSettingsDirExists();
    logger.setLevel(Level.INFO);//w w  w.  jav a 2  s. com
    FileHandler fh = new FileHandler(this.settingsDirname + File.separator + "debug.log", 8096, 1, false);
    logger.addHandler(fh);
    SimpleFormatter formatter = new SimpleFormatter();
    fh.setFormatter(formatter);
    logger.info("Starting NameDatabaseScraper");

    // Load our properties and attach the database, creating it if it doesn't exist
    this.loadProperties();
    this.attachDatabase();

    // Create our GUI
    UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
    window = new MainWindow(this);
    window.setLocationRelativeTo(null);
    window.setTitle("NameDatabaseScraper");
    window.setVisible(true);
}

From source file:com.nilostep.xlsql.database.xlInstance.java

private xlInstance(String cfg) throws xlException {
    logger = Logger.getLogger(this.getClass().getName());
    instance = this;

    try {//from w  w w  . ja  va 2s  .  co  m
        PropertiesConfiguration config = new PropertiesConfiguration();
        config.load(this.getClass().getResourceAsStream(cfg + ".properties"));
        this.config = config;

        engine = config.getString("general.engine");

        logger.info("Configuration engine: " + engine + " loaded");
    } catch (ConfigurationException e) {
        e.printStackTrace();
        throw new xlException(e.getMessage());
    }

    try {
        boolean append = true;
        FileHandler loghandler = new FileHandler(getLog(), append);
        loghandler.setFormatter(new SimpleFormatter());
        logger.addHandler(loghandler);
    } catch (IOException e) {
        throw new xlException("error while creating logfile");
    }

    logger.info("Instance created with engine " + getEngine());
}

From source file:org.norvelle.addressdiscoverer.AddressDiscoverer.java

@SuppressWarnings("LeakingThisInConstructor")
public AddressDiscoverer() throws Exception {
    AddressDiscoverer.application = this;

    // First setup our logger. The ORMLite logger is prolix and useless,
    // so we redirect it to a temp file.
    System.setProperty(LocalLog.LOCAL_LOG_FILE_PROPERTY,
            System.getProperty("java.io.tmpdir") + File.separator + "addressdiscoverer.ormlite.log");
    this.checkSettingsDirExists();
    logger.setLevel(Level.SEVERE);
    FileHandler fh = new FileHandler(this.settingsDirname + File.separator + "debug.log", 8096, 1, true);
    logger.addHandler(fh);/*w  w w .ja  va2 s.  c  om*/
    SimpleFormatter formatter = new SimpleFormatter();
    fh.setFormatter(formatter);
    logger.info("Starting AddressDiscoverer");

    // Load our properties and attach the database, creating it if it doesn't exist
    this.loadProperties();
    this.attachDatabase();
    KnownLastName.initialize(this.settingsDirname);
    KnownFirstName.initialize(this.settingsDirname);
    KnownSpanishWord.initialize(this.settingsDirname);
    Abbreviations.initialize(this.settingsDirname);
    GrammarParticles.initialize(this.settingsDirname);
    GenderDeterminer.initialize(this.settingsDirname);

    // Create our GUI
    UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
    window = new MainWindow(this);
    window.setTitle("AddressDiscoverer");
    window.setExtendedState(window.getExtendedState() | java.awt.Frame.MAXIMIZED_BOTH);
    window.setVisible(true);
}

From source file:com.valygard.aohruthless.Joystick.java

/**
 * Not satisfied with global logging, which can become cluttered and messy
 * with many plugins or players using commands, etc, the Bukkit logger will
 * log all relevant information to a log file. This log file can be found in
 * the plugin data folder, in the subdirectory <i>logs</i>.
 * <p>/*from  ww  w.jav  a  2s . co m*/
 * The log file, <i>joystick.log</i>, will not be overriden. The logger will
 * simply append new information if the file already exists. All messages
 * will be logged in the format:<br>
 * [month-day-year hr-min-sec] (level): (message), where level is the
 * {@link LogRecord#getLevel()} and the message is the
 * {@link LogRecord#getMessage()}.
 * </p>
 * 
 * @return the created FileHandler, null if a SecurityException or
 *         IOException were thrown and handled.
 */
private FileHandler setupLogger() {
    File dir = new File(getDataFolder() + File.separator + "logs");
    dir.mkdirs();
    try {
        FileHandler handler = new FileHandler(dir + File.separator + "joystick.log", true);
        getLogger().addHandler(handler);
        handler.setFormatter(new SimpleFormatter() {

            @Override
            public String format(LogRecord record) {
                Date date = new Date();
                SimpleDateFormat df = new SimpleDateFormat("[MM-dd-yyyy HH:mm:ss]");
                return df.format(date) + " " + record.getLevel() + ":"
                // org.apache.commons.lang
                        + StringUtils.replace(record.getMessage(), "[Joystick]", "")
                        + System.getProperty("line.separator");
            }
        });
        return handler;
    } catch (SecurityException | IOException e) {
        e.printStackTrace();
        return null;
    }
}

From source file:com.skelril.aurora.jail.CSVInmateDatabase.java

public CSVInmateDatabase(File inmateStorageDir) {

    inmateFile = new File(inmateStorageDir, "inmates.csv");

    // Set up an audit trail
    try {//from   w  w w  .j  a v  a2s .c om
        FileHandler handler = new FileHandler(
                (new File(inmateStorageDir, "inmates.%g.%u.log")).getAbsolutePath().replace("\\", "/"), true);

        handler.setFormatter(new Formatter() {

            @Override
            public String format(LogRecord record) {

                return "[" + dateFormat.format(new Date()) + "] " + record.getMessage() + "\r\n";
            }
        });

        auditLogger.addHandler(handler);
    } catch (SecurityException | IOException e) {
        log.warning("Failed to setup audit log for the " + "CSV inmate database: " + e.getMessage());
    }
}

From source file:com.skelril.aurora.jail.CSVJailCellDatabase.java

public CSVJailCellDatabase(File cellStorageDir) {

    cellFile = new File(cellStorageDir, "cells.csv");

    // Set up an audit trail
    try {/*from w  ww  . j  av  a2s.c  o  m*/
        FileHandler handler = new FileHandler(
                (new File(cellStorageDir, "cells.%g.%u.log")).getAbsolutePath().replace("\\", "/"), true);

        handler.setFormatter(new java.util.logging.Formatter() {

            @Override
            public String format(LogRecord record) {

                return "[" + dateFormat.format(new Date()) + "] " + record.getMessage() + "\r\n";
            }
        });

        auditLogger.addHandler(handler);
    } catch (SecurityException | IOException e) {
        log.warning("Failed to setup audit log for the CSV cell database: " + e.getMessage());
    }
}

From source file:org.ocsoft.olivia.logger.LogStation.java

/**
 * ???????./*from  w  w  w . ja v a  2s.com*/
 * @return ????????
 */
@Nonnull
private FileHandler createLogFileHandler() {
    try {
        FileHandler fh = new FileHandler(DefaultValues.USER_LOG_FILE.getAbsolutePathString(), true);
        //logger??JSON??
        fh.setFormatter(new OliviaLogFileFormatter());
        return fh;
    } catch (Exception e) {
        e.printStackTrace();
    }
    return null;
}

From source file:org.cloudifysource.azure.CliAzureDeploymentTest.java

@Test(timeout = 120 * 60 * 1000L)
public void repeatTest() throws Throwable {
    DateFormat df = new SimpleDateFormat("_yyyy-MM-dd_hh-mm");
    int repeat = 1;
    for (int i = 1; i <= repeat; i++) {
        //overwrites any existing file with that name.
        String filePattern = "azuretest" + i + df.format(new Date()) + ".log";
        FileHandler fileHandler = new FileHandler(filePattern);
        fileHandler.setFormatter(new SimpleFormatter());
        logger.addHandler(fileHandler);// w w w.j a  v a  2 s  .c  o m

        logger.info("Starting test iteration #" + i);
        boolean failed = false;
        try {
            before();
            test();
        } catch (Throwable t) {
            failed = true;
            throw t;
        } finally {
            if (failed) {
                logger.info(
                        "Failed test iteration #" + i + ". Machines are left running for manual diagnostics");
                logger.removeHandler(fileHandler);
                try {
                    SimpleMail.send("Azure test failed\nSubscription ID="
                            + credentials.getHostedServicesSubscriptionId(), new File(filePattern));
                } catch (Exception e) {
                    logger.log(Level.SEVERE, "Failed to send email", e);
                }
                after();
                // no need to break since an exception was raised and is going to fail the test
            } else {
                logger.info("Passed test iteration #" + i);
                logger.removeHandler(fileHandler);
                try {
                    SimpleMail.send("Azure test passed\nSubscription ID="
                            + credentials.getHostedServicesSubscriptionId(), new File(filePattern));
                } catch (Exception e) {
                    logger.log(Level.SEVERE, "Failed to send email", e);
                }
                after();
                // no need to break since we want to test the run multiple times (or until it fails)
            }
        }
    }
}

From source file:org.apache.oodt.cas.pge.PGETaskInstance.java

protected Logger createLogger() throws IOException, PGEException {
    File logDir = new File(pgeConfig.getExeDir(), "logs");
    if (!(logDir.exists() || logDir.mkdirs())) {
        throw new PGEException("mkdirs for logs directory return false");
    }/*from   w w  w .j a  va  2 s.com*/

    Logger logger = Logger.getLogger(PGETaskInstance.class.getName() + "." + workflowInstId);
    FileHandler handler = new FileHandler(new File(logDir, createLogFileName()).getAbsolutePath());
    handler.setEncoding("UTF-8");
    handler.setFormatter(new SimpleFormatter());
    logger.addHandler(handler);
    return logger;
}