本文整理汇总了Java中java.util.logging.Logger.getLogger方法的典型用法代码示例。如果您正苦于以下问题:Java Logger.getLogger方法的具体用法?Java Logger.getLogger怎么用?Java Logger.getLogger使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类java.util.logging.Logger
的用法示例。
在下文中一共展示了Logger.getLogger方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: tearDown
import java.util.logging.Logger; //导入方法依赖的package包/类
@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();
}
示例2: find
import java.util.logging.Logger; //导入方法依赖的package包/类
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;
}
}
示例3: testPermission
import java.util.logging.Logger; //导入方法依赖的package包/类
/**
* 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);
}
}
示例4: failToLoadResourceBundle
import java.util.logging.Logger; //导入方法依赖的package包/类
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;
}
}
示例5: logLookAndFeelUsage
import java.util.logging.Logger; //导入方法依赖的package包/类
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 );
}
示例6: handleUserFollowed
import java.util.logging.Logger; //导入方法依赖的package包/类
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) {}
}
示例7: run
import java.util.logging.Logger; //导入方法依赖的package包/类
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);
}
}
示例8: setUp
import java.util.logging.Logger; //导入方法依赖的package包/类
@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);
}
示例9: tearDown
import java.util.logging.Logger; //导入方法依赖的package包/类
@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();
}
示例10: fatalError
import java.util.logging.Logger; //导入方法依赖的package包/类
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;
}
}
示例11: TestLogger
import java.util.logging.Logger; //导入方法依赖的package包/类
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;
}
示例12: run
import java.util.logging.Logger; //导入方法依赖的package包/类
@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();
}
}
示例13: log
import java.util.logging.Logger; //导入方法依赖的package包/类
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);
}
}
示例14: setUp
import java.util.logging.Logger; //导入方法依赖的package包/类
@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);
}
示例15: restored
import java.util.logging.Logger; //导入方法依赖的package包/类
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);
}