Example usage for java.util.logging SimpleFormatter SimpleFormatter

List of usage examples for java.util.logging SimpleFormatter SimpleFormatter

Introduction

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

Prototype

SimpleFormatter

Source Link

Usage

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);//from  www .  j  av a 2s.c  o m

    // 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: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 . jav  a2  s. com*/
    logger.info("A message logged to the file");
}

From source file:com.versusoft.packages.ooo.odt2daisy.gui.CommandLineGUI.java

public static void main(String args[]) throws IOException {

    Handler fh = new FileHandler(LOG_FILENAME_PATTERN);
    fh.setFormatter(new SimpleFormatter());

    //removeAllLoggersHandlers(Logger.getLogger(""));

    Logger.getLogger("").addHandler(fh);
    Logger.getLogger("").setLevel(Level.FINEST);

    Options options = new Options();

    Option option1 = new Option("in", "name of ODT file (required)");
    option1.setRequired(true);/*from  w w  w.  jav  a2s  .  c  o m*/
    option1.setArgs(1);

    Option option2 = new Option("out", "name of DAISY DTB file (required)");
    option2.setRequired(true);
    option2.setArgs(1);

    Option option3 = new Option("h", "show this help");
    option3.setArgs(Option.UNLIMITED_VALUES);

    Option option4 = new Option("alt", "use alternate Level Markup");

    Option option5 = new Option("u", "UID of DAISY DTB (optional)");
    option5.setArgs(1);

    Option option6 = new Option("t", "Title of DAISY DTB");
    option6.setArgs(1);

    Option option7 = new Option("c", "Creator of DAISY DTB");
    option7.setArgs(1);

    Option option8 = new Option("p", "Publisher of DAISY DTB");
    option8.setArgs(1);

    Option option9 = new Option("pr", "Producer of DAISY DTB");
    option9.setArgs(1);

    Option option10 = new Option("pic", "set Picture directory");
    option10.setArgs(1);

    Option option11 = new Option("page", "enable pagination");
    option11.setArgs(0);

    Option option12 = new Option("css", "write CSS file");
    option12.setArgs(0);

    options.addOption(option1);
    options.addOption(option2);
    options.addOption(option3);
    options.addOption(option4);
    options.addOption(option5);
    options.addOption(option6);
    options.addOption(option7);
    options.addOption(option8);
    options.addOption(option9);
    options.addOption(option10);
    options.addOption(option11);
    options.addOption(option12);

    CommandLineParser parser = new BasicParser();
    CommandLine cmd = null;

    try {
        cmd = parser.parse(options, args);
    } catch (ParseException e) {
        //System.out.println("***ERROR: " + e.getClass() + ": " + e.getMessage());

        printHelp();
        return;
    }

    if (cmd.hasOption("help")) {
        printHelp();
        return;
    }

    try {

        Odt2Daisy odt2daisy = new Odt2Daisy(cmd.getOptionValue("in")); //@todo add initial output directory URL?
        odt2daisy.init();

        if (odt2daisy.isEmptyDocument()) {
            logger.info("Cannot convert empty documents. Export Aborted...");
            System.exit(1);
        }

        //System.out.println("Metadatas");
        //System.out.println("- title: " + odt2daisy.getTitleMeta());
        //System.out.println("- creator: " + odt2daisy.getCreatorMeta());

        if (!odt2daisy.isUsingHeadings()) {
            logger.info("You SHOULD use Heading styles in your document. Export in a single level.");
        }
        //@todo Warning for incompatible image formats should go here. See UnoGui.java.

        if (cmd.hasOption("u")) {
            //System.out.println("arg uid:"+cmd.getOptionValue("u"));
            odt2daisy.setUidParam(cmd.getOptionValue("u"));
        }

        if (cmd.hasOption("t")) {
            //System.out.println("arg title:"+cmd.getOptionValue("t"));
            odt2daisy.setTitleParam(cmd.getOptionValue("t"));
        }

        if (cmd.hasOption("c")) {
            //System.out.println("arg creator:"+cmd.getOptionValue("c"));
            odt2daisy.setCreatorParam(cmd.getOptionValue("c"));
        }

        if (cmd.hasOption("p")) {
            //System.out.println("arg publisher:"+cmd.getOptionValue("p"));
            odt2daisy.setPublisherParam(cmd.getOptionValue("p"));
        }

        if (cmd.hasOption("pr")) {
            //System.out.println("arg producer:"+cmd.getOptionValue("pr"));
            odt2daisy.setProducerParam(cmd.getOptionValue("pr"));
        }

        if (cmd.hasOption("alt")) {
            //System.out.println("arg alt:"+cmd.getOptionValue("alt"));
            odt2daisy.setUseAlternateLevelParam(true);
        }

        if (cmd.hasOption("css")) {
            odt2daisy.setWriteCSSParam(true);
        }

        if (cmd.hasOption("page")) {
            odt2daisy.paginationProcessing();
        }

        odt2daisy.correctionProcessing();

        if (cmd.hasOption("pic")) {

            odt2daisy.convertAsDTBook(cmd.getOptionValue("out"), cmd.getOptionValue("pic"));

        } else {

            logger.info("Language detected: " + odt2daisy.getLangParam());
            odt2daisy.convertAsDTBook(cmd.getOptionValue("out"), Configuration.DEFAULT_IMAGE_DIR);
        }

        boolean valid = odt2daisy.validateDTD(cmd.getOptionValue("out"));

        if (valid) {

            logger.info("DAISY DTBook produced is valid against DTD - Congratulations !");

        } else {

            logger.info("DAISY Book produced isn't valid against DTD - You SHOULD NOT use this DAISY Book !");
            logger.info("Error at line: " + odt2daisy.getErrorHandler().getLineNumber());
            logger.info("Error Message: " + odt2daisy.getErrorHandler().getMessage());
        }

    } catch (Exception e) {

        e.printStackTrace();

    } finally {

        if (fh != null) {
            fh.flush();
            fh.close();
        }
    }

}

From source file:com.biggerbytes.scheduleupdates.Main.java

/**
 * //from   ww  w .  j  av  a2 s . co  m
 * @param args
 * @throws IOException 
 */
public static void main(String[] args) throws IOException {
    java.util.logging.Logger.getLogger("com.gargoylesoftware").setLevel(Level.OFF); // In order to remove all the log warnings, THANK GOD IT IS THAT SIMPLE
    final int PORT = 25565;
    ServerSocket serverSocket = null;

    // Logger initialization 
    if (LOG) {
        fh = new FileHandler("serv_log.log", true); //It will create a new file everytime we start the server because the previous log is locked, I am not really sure where to close the handler.
        logger.addHandler(fh);
        SimpleFormatter formatter = new SimpleFormatter();
        fh.setFormatter(formatter);
    }
    //        /* Dummy Test */
    //        List<Byte> command = new ArrayList<>();
    //        command.add(CommandConstants.SCEHDULES_HEADER);
    //        command.add(CommandConstants.ADD_SUB_DUMMY);
    //        command.add((byte) 24);
    //        command.addAll(Arrays.asList(ArrayUtils.toObject("05".getBytes())));
    //        command.addAll(Arrays.asList(ArrayUtils.toObject("20.03.2016".getBytes())));
    //        command.addAll(Arrays.asList(ArrayUtils.toObject(" ".getBytes())));
    //        System.out.println("Size is " + command.size());
    //        byte[] commandArr = new byte[command.size()];
    //        for (int i = 0; i < commandArr.length; ++i)
    //            commandArr[i] = command.get(i);
    //        CommandProcessor.executeCommand(commandArr);
    /* Dummy Test End - TESTED, IT WORKS*/

    /* Dummy removal */
    //        byte[] remvCommand = new byte[3];
    //        remvCommand[0] = CommandConstants.SCEHDULES_HEADER;
    //        remvCommand[1] = CommandConstants.REMOVE_ALL_DUMMIES_FROM_ID;
    //        remvCommand[2] = (byte) 24;
    //        
    //        CommandProcessor.executeCommand(remvCommand);
    //        /* Dummy removal end - TESTED, WORKS*/

    try {
        serverSocket = new ServerSocket(PORT);
        initDataRefreshThread();
        infoReadThread.start();
    } catch (Exception e) {
        if (LOG)
            logger.info("Couldn't listen on port " + PORT);
        System.exit(-1);
    }

    new CreateClientThread().start(); //Setup thread for creating threads for clients

    while (true) {
        System.out.println("waiting");
        if (LOG)
            logger.info("Waiting for a client."); //TODO wait for the server to finish loading data then start waiting for a client
        Socket clientSocket = serverSocket.accept();
        clientsQ.add(clientSocket);
    }
}

From source file:com.versusoft.packages.jodl.gui.CommandLineGUI.java

public static void main(String args[]) throws SAXException, IOException {

    Handler fh = new FileHandler(LOG_FILENAME_PATTERN);
    fh.setFormatter(new SimpleFormatter());

    //removeAllLoggersHandlers(Logger.getLogger(""));
    Logger.getLogger("").addHandler(fh);
    Logger.getLogger("").setLevel(Level.FINEST);

    Options options = new Options();

    Option option1 = new Option("in", "ODT file (required)");
    option1.setRequired(true);/*from   www . j  a va 2 s. c  o m*/
    option1.setArgs(1);

    Option option2 = new Option("out", "Output file (required)");
    option2.setRequired(false);
    option2.setArgs(1);

    Option option3 = new Option("pic", "extract pics");
    option3.setRequired(false);
    option3.setArgs(1);

    Option option4 = new Option("page", "enable pagination processing");
    option4.setRequired(false);
    option4.setArgs(0);

    options.addOption(option1);
    options.addOption(option2);
    options.addOption(option3);
    options.addOption(option4);

    CommandLineParser parser = new BasicParser();
    CommandLine cmd = null;

    try {
        cmd = parser.parse(options, args);
    } catch (ParseException e) {
        printHelp();
        return;
    }

    if (cmd.hasOption("help")) {
        printHelp();
        return;
    }

    File outFile = new File(cmd.getOptionValue("out"));

    OdtUtils utils = new OdtUtils();

    utils.open(cmd.getOptionValue("in"));
    //utils.correctionStep();
    utils.saveXML(outFile.getAbsolutePath());

    try {

        if (cmd.hasOption("page")) {
            OdtUtils.paginationProcessing(outFile.getAbsolutePath());
        }

        OdtUtils.correctionProcessing(outFile.getAbsolutePath());

    } catch (ParserConfigurationException ex) {
        logger.log(Level.SEVERE, null, ex);
    } catch (SAXException ex) {
        logger.log(Level.SEVERE, null, ex);
    } catch (IOException ex) {
        logger.log(Level.SEVERE, null, ex);
    } catch (TransformerConfigurationException ex) {
        logger.log(Level.SEVERE, null, ex);
    } catch (TransformerException ex) {
        logger.log(Level.SEVERE, null, ex);
    }

    if (cmd.hasOption("pic")) {

        String imageDir = cmd.getOptionValue("pic");
        if (!imageDir.endsWith("/")) {
            imageDir += "/";
        }

        try {

            String basedir = new File(cmd.getOptionValue("out")).getParent().toString()
                    + System.getProperty("file.separator");
            OdtUtils.extractAndNormalizeEmbedPictures(cmd.getOptionValue("out"), cmd.getOptionValue("in"),
                    basedir, imageDir);
        } catch (SAXException ex) {
            logger.log(Level.SEVERE, null, ex);
        } catch (ParserConfigurationException ex) {
            logger.log(Level.SEVERE, null, ex);
        } catch (TransformerConfigurationException ex) {
            logger.log(Level.SEVERE, null, ex);
        } catch (TransformerException ex) {
            logger.log(Level.SEVERE, null, ex);
        }
    }

}

From source file:org.azrul.langmera.DecisionService.java

public static void main(String[] args) throws IOException {
    ConfigurationProvider config = null;
    ConfigFilesProvider configFilesProvider = () -> Arrays.asList(Paths.get("config.properties"));
    if (args.length <= 0) {
        ConfigurationSource source = new ClasspathConfigurationSource(configFilesProvider);
        config = new ConfigurationProviderBuilder().withConfigurationSource(source).build();
    } else {//www. j a v  a  2  s .  co  m
        ConfigurationSource source = new FilesConfigurationSource(configFilesProvider);
        Environment environment = new ImmutableEnvironment(args[0]);
        config = new ConfigurationProviderBuilder().withConfigurationSource(source).withEnvironment(environment)
                .build();

    }
    Logger logger = null;
    if (config.getProperty("log.file", String.class).isEmpty() == false) {
        FileHandler logHandler = new FileHandler(config.getProperty("log.file", String.class),
                config.getProperty("log.sizePerFile", Integer.class) * 1024 * 1024,
                config.getProperty("log.maxFileCount", Integer.class), true);
        logHandler.setFormatter(new SimpleFormatter());
        logHandler.setLevel(Level.INFO);

        Logger rootLogger = Logger.getLogger("");
        rootLogger.removeHandler(rootLogger.getHandlers()[0]);
        logHandler.setLevel(Level.parse(config.getProperty("log.level", String.class)));
        rootLogger.setLevel(Level.parse(config.getProperty("log.level", String.class)));
        rootLogger.addHandler(logHandler);

        logger = rootLogger;
    } else {
        logger = Logger.getGlobal();
    }

    VertxOptions options = new VertxOptions();
    options.setMaxEventLoopExecuteTime(Long.MAX_VALUE);
    options.setWorkerPoolSize(config.getProperty("workerPoolSize", Integer.class));
    options.setEventLoopPoolSize(40);

    Vertx vertx = Vertx.vertx(options);
    vertx.deployVerticle(new DecisionService(logger, config));
    vertx.deployVerticle(new SaveToDB(logger, config));

}

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}//from   w w  w . j  av 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.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);/*  w w  w  . j  a v  a  2  s . c o  m*/

    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:core.PlanC.java

/**
 * inicio de aplicacion/*from www .  j  a va  2 s . c  o  m*/
 * 
 * @param arg - argumentos de entrada
 */
public static void main(String[] args) {

    // user.name

    /*
     * Properties prp = System.getProperties(); System.out.println(getWmicValue("bios", "SerialNumber"));
     * System.out.println(getWmicValue("cpu", "SystemName"));
     */

    try {
        // log
        // -Djava.util.logging.SimpleFormatter.format='%1$tY-%1$tm-%1$td %1$tH:%1$tM:%1$tS %4$s %2$s %5$s%6$s%n'
        // System.setProperty("java.util.logging.SimpleFormatter.format",
        // "%1$tY-%1$tm-%1$td %1$tH:%1$tM:%1$tS %4$s %2$s %5$s%6$s%n");
        System.setProperty("java.util.logging.SimpleFormatter.format",
                "%1$tY-%1$tm-%1$td %1$tH:%1$tM:%1$tS %5$s%6$s%n");

        FileHandler fh = new FileHandler(LOG_FILE);
        fh.setFormatter(new SimpleFormatter());
        fh.setLevel(Level.INFO);
        ConsoleHandler ch = new ConsoleHandler();
        ch.setFormatter(new SimpleFormatter());
        ch.setLevel(Level.INFO);
        logger = Logger.getLogger("");
        Handler[] hs = logger.getHandlers();
        for (int x = 0; x < hs.length; x++) {
            logger.removeHandler(hs[x]);
        }
        logger.addHandler(fh);
        logger.addHandler(ch);
        // point apache log to this log
        System.setProperty("org.apache.commons.logging.Log", Jdk14Logger.class.getName());

        TPreferences.init();
        TStringUtils.init();

        Font fo = Font.createFont(Font.TRUETYPE_FONT, TResourceUtils.getFile("Dosis-Light.ttf"));
        GraphicsEnvironment.getLocalGraphicsEnvironment().registerFont(fo);
        fo = Font.createFont(Font.TRUETYPE_FONT, TResourceUtils.getFile("Dosis-Medium.ttf"));
        GraphicsEnvironment.getLocalGraphicsEnvironment().registerFont(fo);
        fo = Font.createFont(Font.TRUETYPE_FONT, TResourceUtils.getFile("AERO_ITALIC.ttf"));
        GraphicsEnvironment.getLocalGraphicsEnvironment().registerFont(fo);

        SwingTimerTimingSource ts = new SwingTimerTimingSource();
        AnimatorBuilder.setDefaultTimingSource(ts);
        ts.init();

        // parse app argument parameters and append to tpreferences to futher uses
        for (String arg : args) {
            String[] kv = arg.split("=");
            TPreferences.setProperty(kv[0], kv[1]);
        }
        RUNNING_MODE = TPreferences.getProperty("runningMode", RM_NORMAL);

        newMsg = Applet.newAudioClip(TResourceUtils.getURL("newMsg.wav"));

    } catch (Exception e) {
        SystemLog.logException1(e, true);
    }

    // pass icon from metal to web look and feel
    Icon i1 = UIManager.getIcon("OptionPane.errorIcon");
    Icon i2 = UIManager.getIcon("OptionPane.informationIcon");
    Icon i3 = UIManager.getIcon("OptionPane.questionIcon");
    Icon i4 = UIManager.getIcon("OptionPane.warningIcon");
    // Object fcui = UIManager.get("FileChooserUI");
    // JFileChooser fc = new JFileChooser();

    WebLookAndFeel.install();
    // WebLookAndFeel.setDecorateFrames(true);
    // WebLookAndFeel.setDecorateDialogs(true);

    UIManager.put("OptionPane.errorIcon", i1);
    UIManager.put("OptionPane.informationIcon", i2);
    UIManager.put("OptionPane.questionIcon", i3);
    UIManager.put("OptionPane.warningIcon", i4);
    // UIManager.put("TFileChooserUI", fcui);

    // warm up the IDW.
    // in my computer, some weird error ocurr if i don't execute this preload.
    new RootWindow(null);

    frame = new TWebFrame();
    frame.addWindowListener(new WindowAdapter() {
        public void windowClosing(WindowEvent e) {
            Exit.shutdown();
        }
    });

    if (RUNNING_MODE.equals(RM_NORMAL)) {
        initEnviorement();
    }
    if (RUNNING_MODE.equals(RM_CONSOLE)) {
        initConsoleEnviorement();
    }

    if (RUNNING_MODE.equals(ONE_TASK)) {
        String cln = TPreferences.getProperty("taskName", "*TaskNotFound");
        PlanC.logger.log(Level.INFO, "OneTask parameter found in .properties. file Task name = " + cln);
        try {
            Class cls = Class.forName(cln);
            Object dobj = cls.newInstance();
            // new class must be extends form AbstractExternalTask
            TTaskManager.executeTask((Runnable) dobj);
            return;
        } catch (Exception e) {
            PlanC.logger.log(Level.SEVERE, e.getMessage(), e);
            Exit.shutdown();
        }
    }
}

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);/*from  w  w w .  ja  v  a 2s  .c  om*/

    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();
}