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

The following are Jave code examples for showing how to use getLogger() 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.
+ Save this method
Example 1
Project: incubator-netbeans   File: CslTestBase.java   View Source Code Vote up 6 votes
@Override
protected void tearDown() throws Exception {
    if (classPathsForTest != null && !classPathsForTest.isEmpty()) {
        Logger logger = Logger.getLogger(RepositoryUpdater.class.getName() + ".tests");
        logger.setLevel(Level.FINEST);
        Waiter w = new Waiter(classPathContainsBinaries());
        logger.addHandler(w);

        for(String cpId : classPathsForTest.keySet()) {
            ClassPath cp = classPathsForTest.get(cpId);
            GlobalPathRegistry.getDefault().unregister(cpId, new ClassPath [] { cp });
        }

        w.waitForScanToFinish();
        logger.removeHandler(w);
    }

    super.tearDown();
}
 
Example 2
Project: ProjectAres   File: ClassLogger.java   View Source Code Vote up 6 votes
public static @Nullable ClassLogger find(@Nullable Logger parent, Class<?> klass, @Nullable String instanceKey) {
    if(parent == null) {
        parent = Logger.getLogger("");
    }

    String name = getName(klass, instanceKey);
    if(parent instanceof ClassLogger && Objects.equals(parent.getName(), name)) {
        // If the given parent logger looks exactly like the logger
        // we are supposed to return, just use it. This makes it easy
        // to replace a parent logger with a child once only e.g.
        //
        //     logger = ClassLogger.get(logger, getClass(), "myInstance")
        return (ClassLogger) parent;
    }

    LogManager lm = LogManager.getLogManager();
    Logger logger = lm.getLogger(name);
    if(logger instanceof ClassLogger) {
        if(parent != logger.getParent()) {
            throw new IllegalStateException("Already registred logger " + name + " has a different parent than the one requested:\n  old = " + logger.getParent() + "\n  new = " + parent);
        }
        return (ClassLogger) logger;
    } else {
        return null;
    }
}
 
Example 3
Project: openjdk-jdk10   File: TestSetResourceBundle.java   View Source Code Vote up 6 votes
/**
 * Test the LoggingPermission("control") is required.
 * @param loggerName The logger to use.
 */
public static void testPermission(String loggerName) {
    if (System.getSecurityManager() != null) {
        throw new Error("Security manager is already set");
    }
    Policy.setPolicy(new SimplePolicy(TestCase.PERMISSION));
    System.setSecurityManager(new SecurityManager());
    final ResourceBundle bundle = ResourceBundle.getBundle(LIST_BUNDLE_NAME);
    Logger foobar = Logger.getLogger(loggerName);
    try {
        foobar.setResourceBundle(bundle);
        throw new RuntimeException("Permission not checked!");
    } catch (AccessControlException x) {
        if (x.getPermission() instanceof LoggingPermission) {
            if ("control".equals(x.getPermission().getName())) {
                System.out.println("Got expected exception: " + x);
                return;
            }
        }
        throw new RuntimeException("Unexpected exception: "+x, x);
    }

}
 
Example 4
Project: openjdk-jdk10   File: ResourceBundleTest.java   View Source Code Vote up 6 votes
static void failToLoadResourceBundle(String loggerName, String rbName,
        boolean getLoggerInNamedModule, String helpMsg) {
    String msg = String.format(
            "Logger : %s. Expected exception is not thrown for ResourceBundle : %s.",
            loggerName, rbName);
    System.out.println(helpMsg);
    try {
        if(getLoggerInNamedModule) {
            ModuleLoggerAccess.getLogger(loggerName, rbName);
        } else {
            Logger.getLogger(loggerName, rbName);
        }
        throw new RuntimeException(msg);
    } catch (MissingResourceException expected) {
        System.out.println("Get expected exception : " + expected);
        return;
    }
}
 
Example 5
Project: incubator-netbeans   File: MainWindow.java   View Source Code Vote up 6 votes
private static void logLookAndFeelUsage() {
    if( lafLogged )
        return;
    lafLogged = true;
    LookAndFeel laf = UIManager.getLookAndFeel();
    Logger logger = Logger.getLogger( "org.netbeans.ui.metrics.laf" );   // NOI18N
    LogRecord rec = new LogRecord( Level.INFO, "USG_LOOK_AND_FEEL" ); //NOI18N
    String lafId = laf.getID();
    if( laf.getDefaults().getBoolean( "nb.dark.theme" ) ) //NOI18N
    {
        lafId = "DARK " + lafId; //NOI18N
    }
    rec.setParameters( new Object[]{ lafId, laf.getName() } );
    rec.setLoggerName( logger.getName() );
    logger.log( rec );
}
 
Example 6
Project: BeamTeamDiscordBot   File: ConstellationManager.java   View Source Code Vote up 6 votes
private static void handleUserFollowed(LiveEvent event, JsonObject payload) {
	try {
		if (Files.notExists(Paths.get("payloads\\"))) {
			new File("payloads\\").mkdir();
		}

		Logger logger = Logger.getLogger("payload-userFollowed");
		FileHandler fh = new FileHandler("payloads\\" + logger.getName() + ".json");
		SimpleFormatter formatter = new SimpleFormatter();
		fh.setFormatter(formatter);

		logger.addHandler(fh);

		logger.log(Level.INFO, payload.toString());
	} catch (SecurityException | IOException e) {}
}
 
Example 7
Project: jdk8u-jdk   File: ResourceBundleSearchTest.java   View Source Code Vote up 6 votes
public void run() {
    boolean setTCCL = false;
    try {
        if (clToSetOnTCCL != null) {
            Thread.currentThread().setContextClassLoader(clToSetOnTCCL);
            setTCCL = true;
        }
        // this should succeed if the bundle is on the system classpath.
        try {
            Logger aLogger = Logger.getLogger(ResourceBundleSearchTest.newLoggerName(),
                                              bundleName);
            msg = "INFO: LoggingThread.run() found the bundle " + bundleName
                  + (setTCCL ? " with " : " without ") + "setting the TCCL";
            foundBundle = true;
        } catch (MissingResourceException re) {
            msg = "INFO: LoggingThread.run() did not find the bundle " + bundleName
                  + (setTCCL ? " with " : " without ") + "setting the TCCL";
            foundBundle = false;
        }
    } catch (Throwable e) {
        e.printStackTrace();
        System.exit(1);
    }
}
 
Example 8
Project: incubator-netbeans   File: NoLockWhenRefreshIOTest.java   View Source Code Vote up 6 votes
@Override
protected void setUp() throws Exception {
    LOG = Logger.getLogger("test." + getName());
    try {
        clearWorkDir();
    } catch (IOException ex) {
        LOG.log(Level.WARNING, "Cannot clear work dir for some reason", ex);
    }
    
    File dir = new File(getWorkDir(), "dir");
    dir.mkdir();
    
    for (int i = 0; i < 100; i++) {
        new File(dir, "x" + i + ".txt").createNewFile();
        new File(dir, "d" + i).mkdir();
    }
    
    assertEquals("Two hundred", 200, dir.list().length);
}
 
Example 9
Project: incubator-netbeans   File: RepositoryUpdaterTest.java   View Source Code Vote up 6 votes
@Override
protected void tearDown() throws Exception {
    final TestHandler handler = new TestHandler();
    final Logger logger = Logger.getLogger(RepositoryUpdater.class.getName()+".tests");
    try {
        logger.setLevel (Level.FINEST);
        logger.addHandler(handler);
        for(String id : registeredClasspaths.keySet()) {
            final Map<ClassPath,Void> classpaths = registeredClasspaths.get(id);
            GlobalPathRegistry.getDefault().unregister(id, classpaths.keySet().toArray(new ClassPath[classpaths.size()]));
        }
        handler.await();
    } finally {
        logger.removeHandler(handler);
    }
    super.tearDown();
}
 
Example 10
Project: incubator-netbeans   File: XMLMIMEComponent.java   View Source Code Vote up 6 votes
public void fatalError(SAXParseException exception) throws SAXException {
    if (exception.getMessage().contains("Invalid encoding")) { // NOI18N
        // ok, go on, we want to continue parsing anyway
        return;
    }
    
    // it may be caused by wrong user XML documents, notify only in debug mode
    // also see #16484 if the error message makes no sense
    Logger emgr = Logger.getLogger(XMLMIMEComponent.class.getName());
    if (emgr.isLoggable(Level.FINE)) {
        emgr.fine("[while parsing " + fo + "] " + exception.getSystemId() + ":" + exception.getLineNumber() + ":" + exception.getColumnNumber() + ": " + exception.getMessage()); // NOI18N
    }
    
    // go on anyway, needed to fix 203959
    if (errors++ > 10) {
        state = ERROR;
        throw STOP;
    }
}
 
Example 11
Project: openjdk-jdk10   File: TestLogger.java   View Source Code Vote up 5 votes
public TestLogger(String loggerName, String className) {
    Logger l = null;
    try {
        l = Logger.getLogger(loggerName);
    } catch (Exception x) {
        // OK. Should not happen
    }
    logger = l;
    this.className=className;
}
 
Example 12
Project: jdk8u-jdk   File: DrainFindDeadlockTest.java   View Source Code Vote up 5 votes
@Override
public void run() {
    System.out.println("Running " + Thread.currentThread().getName());

    for (int i=0; i < MAX_ITERATIONS; i++) {
        logger = Logger.getLogger("DrainFindDeadlockTest"+i);
        DrainFindDeadlockTest.randomDelay();
    }
}
 
Example 13
Project: incubator-netbeans   File: OpenProjectList.java   View Source Code Vote up 5 votes
private static void log(LogRecord[] arr, String loggerName) {
    if (arr == null) {
        return;
    }
    Logger logger = Logger.getLogger(loggerName); // NOI18N
    for (LogRecord r : arr) {
        logger.log(r);
    }
}
 
Example 14
Project: incubator-netbeans   File: SlowRefreshTest.java   View Source Code Vote up 5 votes
@Override
protected void setUp() throws Exception {
    clearWorkDir();

    LOG = Logger.getLogger("test." + getName());
    Logger.getLogger("org.openide.util.Mutex").setUseParentHandlers(false);

    File dir = new File(getWorkDir(), "test");
    dir.mkdirs();
    testFolder = FileUtil.toFileObject(dir);
    assertNotNull("Test folder created", testFolder);

}
 
Example 15
Project: incubator-netbeans   File: Install.java   View Source Code 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 16
Project: openjdk-jdk10   File: FailOverExecutionControlProvider.java   View Source Code Vote up 5 votes
private Logger logger() {
    if (logger == null) {
        logger = Logger.getLogger("jdk.jshell.execution");
        if (logger.getLevel() == null) {
            // Logging has not been specifically requested, turn it off
            logger.setLevel(Level.OFF);
        }
    }
    return logger;
}
 
Example 17
Project: incubator-netbeans   File: ChildFactoryTest.java   View Source Code Vote up 4 votes
public ChildFactoryTest(String name) {
    super(name);
    LOG = Logger.getLogger(ChildFactoryTest.class.getName() + name);
}
 
Example 18
Project: incubator-netbeans   File: TaskListTopComponent.java   View Source Code Vote up 4 votes
static private Logger getLogger() {
    return Logger.getLogger( TaskListTopComponent.class.getName() );
}
 
Example 19
Project: openjdk-jdk10   File: ClassLoaderLeakTest.java   View Source Code Vote up 4 votes
public void launch(CountDownLatch done) {
    Logger log = Logger.getLogger("app_test_logger");
    log.fine("Test app is launched");

    done.countDown();
}
 
Example 20
Project: googles-monorepo-demo   File: EventBus.java   View Source Code Vote up 4 votes
private static Logger logger(SubscriberExceptionContext context) {
  return Logger.getLogger(EventBus.class.getName() + "." + context.getEventBus().identifier());
}