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:MainClass.java

public static void main(String[] args) throws Exception {
    FileHandler logFile = new FileHandler("LogToFile2.txt");
    logFile.setFormatter(new SimpleFormatter());
    logger.addHandler(logFile);//w w w  .j a va 2  s .  co  m
    logger.info("A message logged to the file");
}

From source file:Main.java

public static void main(String args[]) throws Exception {
    XMLFormatter formatter = new XMLFormatter();
    LogRecord record = new LogRecord(Level.INFO, "XML message..");

    FileHandler handler = new FileHandler("newxml.xml");
    handler.setFormatter(formatter);

    handler.publish(record);/* www  .  j av  a  2 s. co m*/
    handler.flush();
}

From source file:Main.java

public static void main(String[] argv) throws Exception {
    Logger logger = Logger.getLogger("com.mycompany");
    FileHandler fh = new FileHandler("mylog.txt");
    fh.setFormatter(new SimpleFormatter());
    logger.addHandler(fh);// w w w.ja  v a2s. c  om

    // fh = new FileHandler("mylog.xml");
    // fh.setFormatter(new XMLFormatter());
    // logger.addHandler(fh);

    // Log a few messages
    logger.severe("my severe message");
    logger.warning("my warning message");
    logger.info("my info message");
    logger.config("my config message");
    logger.fine("my fine message");
    logger.finer("my finer message");
    logger.finest("my finest message");
}

From source file:MyHtmlFormatter.java

public static void main(String[] argv) throws Exception {
    Logger logger = Logger.getLogger("com.mycompany");
    FileHandler fh = new FileHandler("mylog.html");
    fh.setFormatter(new MyHtmlFormatter());
    logger.addHandler(fh);//from w  w w .ja  v a2 s  .c om

    logger.setLevel(Level.ALL);
    logger.severe("my severe message");
    logger.info("my info message");
    logger.entering("Main class", "myMethod", new Object[] { "para1", "para2" });
}

From source file:Main.java

public static void main(String args[]) throws Exception {
    LogManager lm = LogManager.getLogManager();
    Logger logger;//from   ww  w . j  a v a 2s.co m
    FileHandler fh = new FileHandler("log_test.txt");

    logger = Logger.getLogger("LoggingExample1");

    lm.addLogger(logger);
    logger.setLevel(Level.INFO);
    fh.setFormatter(new XMLFormatter());

    logger.addHandler(fh);
    //logger.setUseParentHandlers(false);
    logger.log(Level.INFO, "test 1");
    logger.log(Level.INFO, "test 2");
    logger.log(Level.INFO, "test 3");
    fh.close();
}

From source file:LoggingExample1.java

public static void main(String args[]) {
    try {//from w w  w . j a va2s .c  o m
        LogManager lm = LogManager.getLogManager();
        Logger logger;
        FileHandler fh = new FileHandler("log_test.txt");

        logger = Logger.getLogger("LoggingExample1");

        lm.addLogger(logger);
        logger.setLevel(Level.INFO);
        fh.setFormatter(new XMLFormatter());

        logger.addHandler(fh);
        //logger.setUseParentHandlers(false);
        logger.log(Level.INFO, "test 1");
        logger.log(Level.INFO, "test 2");
        logger.log(Level.INFO, "test 3");
        fh.close();
    } catch (Exception e) {
        System.out.println("Exception thrown: " + e);
        e.printStackTrace();
    }
}

From source file:edu.cmu.cs.lti.ark.fn.identification.latentmodel.LatentAlphabetCreationThreaded.java

public static void main(String[] args) throws IOException, ClassNotFoundException {
    final FNModelOptions options = new FNModelOptions(args);

    LogManager.getLogManager().reset();
    final FileHandler fileHandler = new FileHandler(options.logOutputFile.get(), true);
    fileHandler.setFormatter(new SimpleFormatter());
    logger.addHandler(fileHandler);//from  w  w w  .  ja  v a2  s. c  om

    final int startIndex = options.startIndex.get();
    final int endIndex = options.endIndex.get();
    logger.info("Start:" + startIndex + " end:" + endIndex);
    final RequiredDataForFrameIdentification r = SerializedObjects.readObject(options.fnIdReqDataFile.get());
    final Relations wnRelations = new CachedRelations(r.getRevisedRelMap(), r.getRelatedWordsForWord());
    final Lemmatizer lemmatizer = new CachedLemmatizer(r.getHvLemmaCache());
    final int numThreads = options.numThreads.present() ? options.numThreads.get()
            : Runtime.getRuntime().availableProcessors();
    final File alphabetDir = new File(options.modelFile.get());
    final LatentAlphabetCreationThreaded events = new LatentAlphabetCreationThreaded(alphabetDir,
            options.trainFrameElementFile.get(), options.trainParseFile.get(), r.getFrameMap(),
            new LatentFeatureExtractor(wnRelations, lemmatizer), startIndex, endIndex, numThreads);
    events.createLocalAlphabets();
    combineAlphabets(alphabetDir);
}

From source file:edu.cmu.cs.lti.ark.fn.identification.training.AlphabetCreationThreaded.java

/**
 * Parses commandline args, then creates a new {@link #AlphabetCreationThreaded} with them
 * and calls {@link #createAlphabet}/*w w  w .  j a v a2  s  .c o m*/
 *
 * @param args commandline arguments. see {@link #AlphabetCreationThreaded}
 *             for details.
 */
public static void main(String[] args)
        throws IOException, ClassNotFoundException, ExecutionException, InterruptedException {
    final FNModelOptions options = new FNModelOptions(args);

    LogManager.getLogManager().reset();
    final FileHandler fileHandler = new FileHandler(options.logOutputFile.get(), true);
    fileHandler.setFormatter(new SimpleFormatter());
    logger.addHandler(fileHandler);

    final int startIndex = options.startIndex.get();
    final int endIndex = options.endIndex.get();
    logger.info("Start:" + startIndex + " end:" + endIndex);
    final RequiredDataForFrameIdentification r = SerializedObjects.readObject(options.fnIdReqDataFile.get());

    final int minimumCount = options.minimumCount.present() ? options.minimumCount.get()
            : DEFAULT_MINIMUM_FEATURE_COUNT;
    final int numThreads = options.numThreads.present() ? options.numThreads.get()
            : Runtime.getRuntime().availableProcessors();
    final File alphabetDir = new File(options.modelFile.get());
    final String featureExtractorType = options.idFeatureExtractorType.present()
            ? options.idFeatureExtractorType.get()
            : "basic";
    final IdFeatureExtractor featureExtractor = IdFeatureExtractor.fromName(featureExtractorType);
    final AlphabetCreationThreaded events = new AlphabetCreationThreaded(options.trainFrameElementFile.get(),
            options.trainParseFile.get(), r.getFrameMap().keySet(), featureExtractor, startIndex, endIndex,
            numThreads);
    final Multiset<String> unconjoinedFeatures = events.createAlphabet();
    final File alphabetFile = new File(alphabetDir, ALPHABET_FILENAME);
    events.conjoinAndWriteAlphabet(unconjoinedFeatures, minimumCount, alphabetFile);
}

From source file:edu.cmu.cs.lti.ark.fn.identification.latentmodel.TrainBatchModelDerThreaded.java

public static void main(String[] args) throws Exception {
    final FNModelOptions options = new FNModelOptions(args);
    LogManager.getLogManager().reset();
    final FileHandler fh = new FileHandler(options.logOutputFile.get(), true);
    fh.setFormatter(new SimpleFormatter());
    logger.addHandler(fh);/*w w w . j  a va 2  s . c o  m*/

    final String restartFile = options.restartFile.get();
    final int numThreads = options.numThreads.present() ? options.numThreads.get()
            : Runtime.getRuntime().availableProcessors();
    final TrainBatchModelDerThreaded tbm = new TrainBatchModelDerThreaded(options.alphabetFile.get(),
            options.eventsFile.get(), options.modelFile.get(), options.reg.get(), options.lambda.get(),
            restartFile.equals("null") ? Optional.<String>absent() : Optional.of(restartFile), numThreads);
    tbm.trainModel();
}

From source file:HTMLFormatter.java

public static void main(String args[]) throws Exception {
    LogManager lm = LogManager.getLogManager();
    Logger parentLogger, childLogger;
    FileHandler xml_handler = new FileHandler("log_output.xml");
    FileHandler html_handler = new FileHandler("log_output.html");
    parentLogger = Logger.getLogger("ParentLogger");
    childLogger = Logger.getLogger("ParentLogger.ChildLogger");

    lm.addLogger(parentLogger);/*from   ww  w . j av a 2  s. c o  m*/

    lm.addLogger(childLogger);

    parentLogger.setLevel(Level.WARNING);
    childLogger.setLevel(Level.ALL);
    xml_handler.setFormatter(new XMLFormatter());
    html_handler.setFormatter(new HTMLFormatter());

    parentLogger.addHandler(xml_handler);
    childLogger.addHandler(html_handler);

    childLogger.log(Level.FINE, "This is a fine log message");
    childLogger.log(Level.SEVERE, "This is a severe log message");
    xml_handler.close();
    html_handler.close();
}