Search in sources :

Example 51 with ConsoleHandler

use of java.util.logging.ConsoleHandler in project gatk by broadinstitute.

the class LoggingUtils method setJavaUtilLoggingLevel.

/**
     * Set the java.util.logging level since some of our dependencies write messages using it.
     *
     * Taken with modifications from a post by michel.iamit
     * http://stackoverflow.com/users/369060/michel-iamit
     * from http://stackoverflow.com/questions/470430/java-util-logging-logger-doesnt-respect-java-util-logging-level
     */
private static void setJavaUtilLoggingLevel(final Log.LogLevel verbosity) {
    Logger topLogger = java.util.logging.Logger.getLogger("");
    Handler consoleHandler = null;
    for (Handler handler : topLogger.getHandlers()) {
        if (handler instanceof ConsoleHandler) {
            consoleHandler = handler;
            break;
        }
    }
    if (consoleHandler == null) {
        consoleHandler = new ConsoleHandler();
        topLogger.addHandler(consoleHandler);
    }
    consoleHandler.setLevel(levelToJavaUtilLevel(verbosity));
}
Also used : ConsoleHandler(java.util.logging.ConsoleHandler) Handler(java.util.logging.Handler) Logger(java.util.logging.Logger) ConsoleHandler(java.util.logging.ConsoleHandler)

Example 52 with ConsoleHandler

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

the class IgniteUtils method addJavaNoOpLogger.

/**
 * Adds no-op console handler for root java logger.
 *
 * @return Removed handlers.
 */
public static Collection<Handler> addJavaNoOpLogger() {
    Collection<Handler> savedHnds = new ArrayList<>();
    Logger log = Logger.getLogger("");
    for (Handler h : log.getHandlers()) {
        log.removeHandler(h);
        savedHnds.add(h);
    }
    ConsoleHandler hnd = new ConsoleHandler();
    hnd.setLevel(Level.OFF);
    log.addHandler(hnd);
    return savedHnds;
}
Also used : ArrayList(java.util.ArrayList) ConsoleHandler(java.util.logging.ConsoleHandler) Handler(java.util.logging.Handler) IgniteLogger(org.apache.ignite.IgniteLogger) Logger(java.util.logging.Logger) ConsoleHandler(java.util.logging.ConsoleHandler)

Example 53 with ConsoleHandler

use of java.util.logging.ConsoleHandler in project Payara by payara.

the class EjbClosureCompiler method main.

public static void main(String[] args) {
    Handler h = new ConsoleHandler();
    h.setLevel(Level.ALL);
    // NOI18N
    Logger.getLogger("apiscan").addHandler(h);
    // NOI18N
    Logger.getLogger("apiscan").setLevel(Level.ALL);
    int j = 0;
    String pcp = "";
    String specVer = "";
    for (j = 0; j < args.length; ++j) {
        if (args[j].equals("-prefixClassPath")) {
            // NOI18N
            pcp = args[++j];
            continue;
        } else if (args[j].equals("-specVer")) {
            // NOI18N
            specVer = args[++j];
            continue;
        }
    }
    if (args.length < 5) {
        System.out.println(// NOI18N
        "Usage: " + EjbClosureCompiler.class.getName() + // NOI18N
        " <-prefixClassPath> <prefix classpath> <-specVer> <something like ejb_2.1> <jar file name(s)>");
        return;
    }
    for (int i = 4; i < args.length; ++i) {
        try (JarFile jar = new JarFile(args[i])) {
            String cp = pcp + File.pathSeparator + ClassPathBuilder.buildClassPathForJar(jar);
            // NOI18N
            System.out.println("Using CLASSPATH " + cp);
            ClassFileLoader cfl = ClassFileLoaderFactory.newInstance(new Object[] { cp });
            EjbClosureCompiler ejbClosureCompiler = new EjbClosureCompiler(specVer, cfl);
            boolean result = ejbClosureCompiler.buildClosure(jar);
            jar.close();
            // NOI18N
            System.out.println("The closure is [\n");
            System.out.println(ejbClosureCompiler);
            if (result) {
                // NOI18N
                System.out.println("Did not find any non-standard APIs ");
            } else {
                System.out.println(// NOI18N
                "Found non-standard APIs for " + args[i]);
            }
        } catch (IOException e) {
            e.printStackTrace();
            continue;
        }
        // NOI18N
        System.out.println("\n]");
    }
// args[i]
}
Also used : ClassFileLoader(com.sun.enterprise.tools.verifier.apiscan.classfile.ClassFileLoader) ConsoleHandler(java.util.logging.ConsoleHandler) Handler(java.util.logging.Handler) IOException(java.io.IOException) JarFile(java.util.jar.JarFile) ConsoleHandler(java.util.logging.ConsoleHandler)

Example 54 with ConsoleHandler

use of java.util.logging.ConsoleHandler in project Payara by payara.

the class LoggingAnnotationsTest method initializeLoggingAnnotationsTest.

@BeforeClass
public static void initializeLoggingAnnotationsTest() throws Exception {
    File basePath = new File(BASE_PATH);
    basePath.mkdirs();
    // Add a file handler with UniformLogFormatter
    uniformFormatHandler = new FileHandler(ULF_LOG);
    uniformFormatHandler.setLevel(Level.FINE);
    uniformFormatHandler.setFormatter(new UniformLogFormatter());
    // Add a file handler with ODLLogFormatter
    odlFormatHandler = new FileHandler(ODL_LOG);
    odlFormatHandler.setLevel(Level.FINE);
    odlFormatHandler.setFormatter(new ODLLogFormatter());
    consoleHandler = new ConsoleHandler();
    consoleHandler.setFormatter(new UniformLogFormatter());
    LOGGER.addHandler(uniformFormatHandler);
    LOGGER.addHandler(odlFormatHandler);
    Boolean enableConsoleHandler = Boolean.getBoolean(LoggingAnnotationsTest.class.getName() + ".enableConsoleHandler");
    if (enableConsoleHandler) {
        LOGGER.addHandler(consoleHandler);
    }
    LOGGER.setUseParentHandlers(false);
    LOGGER.setLevel(Level.FINE);
}
Also used : File(java.io.File) ConsoleHandler(java.util.logging.ConsoleHandler) FileHandler(java.util.logging.FileHandler) BeforeClass(org.junit.BeforeClass)

Aggregations

ConsoleHandler (java.util.logging.ConsoleHandler)54 Handler (java.util.logging.Handler)23 Logger (java.util.logging.Logger)17 LogRecord (java.util.logging.LogRecord)13 Properties (java.util.Properties)12 IOException (java.io.IOException)7 FileHandler (java.util.logging.FileHandler)6 File (java.io.File)5 PrintStream (java.io.PrintStream)5 ByteArrayOutputStream (java.io.ByteArrayOutputStream)4 SimpleFormatter (java.util.logging.SimpleFormatter)4 ArrayList (java.util.ArrayList)2 JarFile (java.util.jar.JarFile)2 Formatter (java.util.logging.Formatter)2 Level (java.util.logging.Level)2 CommandCenterLogic (alma.acs.commandcenter.app.CommandCenterLogic)1 StartupOptions (alma.acs.commandcenter.app.CommandCenterLogic.StartupOptions)1 JmeFormatter (com.jme3.util.JmeFormatter)1 ClassFileLoader (com.sun.enterprise.tools.verifier.apiscan.classfile.ClassFileLoader)1 RcvrExceptionHandler (edu.cmu.cs.hcii.cogtool.ui.RcvrExceptionHandler)1