Search in sources :

Example 6 with Filter

use of java.util.logging.Filter 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 7 with Filter

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

the class HandlerTest method testGetSetFilter_Normal.

/*
	 * Test getErrorManager with insufficient privilege.
	 *
	public void testGetErrorManager_InsufficientPrivilege() throws Exception {
		MockHandler h = new MockHandler();
		SecurityManager oldMan = System.getSecurityManager();
		System.setSecurityManager(new MockSecurityManager());

		try {
			h.getErrorManager();
			fail("Should throw SecurityException!");
		} catch (SecurityException e) {
		} finally {
			System.setSecurityManager(oldMan);
		}
	}

	/*
	 * Test setErrorManager with insufficient privilege.
	 *
	public void testSetErrorManager_InsufficientPrivilege() throws Exception {
		MockHandler h = new MockHandler();
		SecurityManager oldMan = System.getSecurityManager();
		System.setSecurityManager(new MockSecurityManager());

		// set null
		try {

			h.setErrorManager(null);
			fail("Should throw SecurityException!");
		} catch (SecurityException e) {
		} finally {
			System.setSecurityManager(oldMan);
		}
		// set a normal value
		System.setSecurityManager(new MockSecurityManager());
		try {

			h.setErrorManager(new ErrorManager());
			fail("Should throw SecurityException!");
		} catch (SecurityException e) {
		} finally {
			System.setSecurityManager(oldMan);
		}
	}
	*/
/*
	 * Test getFilter & setFilter methods with non-null value.
	 */
public void testGetSetFilter_Normal() throws Exception {
    MockHandler h = new MockHandler();
    Filter f = new MockFilter();
    h.setFilter(f);
    assertSame(f, h.getFilter());
}
Also used : Filter(java.util.logging.Filter)

Example 8 with Filter

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

the class LoggerTest method testSetFilter_AnonyLoggerSufficientPrivilege.

/*
	 * Test setFilter with normal value for a named logger, having insufficient
	 * privilege.
	 *
	public void testGetSetFilter_NamedLoggerInsufficientPrivilege() {
		Logger log = Logger
				.getLogger("testGetSetFilter_NamedLoggerInsufficientPrivilege");
		Filter f = new MockFilter();
		SecurityManager oldMan = System.getSecurityManager();
		System.setSecurityManager(new MockSecurityManager());
		try {
			log.setFilter(f);
			fail("Should throw SecurityException!");
		} catch (SecurityException e) {
		} finally {
			System.setSecurityManager(oldMan);
		}
	}

	/*
	 * Test setFilter for an anonymous logger with sufficient privilege.
	 */
public void testSetFilter_AnonyLoggerSufficientPrivilege() {
    Logger log = Logger.getAnonymousLogger();
    Filter f = new MockFilter();
    assertNull(log.getFilter());
    log.setFilter(f);
    assertSame(f, log.getFilter());
}
Also used : Filter(java.util.logging.Filter) Logger(java.util.logging.Logger)

Example 9 with Filter

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

the class MemoryHandlerTest method testClose.

/*
	public void testSecurity() {
		SecurityManager currentManager = System.getSecurityManager();
		System.setSecurityManager(securityManager);
		try {
			try {
				handler.close();
				fail("should throw security exception");
			} catch (SecurityException e) {
			}
			try {
				handler.setPushLevel(Level.CONFIG);
				fail("should throw security exception");
			} catch (SecurityException e) {
			}
			handler.flush();
			handler.push();
			handler.getPushLevel();
			handler.isLoggable(new LogRecord(Level.ALL, "message"));
			handler.publish(new LogRecord(Level.ALL, "message"));
		} finally {
			System.setSecurityManager(currentManager);
		}

	}
	*/
public void testClose() {
    Filter filter = handler.getFilter();
    Formatter formatter = handler.getFormatter();
    writer.getBuffer().setLength(0);
    handler.close();
    assertEquals(writer.toString(), "close");
    assertEquals(handler.getFilter(), filter);
    assertEquals(handler.getFormatter(), formatter);
    assertNull(handler.getEncoding());
    assertNotNull(handler.getErrorManager());
    assertEquals(handler.getLevel(), Level.OFF);
    assertEquals(handler.getPushLevel(), Level.WARNING);
    assertFalse(handler.isLoggable(new LogRecord(Level.SEVERE, "test")));
}
Also used : Filter(java.util.logging.Filter) LogRecord(java.util.logging.LogRecord) SimpleFormatter(java.util.logging.SimpleFormatter) Formatter(java.util.logging.Formatter)

Example 10 with Filter

use of java.util.logging.Filter in project ACS by ACS-Community.

the class AcsLogger method configureLogging.

/**
     * Callback method, configures this logger from the data in logConfig.
     * @see alma.acs.logging.config.LogConfigSubscriber#configureLogging(alma.acs.logging.config.LogConfig)
     */
public void configureLogging(LogConfig newLogConfig) {
    if (newLogConfig == null) {
        throw new IllegalArgumentException("newLogConfig must not be null");
    }
    logConfig = newLogConfig;
    try {
        UnnamedLogger config = logConfig.getNamedLoggerConfig(getLoggerName());
        if (DEBUG) {
            System.out.println("*** AcsLogger#configureLogging: name=" + getLoggerName() + " minLevel=" + config.getMinLogLevel() + " minLevelLocal=" + config.getMinLogLevelLocal());
        }
        configureLevels(config);
    } catch (Exception e) {
        log(Level.INFO, "Failed to configure logger.", e);
    }
    // forward log level to optional JacORB filter
    // Perhaps this dependency is too dirty, then we need a more general
    // filter registration mechanism parallel to what the JDK foresees.
    Filter logFilter = getFilter();
    if (logFilter != null && logFilter instanceof JacORBFilter) {
        ((JacORBFilter) logFilter).setLogLevel(getLevel());
    }
}
Also used : UnnamedLogger(alma.maci.loggingconfig.UnnamedLogger) JacORBFilter(alma.acs.logging.adapters.JacORBFilter) Filter(java.util.logging.Filter) JacORBFilter(alma.acs.logging.adapters.JacORBFilter)

Aggregations

Filter (java.util.logging.Filter)12 Formatter (java.util.logging.Formatter)4 LogRecord (java.util.logging.LogRecord)4 Logger (java.util.logging.Logger)4 File (java.io.File)2 IOException (java.io.IOException)2 Level (java.util.logging.Level)2 SimpleFormatter (java.util.logging.SimpleFormatter)2 JacORBFilter (alma.acs.logging.adapters.JacORBFilter)1 UnnamedLogger (alma.maci.loggingconfig.UnnamedLogger)1 SSOException (com.iplanet.sso.SSOException)1 ServerTlsHandler (io.grpc.netty.ProtocolNegotiators.ServerTlsHandler)1 ChannelHandler (io.netty.channel.ChannelHandler)1 SupportedCipherSuiteFilter (io.netty.handler.ssl.SupportedCipherSuiteFilter)1 FilenameFilter (java.io.FilenameFilter)1 UnsupportedEncodingException (java.io.UnsupportedEncodingException)1 Constructor (java.lang.reflect.Constructor)1 MissingResourceException (java.util.MissingResourceException)1 ConsoleHandler (java.util.logging.ConsoleHandler)1 ErrorManager (java.util.logging.ErrorManager)1