Java Code Examples for java.util.logging.Logger.setUseParentHandlers()

The following are Jave code examples for showing how to use setUseParentHandlers() of the java.util.logging.Logger class. You can vote up the examples you like. Your votes will be used in our system to get more good examples.
Example 1
Project: incubator-netbeans   File: Installer.java   Source Code and License Vote up 6 votes
@Override
public void preferenceChange(PreferenceChangeEvent evt) {
    if (corePref.equals(evt.getNode()) && USAGE_STATISTICS_ENABLED.equals(evt.getKey())) {
        boolean newVal = Boolean.parseBoolean(evt.getNewValue());
        if (newVal != logMetricsEnabled) {
            corePref.putBoolean(USAGE_STATISTICS_SET_BY_IDE, true);
            logMetricsEnabled = newVal;
            Logger log = Logger.getLogger(METRICS_LOGGER_NAME);
            if (logMetricsEnabled) {
                log.setUseParentHandlers(true);
                log.setLevel(Level.FINEST);
                log.addHandler(metrics);
                MetricsHandler.setFlushOnRecord(false);
            } else {
                MetricsHandler.flushImmediatelly();
                closeLogStreamMetrics();
                log.removeHandler(metrics);
            }
        }
    }
}
 
Example 2
Project: incubator-netbeans   File: ScanMonitor.java   Source Code and License Vote up 6 votes
private ScanMonitor() {
    Logger logger = Logger.getLogger("org.netbeans.modules.java.source.usages.RepositoryUpdater.activity"); //NOI18N
    logger.setLevel(Level.FINEST);
    logger.setUseParentHandlers(false);
    logger.addHandler( new Handler() { //NOI18N

        @Override
        public void publish(LogRecord record) {
            if( Level.FINEST.equals( record.getLevel() )
                    && "START".equals(record.getMessage()) ) { //NOI18N
                lock();
                return;
            }

            if( Level.FINEST.equals( record.getLevel() )
                    && "FINISHED".equals(record.getMessage()) ) { //NOI18N
                unlock();
                return;
            }
        }

        @Override
        public void flush() {
        }

        @Override
        public void close() throws SecurityException {
        }
    });
}
 
Example 3
Project: JInsight   File: TracingMetricRegistry.java   Source Code and License Vote up 6 votes
private static Logger createMetricUpdateTracer() {
  Logger logger = Logger.getLogger(TracingMetricRegistry.class.getName() + ".metricUpdates");
  ConsoleHandler handler = new ConsoleHandler();
  handler.setFormatter(new Formatter() {
    @Override
    public String format(LogRecord record) {
      return ">>" + record.getMessage() + "\n";
    }
  });
  logger.addHandler(handler);
  logger.setUseParentHandlers(false);
  handler.setLevel(Level.ALL);
  //logger.setLevel(Level.ALL);

  return logger;
}
 
Example 4
Project: incubator-netbeans   File: StampsTest.java   Source Code and License Vote up 5 votes
@Override
protected void setUp() throws Exception {
    branding = NbBundle.getBranding();
    locale = Locale.getDefault();
    
    clearWorkDir();
    
    install = new File(getWorkDir(), "install");
    platform = new File(install, "platform");
    ide = createIdeCluster(install);
    userdir = new File(getWorkDir(), "tmp");
    
    System.setProperty("netbeans.home", platform.getPath());
    System.setProperty("netbeans.dirs", ide.getPath());
    System.setProperty("netbeans.user", userdir.getPath());
    
    createModule("org.openide.awt", platform, 50000L);
    createModule("org.openide.nodes", platform, 60000L);
    createModule("org.netbeans.api.languages", ide, 90000L);
    createModule("org.netbeans.modules.logmanagement", userdir, 10000L);
    
    reset();
    
    Thread.sleep(100);

    Logger l = Logger.getLogger("org");
    l.setLevel(Level.OFF);
    l.setUseParentHandlers(false);
}
 
Example 5
Project: incubator-netbeans   File: StampsNoFallbackTest.java   Source Code and License Vote up 5 votes
@Override
protected void setUp() throws Exception {
    branding = NbBundle.getBranding();
    locale = Locale.getDefault();
    
    clearWorkDir();
    
    install = new File(getWorkDir(), "install");
    platform = new File(install, "platform");
    ide = new File(install, "ide");
    userdir = new File(getWorkDir(), "tmp");
    
    System.setProperty("netbeans.home", platform.getPath());
    System.setProperty("netbeans.dirs", ide.getPath());
    System.setProperty("netbeans.user", userdir.getPath());
    
    createModule("org.openide.awt", platform, 50000L);
    createModule("org.openide.nodes", platform, 60000L);
    createModule("org.netbeans.api.languages", ide, 90000L);
    createModule("org.netbeans.modules.logmanagement", userdir, 10000L);
    
    Thread.sleep(100);
    
    createPopulateZip();

    Logger l = Logger.getLogger("org");
    l.setLevel(Level.OFF);
    l.setUseParentHandlers(false);
}
 
Example 6
Project: incubator-netbeans   File: StampsIdeLessThanPlatformTest.java   Source Code and License Vote up 5 votes
@Override
protected void setUp() throws Exception {
    clearWorkDir();
    
    install = new File(getWorkDir(), "install");
    platform = new File(install, "platform");
    nonexist = new File(install, "nonexist7");
    ide = new File(install, "ide");
    userdir = new File(getWorkDir(), "tmp");
    
    System.setProperty("netbeans.home", platform.getPath());
    System.setProperty("netbeans.dirs", ide.getPath() + File.pathSeparator + nonexist.getPath());
    PlacesTestUtils.setUserDirectory(userdir);
    
    StampsTest.createModule("org.openide.awt", platform, 50000L);
    StampsTest.createModule("org.openide.nodes", platform, 60000L);
    StampsTest.createModule("org.netbeans.api.languages", ide, 50000L);
    StampsTest.createModule("org.netbeans.modules.logmanagement", userdir, 10000L);
    
    Stamps.main("reset");
    
    Thread.sleep(100);

    Logger l = Logger.getLogger("org");
    l.setLevel(Level.OFF);
    l.setUseParentHandlers(false);
}
 
Example 7
Project: bibliome-java-utils   File: LogBuilder.java   Source Code and License Vote up 5 votes
public Logger getLogger() throws IOException {
	Logger logger = Logger.getLogger("qsync");
	logger.setUseParentHandlers(false);
	Handler handler = new FlushedStreamHandler(System.err, LogFormatter.INSTANCE);
	logger.addHandler(handler);
	if (logFile != null) {
		Handler fileHandler = new FileHandler(logFile);
		logger.addHandler(fileHandler);
	}
	return logger;
}
 
Example 8
Project: incubator-netbeans   File: StampsDifferentPopulateTest.java   Source Code and License Vote up 5 votes
@Override
protected void setUp() throws Exception {
    branding = NbBundle.getBranding();
    locale = Locale.getDefault();
    
    clearWorkDir();
    
    install = new File(getWorkDir(), "install");
    platform = new File(install, "platform");
    ide = new File(install, "ide");
    userdir = new File(getWorkDir(), "tmp");
    cache = new File(install, "cache");
    
    System.setProperty("netbeans.home", platform.getPath());
    System.setProperty("netbeans.dirs", ide.getPath());
    System.setProperty("netbeans.user", userdir.getPath());
    
    createModule("org.openide.awt", platform, 50000L);
    createModule("org.openide.nodes", platform, 60000L);
    createModule("org.netbeans.api.languages", ide, 90000L);
    createModule("org.netbeans.modules.logmanagement", userdir, 10000L);
    
    Thread.sleep(100);
    
    createPopulateZip();

    Logger l = Logger.getLogger("org");
    l.setLevel(Level.OFF);
    l.setUseParentHandlers(false);
}
 
Example 9
Project: incubator-netbeans   File: StampsPopulateTest.java   Source Code and License Vote up 5 votes
@Override
protected void setUp() throws Exception {
    branding = NbBundle.getBranding();
    locale = Locale.getDefault();
    
    clearWorkDir();
    
    install = new File(getWorkDir(), "install");
    platform = new File(install, "platform");
    ide = new File(install, "ide");
    userdir = new File(getWorkDir(), "tmp");
    
    System.setProperty("netbeans.home", platform.getPath());
    System.setProperty("netbeans.dirs", ide.getPath());
    System.setProperty("netbeans.user", userdir.getPath());
    
    createModule("org.openide.awt", platform, 50000L);
    createModule("org.openide.nodes", platform, 60000L);
    createModule("org.netbeans.api.languages", ide, 90000L);
    createModule("org.netbeans.modules.logmanagement", userdir, 10000L);
    
    Thread.sleep(100);
    
    createPopulateZip();

    Logger l = Logger.getLogger("org");
    l.setLevel(Level.OFF);
    l.setUseParentHandlers(false);
}
 
Example 10
Project: incubator-netbeans   File: Install.java   Source Code and License Vote up 5 votes
public @Override void restored() {
    if (!ENABLED) {
        return ;
    }
    
    Logger log = Logger.getLogger("TIMER"); // NOI18N
    log.setUseParentHandlers(false);
    log.setLevel(Level.FINE);
    log.addHandler(timers);
    
    EditorRegistry.addPropertyChangeListener(docTracker);
}
 
Example 11
Project: ios-device-control   File: FluentLogger.java   Source Code and License Vote up 5 votes
/** Returns a generic fluent logger for a class. */
public static FluentLogger forEnclosingClass() {
  StackTraceElement caller = new Throwable().getStackTrace()[1];
  Logger logger = Logger.getLogger(caller.getClassName());
  logger.setUseParentHandlers(false);
  logger.addHandler(new ConsoleHandler());
  return new FluentLogger(logger, Level.OFF, Optional.empty());
}
 
Example 12
Project: ProjectAres   File: HttpClient.java   Source Code and License Vote up 5 votes
@Inject HttpClient(Loggers loggers, HttpClientConfiguration config, JsonUtils jsonUtils, Gson gson) {
    this.logger = loggers.get(getClass());
    this.config = checkNotNull(config, "config");
    this.jsonUtils = jsonUtils;
    this.gson = gson;
    ThreadFactory threadFactory = new ThreadFactoryBuilder().setNameFormat("API HTTP Executor").build();
    if (config.getThreads() > 0) {
        this.executorService = MoreExecutors.listeningDecorator(Executors.newFixedThreadPool(config.getThreads()));
    } else {
        this.executorService = MoreExecutors.listeningDecorator(Executors.newCachedThreadPool(threadFactory));
    }

    this.requestFactory = this.createRequestFactory();

    // By default the google http client is very noisy on http errors,
    // spitting out a long stack trace every time one try of a request
    // fails. Disabling the parent handlers (removes default console
    // handling) and adding our own handler that will only show the short
    // message makes the error output much more manageable.
    // See HttpRequest#986 for the offending line and HttpTransport#81 for
    // the logger definition (it's package private so we can't access it
    // directly).
    final Logger httpLogger = Logger.getLogger(HttpTransport.class.getName());
    httpLogger.setUseParentHandlers(false);
    httpLogger.addHandler(new ConsoleHandler() {
        @Override
        public void publish(LogRecord record) {
            String message = record.getMessage();
            if (record.getThrown() != null) message += ": " + record.getThrown().toString();
            HttpClient.this.logger.log(record.getLevel(), message);
        }
    });
}
 
Example 13
Project: BrainControl   File: Logging.java   Source Code and License Vote up 5 votes
/**
 * Deactivates console output for a given logger.
 * 
 * @param loggerName
 */
public static void deactivateConsoleOutput(String loggerName) {
	if (loggerName != null) {
		Logger logger = loggers.get(loggerName);
		if (logger != null) {
			logger.setUseParentHandlers(false);
		}
	}
}
 
Example 14
Project: BrainControl   File: Logging.java   Source Code and License Vote up 5 votes
/**
 * Activates console output for a given logger.
 * 
 * @param loggerName
 */
public static void activateConsoleOutput(String loggerName) {
	if (loggerName != null) {
		Logger logger = loggers.get(loggerName);
		if (logger != null) {
			logger.setUseParentHandlers(true);
		}
	}
}
 
Example 15
Project: alvisnlp   File: AbstractAlvisNLP.java   Source Code and License Vote up 5 votes
protected Logger getLogger(C ctx) throws FileNotFoundException, IOException {
	Logger result = ctx.getLogger("alvisnlp");
	result.setLevel(logLevel);
    result.setUseParentHandlers(false);
	setHandlers(result, logFile);
	for (Map.Entry<String,File> e : logFiles.entrySet()) {
    	Logger logger = ctx.getLogger("alvisnlp." + e.getKey());
    	logger.setLevel(logLevel);
    	setHandlers(logger, e.getValue());
    }
    return result;
}
 
Example 16
Project: alvisnlp   File: Run.java   Source Code and License Vote up 5 votes
public Logger getLogger(ProcessingContext<Corpus> processingContext) throws FileNotFoundException {
	Logger result = processingContext.getLogger("alvisnlp");
	result.setLevel(Level.INFO);
    result.setUseParentHandlers(false);
	setHandlers(result, Level.INFO);
    return result;
}
 
Example 17
Project: openjdk-jdk10   File: TestAnonymousLogger.java   Source Code and License Vote up 5 votes
public static void main(String[] args) {
    System.setSecurityManager(new SecurityManager());
    Logger anonymous = Logger.getAnonymousLogger();

    final TestHandler handler = new TestHandler();
    final TestFilter filter = new TestFilter();
    final ResourceBundle bundle = ResourceBundle.getBundle(TestBundle.class.getName());
    anonymous.setLevel(Level.FINEST);
    anonymous.addHandler(handler);
    anonymous.setFilter(filter);
    anonymous.setUseParentHandlers(true);
    anonymous.setResourceBundle(bundle);

    if (anonymous.getLevel() != Level.FINEST) {
        throw new RuntimeException("Unexpected level: " + anonymous.getLevel());
    } else {
        System.out.println("Got expected level: " + anonymous.getLevel());
    }
    if (!Arrays.asList(anonymous.getHandlers()).contains(handler)) {
        throw new RuntimeException("Expected handler not found in: "
                + Arrays.asList(anonymous.getHandlers()));
    } else {
        System.out.println("Got expected handler in: " + Arrays.asList(anonymous.getHandlers()));
    }
    if (anonymous.getFilter() != filter) {
        throw new RuntimeException("Unexpected filter: " + anonymous.getFilter());
    } else {
        System.out.println("Got expected filter: " + anonymous.getFilter());
    }
    if (!anonymous.getUseParentHandlers()) {
        throw new RuntimeException("Unexpected flag: " + anonymous.getUseParentHandlers());
    } else {
        System.out.println("Got expected flag: " + anonymous.getUseParentHandlers());
    }
    if (anonymous.getResourceBundle() != bundle) {
        throw new RuntimeException("Unexpected bundle: " + anonymous.getResourceBundle());
    } else {
        System.out.println("Got expected bundle: " + anonymous.getResourceBundle());
    }
    try {
        anonymous.setParent(Logger.getLogger("foo.bar"));
        throw new RuntimeException("Expected SecurityException not raised!");
    } catch (SecurityException x) {
        System.out.println("Got expected exception: " + x);
    }
    if (anonymous.getParent() != Logger.getLogger("")) {
        throw new RuntimeException("Unexpected parent: " + anonymous.getParent());
    } else {
        System.out.println("Got expected parent: " + anonymous.getParent());
    }
}
 
Example 18
Project: SlideBar   File: MainBack.java   Source Code and License Vote up 5 votes
public static HttpServer startRestServer() {
    BeanConfig beanConfig = new BeanConfig();
    beanConfig.setVersion("1.0.0");
    beanConfig.setTitle("SlideBar REST Interface");
    beanConfig.setResourcePackage(RootResource.class.getPackage().getName());
    beanConfig.setSchemes(new String[] { "http" });
    beanConfig.setHost("localhost:5055");
    beanConfig.setScan(true);

    final ResourceConfig rc = new ResourceConfig();
    rc.packages(RootResource.class.getPackage().getName());
    rc.register(LoggingFeature.class);
    rc.register(JacksonFeature.class);
    rc.register(ApiListingResource.class);
    rc.register(SwaggerSerializers.class);
    rc.property(ServerProperties.WADL_FEATURE_DISABLE, true);

    Logger l = Logger.getLogger("org.glassfish.grizzly.http.server.HttpHandler");
    l.setLevel(Level.FINE);
    l.setUseParentHandlers(false);
    ConsoleHandler ch = new ConsoleHandler();
    ch.setLevel(Level.ALL);
    l.addHandler(ch);

    try {
        return GrizzlyHttpServerFactory.createHttpServer(new URI("http://localhost:5055"), rc);
    } catch (URISyntaxException e) {
        e.printStackTrace();
        return null;
    }
}
 
Example 19
Project: dsp4e   File: LogMessageAccumulator.java   Source Code and License Vote up 5 votes
public void unregister() {
	for (Logger logger : registeredLoggers) {
		logger.removeHandler(this);
		logger.setUseParentHandlers(true);
	}
	registeredLoggers.clear();
}
 
Example 20
Project: incubator-netbeans   File: StampsExtraTest.java   Source Code and License Vote up 4 votes
public void testTimeStampsWhenAddingCluster() throws Exception {
    clearWorkDir();
    
    install = new File(getWorkDir(), "install");
    platform = new File(install, "platform");
    platform.mkdirs();
    ide = new File(install, "ide");
    ide.mkdirs();
    extra = new File(install, "extra");
    userdir = new File(getWorkDir(), "tmp");
    userdir.mkdirs();
    
    System.setProperty("netbeans.home", platform.getPath());
    System.setProperty("netbeans.dirs", ide.getPath() + File.pathSeparator + extra.getPath());
    PlacesTestUtils.setUserDirectory(userdir);

    touch(platform, ".lastModified", 50000L);
    touch(ide, ".lastModified", 90000L);
    assertFalse("One cluster does not exists", extra.isDirectory());
    
    Stamps.main("init");
    
    Thread.sleep(100);

    Logger l = Logger.getLogger("org");
    l.setLevel(Level.OFF);
    l.setUseParentHandlers(false);

    long stamp = Stamps.moduleJARs();
    assertEquals("Timestamp is taken from api.languages module", 90000L, stamp);

    Stamps.main("clear");

    CountingSecurityManager.initialize(install.getPath());

    long newStamp = Stamps.moduleJARs();

    CountingSecurityManager.assertCounts("Just few accesses to installation", 6);
    assertEquals("Stamps are the same", stamp, newStamp);

    assertFalse("File has not been created for non-existing cluster", Places.getCacheSubfile("lastModified/extra").canRead());

    extra.mkdirs();
    File lastModified = new File(extra, ".lastModified");
    lastModified.createNewFile();
    lastModified.setLastModified(200000L);
    assertEquals("Correct last modified", 200000L, lastModified.lastModified());

    Stamps.main("clear");
    stamp = Stamps.moduleJARs();
    if (stamp < 200000L) {
        fail("lastModified has not been updated: " + stamp);
    }
}