Search in sources :

Example 21 with ConsoleHandler

use of java.util.logging.ConsoleHandler in project camel by apache.

the class ManagedSEDeployableContainer method configureLogging.

private void configureLogging(ManagedSEContainerConfiguration configuration) {
    ConsoleHandler consoleHandler = new ConsoleHandler();
    consoleHandler.setLevel(configuration.getLogLevel());
    LOGGER.setUseParentHandlers(false);
    LOGGER.addHandler(consoleHandler);
    LOGGER.setLevel(configuration.getLogLevel());
}
Also used : ConsoleHandler(java.util.logging.ConsoleHandler)

Example 22 with ConsoleHandler

use of java.util.logging.ConsoleHandler in project checkstyle by checkstyle.

the class Main method runCli.

/**
     * Do execution of CheckStyle based on Command line options.
     * @param commandLine command line object
     * @param filesToProcess List of files to process found from the command line.
     * @return number of violations
     * @throws IOException if a file could not be read.
     * @throws CheckstyleException if something happens processing the files.
     */
private static int runCli(CommandLine commandLine, List<File> filesToProcess) throws IOException, CheckstyleException {
    int result = 0;
    // create config helper object
    final CliOptions config = convertCliToPojo(commandLine, filesToProcess);
    if (commandLine.hasOption(OPTION_T_NAME)) {
        // print AST
        final File file = config.files.get(0);
        final String stringAst = AstTreeStringPrinter.printFileAst(file, false);
        System.out.print(stringAst);
    } else if (commandLine.hasOption(OPTION_CAPITAL_T_NAME)) {
        final File file = config.files.get(0);
        final String stringAst = AstTreeStringPrinter.printFileAst(file, true);
        System.out.print(stringAst);
    } else if (commandLine.hasOption(OPTION_J_NAME)) {
        final File file = config.files.get(0);
        final String stringAst = DetailNodeTreeStringPrinter.printFileAst(file);
        System.out.print(stringAst);
    } else if (commandLine.hasOption(OPTION_CAPITAL_J_NAME)) {
        final File file = config.files.get(0);
        final String stringAst = AstTreeStringPrinter.printJavaAndJavadocTree(file);
        System.out.print(stringAst);
    } else {
        if (commandLine.hasOption(OPTION_D_NAME)) {
            final Logger parentLogger = Logger.getLogger(Main.class.getName()).getParent();
            final ConsoleHandler handler = new ConsoleHandler();
            handler.setLevel(Level.FINEST);
            handler.setFilter(new Filter() {

                private final String packageName = Main.class.getPackage().getName();

                @Override
                public boolean isLoggable(LogRecord record) {
                    return record.getLoggerName().startsWith(packageName);
                }
            });
            parentLogger.addHandler(handler);
            parentLogger.setLevel(Level.FINEST);
        }
        if (LOG.isDebugEnabled()) {
            LOG.debug("Checkstyle debug logging enabled");
            LOG.debug("Running Checkstyle with version: " + Main.class.getPackage().getImplementationVersion());
        }
        // run Checker
        result = runCheckstyle(config);
    }
    return result;
}
Also used : Filter(java.util.logging.Filter) LogRecord(java.util.logging.LogRecord) Logger(java.util.logging.Logger) File(java.io.File) ConsoleHandler(java.util.logging.ConsoleHandler)

Example 23 with ConsoleHandler

use of java.util.logging.ConsoleHandler in project cogtool by cogtool.

the class CogTool method enableLogging.

public static void enableLogging(boolean value) {
    if (value) {
        logger.setLevel(Level.ALL);
        for (Handler h : logger.getHandlers()) {
            if (h instanceof FileHandler) {
                return;
            }
        }
        FileHandler fh = null;
        try {
            fh = new FileHandler((CogToolPref.LOG_DIRECTORY.getString() + LOG_FILE_PATTERN), LOG_FILE_MAX_SIZE, LOG_FILES_MAX_COUNT, true);
        } catch (IOException ex) {
            logger.warning("Couldn't create log file: " + ex);
            return;
        }
        fh.setFormatter(new Formatter() {

            @Override
            public String format(LogRecord r) {
                long ms = r.getMillis();
                return String.format("%tF %tT.%tL\t%s\n", ms, ms, ms, r.getMessage());
            }
        });
        logger.addHandler(fh);
    } else {
        logger.setLevel(DEFAULT_LOG_LEVEL);
        for (Handler h : logger.getHandlers()) {
            if (!(h instanceof ConsoleHandler)) {
                logger.removeHandler(h);
            }
        }
    }
}
Also used : LogRecord(java.util.logging.LogRecord) Formatter(java.util.logging.Formatter) FileHandler(java.util.logging.FileHandler) RcvrExceptionHandler(edu.cmu.cs.hcii.cogtool.ui.RcvrExceptionHandler) ConsoleHandler(java.util.logging.ConsoleHandler) Handler(java.util.logging.Handler) IOException(java.io.IOException) ConsoleHandler(java.util.logging.ConsoleHandler) FileHandler(java.util.logging.FileHandler)

Example 24 with ConsoleHandler

use of java.util.logging.ConsoleHandler in project j2objc by google.

the class ConsoleHandlerTest method testPublish_AfterResetSystemErr.

/*
	 * Test publish(), after system err is reset.
	 */
public void testPublish_AfterResetSystemErr() throws Exception {
    Properties p = new Properties();
    p.put("java.util.logging.ConsoleHandler.formatter", className + "$MockFormatter");
    LogManager.getLogManager().readConfiguration(EnvironmentHelper.PropertiesToInputStream(p));
    ConsoleHandler h = new ConsoleHandler();
    h.setFilter(new MockFilter());
    System.setErr(new PrintStream(new ByteArrayOutputStream()));
    LogRecord r = new LogRecord(Level.INFO, "testPublish_WithFilter");
    h.setLevel(Level.INFO);
    h.publish(r);
    assertNull(CallVerificationStack.getInstance().pop());
    assertSame(r, CallVerificationStack.getInstance().pop());
    assertEquals("", this.errSubstituteStream.toString());
}
Also used : PrintStream(java.io.PrintStream) LogRecord(java.util.logging.LogRecord) ByteArrayOutputStream(java.io.ByteArrayOutputStream) Properties(java.util.Properties) ConsoleHandler(java.util.logging.ConsoleHandler)

Example 25 with ConsoleHandler

use of java.util.logging.ConsoleHandler in project j2objc by google.

the class ConsoleHandlerTest method testPublish_WithFilter.

/*
	 * Test publish(), use a filter, having output stream, normal log record.
	 */
public void testPublish_WithFilter() throws Exception {
    Properties p = new Properties();
    p.put("java.util.logging.ConsoleHandler.formatter", className + "$MockFormatter");
    LogManager.getLogManager().readConfiguration(EnvironmentHelper.PropertiesToInputStream(p));
    ConsoleHandler h = new ConsoleHandler();
    h.setFilter(new MockFilter());
    LogRecord r = new LogRecord(Level.INFO, "testPublish_WithFilter");
    h.setLevel(Level.INFO);
    h.publish(r);
    assertNull(CallVerificationStack.getInstance().pop());
    assertSame(r, CallVerificationStack.getInstance().pop());
    assertEquals("", this.errSubstituteStream.toString());
    h.setLevel(Level.WARNING);
    h.publish(r);
    assertNull(CallVerificationStack.getInstance().pop());
    assertTrue(CallVerificationStack.getInstance().empty());
    assertEquals("", this.errSubstituteStream.toString());
    h.setLevel(Level.CONFIG);
    h.publish(r);
    assertNull(CallVerificationStack.getInstance().pop());
    assertSame(r, CallVerificationStack.getInstance().pop());
    assertEquals("", this.errSubstituteStream.toString());
    r.setLevel(Level.OFF);
    h.setLevel(Level.OFF);
    h.publish(r);
    assertNull(CallVerificationStack.getInstance().pop());
    assertEquals("", this.errSubstituteStream.toString());
    assertTrue(CallVerificationStack.getInstance().empty());
}
Also used : LogRecord(java.util.logging.LogRecord) Properties(java.util.Properties) ConsoleHandler(java.util.logging.ConsoleHandler)

Aggregations

ConsoleHandler (java.util.logging.ConsoleHandler)49 Handler (java.util.logging.Handler)19 Logger (java.util.logging.Logger)15 LogRecord (java.util.logging.LogRecord)13 Properties (java.util.Properties)12 IOException (java.io.IOException)5 PrintStream (java.io.PrintStream)5 FileHandler (java.util.logging.FileHandler)5 ByteArrayOutputStream (java.io.ByteArrayOutputStream)4 SimpleFormatter (java.util.logging.SimpleFormatter)4 File (java.io.File)3 ArrayList (java.util.ArrayList)2 Formatter (java.util.logging.Formatter)2 CommandCenterLogic (alma.acs.commandcenter.app.CommandCenterLogic)1 StartupOptions (alma.acs.commandcenter.app.CommandCenterLogic.StartupOptions)1 JmeFormatter (com.jme3.util.JmeFormatter)1 RcvrExceptionHandler (edu.cmu.cs.hcii.cogtool.ui.RcvrExceptionHandler)1 Rectangle (java.awt.Rectangle)1 InvocationTargetException (java.lang.reflect.InvocationTargetException)1 Method (java.lang.reflect.Method)1