Search in sources :

Example 31 with Logger

use of java.util.logging.Logger in project guice by google.

the class CheckedProviderMethodsModule method createProviderMethod.

<T> CheckedProviderMethod<T> createProviderMethod(Binder binder, final Method method, CheckedProvides checkedProvides) {
    @SuppressWarnings("rawtypes") Class<? extends CheckedProvider> throwingProvider = checkedProvides.value();
    binder = binder.withSource(method);
    Errors errors = new Errors(method);
    // prepare the parameter providers
    List<Dependency<?>> dependencies = Lists.newArrayList();
    List<Provider<?>> parameterProviders = Lists.newArrayList();
    List<TypeLiteral<?>> parameterTypes = typeLiteral.getParameterTypes(method);
    Annotation[][] parameterAnnotations = method.getParameterAnnotations();
    for (int i = 0; i < parameterTypes.size(); i++) {
        Key<?> key = getKey(errors, parameterTypes.get(i), method, parameterAnnotations[i]);
        if (key.equals(LOGGER_KEY)) {
            // If it was a Logger, change the key to be unique & bind it to a
            // provider that provides a logger with a proper name.
            // This solves issue 482 (returning a new anonymous logger on every call exhausts memory)
            Key<Logger> loggerKey = Key.get(Logger.class, UniqueAnnotations.create());
            binder.bind(loggerKey).toProvider(new LogProvider(method));
            key = loggerKey;
        }
        dependencies.add(Dependency.get(key));
        parameterProviders.add(binder.getProvider(key));
    }
    // Define T as the method's return type.
    @SuppressWarnings("unchecked") TypeLiteral<T> returnType = (TypeLiteral<T>) typeLiteral.getReturnType(method);
    List<TypeLiteral<?>> exceptionTypes = typeLiteral.getExceptionTypes(method);
    Key<T> key = getKey(errors, returnType, method, method.getAnnotations());
    Class<? extends Annotation> scopeAnnotation = Annotations.findScopeAnnotation(errors, method.getAnnotations());
    for (Message message : errors.getMessages()) {
        binder.addError(message);
    }
    return new CheckedProviderMethod<T>(key, method, delegate, ImmutableSet.copyOf(dependencies), parameterProviders, scopeAnnotation, throwingProvider, exceptionTypes, checkedProvides.scopeExceptions());
}
Also used : Message(com.google.inject.spi.Message) Dependency(com.google.inject.spi.Dependency) Logger(java.util.logging.Logger) Provider(com.google.inject.Provider) Errors(com.google.inject.internal.Errors) TypeLiteral(com.google.inject.TypeLiteral)

Example 32 with Logger

use of java.util.logging.Logger in project CoreNLP by stanfordnlp.

the class JavaUtilLoggingHandler method print.

@Override
public void print(Object[] channel, String line) {
    // Parse the channels
    Pair<String, Redwood.Flag> pair = getSourceStringAndLevel(channel);
    // Get the logger
    Logger impl = Logger.getLogger(pair.first());
    // Route the signal
    switch(pair.second()) {
        case ERROR:
            impl.log(Level.SEVERE, line);
            break;
        case WARN:
            impl.log(Level.WARNING, line);
            break;
        case DEBUG:
            impl.log(Level.FINE, line);
            break;
        case STDOUT:
        case STDERR:
            impl.info(line);
            break;
        case FORCE:
            throw new IllegalStateException("Should not reach this switch case");
    }
}
Also used : Logger(java.util.logging.Logger)

Example 33 with Logger

use of java.util.logging.Logger in project roboguice by roboguice.

the class ProviderMethodsModule method createProviderMethod.

private <T> ProviderMethod<T> createProviderMethod(Binder binder, Method method) {
    binder = binder.withSource(method);
    Errors errors = new Errors(method);
    // prepare the parameter providers
    List<Dependency<?>> dependencies = Lists.newArrayList();
    List<Provider<?>> parameterProviders = Lists.newArrayList();
    List<TypeLiteral<?>> parameterTypes = typeLiteral.getParameterTypes(method);
    Annotation[][] parameterAnnotations = method.getParameterAnnotations();
    for (int i = 0; i < parameterTypes.size(); i++) {
        Key<?> key = getKey(errors, parameterTypes.get(i), method, parameterAnnotations[i]);
        if (key.equals(LOGGER_KEY)) {
            // If it was a Logger, change the key to be unique & bind it to a
            // provider that provides a logger with a proper name.
            // This solves issue 482 (returning a new anonymous logger on every call exhausts memory)
            Key<Logger> loggerKey = Key.get(Logger.class, UniqueAnnotations.create());
            binder.bind(loggerKey).toProvider(new LogProvider(method));
            key = loggerKey;
        }
        dependencies.add(Dependency.get(key));
        parameterProviders.add(binder.getProvider(key));
    }
    // Define T as the method's return type.
    @SuppressWarnings("unchecked") TypeLiteral<T> returnType = (TypeLiteral<T>) typeLiteral.getReturnType(method);
    Key<T> key = getKey(errors, returnType, method, method.getAnnotations());
    Class<? extends Annotation> scopeAnnotation = Annotations.findScopeAnnotation(errors, method.getAnnotations());
    for (Message message : errors.getMessages()) {
        binder.addError(message);
    }
    return ProviderMethod.create(key, method, delegate, ImmutableSet.copyOf(dependencies), parameterProviders, scopeAnnotation, skipFastClassGeneration);
}
Also used : Message(com.google.inject.spi.Message) Dependency(com.google.inject.spi.Dependency) Logger(java.util.logging.Logger) Provider(com.google.inject.Provider) TypeLiteral(com.google.inject.TypeLiteral)

Example 34 with Logger

use of java.util.logging.Logger in project bazel by bazelbuild.

the class PackageFactoryTest method testCreatePackageIsolatedFromOuterErrors.

@Test
public void testCreatePackageIsolatedFromOuterErrors() throws Exception {
    ExecutorService e = Executors.newCachedThreadPool();
    final Semaphore beforeError = new Semaphore(0);
    final Semaphore afterError = new Semaphore(0);
    Reporter reporter = new Reporter(new EventBus());
    ParsingTracker parser = new ParsingTracker(beforeError, afterError, reporter);
    final Logger log = Logger.getLogger(PackageFactory.class.getName());
    log.addHandler(parser);
    Level originalLevel = log.getLevel();
    log.setLevel(Level.FINE);
    e.execute(new ErrorReporter(reporter, beforeError, afterError));
    e.execute(parser);
    // wait for all to finish
    e.shutdown();
    assertTrue(e.awaitTermination(TestUtils.WAIT_TIMEOUT_MILLISECONDS, TimeUnit.MILLISECONDS));
    log.removeHandler(parser);
    log.setLevel(originalLevel);
    assertTrue(parser.hasParsed());
}
Also used : Reporter(com.google.devtools.build.lib.events.Reporter) ExecutorService(java.util.concurrent.ExecutorService) Level(java.util.logging.Level) Semaphore(java.util.concurrent.Semaphore) EventBus(com.google.common.eventbus.EventBus) Logger(java.util.logging.Logger) Test(org.junit.Test)

Example 35 with Logger

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

the class LoggerTest method testGetLogger_Empty.

/*
	 * Test getLogger(String) with empty name.
	 */
public void testGetLogger_Empty() {
    assertNotNull(LogManager.getLogManager().getLogger(""));
    Logger log = Logger.getLogger("");
    assertSame(log, LogManager.getLogManager().getLogger(""));
    assertNull(log.getFilter());
    assertEquals(0, log.getHandlers().length);
    // check it's set to the preconfigured level
    assertSame(Level.INFO, log.getLevel());
    assertEquals("", log.getName());
    assertNull(log.getParent());
    assertNull(log.getResourceBundle());
    assertNull(log.getResourceBundleName());
    assertTrue(log.getUseParentHandlers());
}
Also used : Logger(java.util.logging.Logger)

Aggregations

Logger (java.util.logging.Logger)499 Test (org.junit.Test)70 LogRecord (java.util.logging.LogRecord)60 ActionReport (org.glassfish.api.ActionReport)56 Handler (java.util.logging.Handler)52 IOException (java.io.IOException)37 File (java.io.File)36 Level (java.util.logging.Level)25 ArrayList (java.util.ArrayList)22 ConsoleHandler (java.util.logging.ConsoleHandler)19 Properties (java.util.Properties)15 SimpleFormatter (java.util.logging.SimpleFormatter)15 Config (com.sun.enterprise.config.serverbeans.Config)14 HashMap (java.util.HashMap)14 Map (java.util.Map)12 ByteArrayOutputStream (java.io.ByteArrayOutputStream)11 ResourceBundle (java.util.ResourceBundle)11 LogManager (java.util.logging.LogManager)11 ExtendedDeploymentContext (org.glassfish.internal.deployment.ExtendedDeploymentContext)11 BlockingQueueHandler (fish.payara.nucleus.notification.BlockingQueueHandler)10