use of java.util.logging.LogManager in project jetty.project by eclipse.
the class JavaUtilLogTest method setJUL.
@BeforeClass
public static void setJUL() {
LogManager lmgr = LogManager.getLogManager();
java.util.logging.Logger root = lmgr.getLogger("");
// Remember original handlers
originalHandlers = root.getHandlers();
// Remove original handlers
for (Handler existing : originalHandlers) {
root.removeHandler(existing);
}
// Set test/capturing handler
jul = new CapturingJULHandler();
root.addHandler(jul);
}
use of java.util.logging.LogManager in project j2objc by google.
the class LoggerTest method test_initHandler.
/*
* Test whether privileged code is used to load resource bundles.
*
public void testLoadResourceBundle() {
//
SecurityManager oldMan = System.getSecurityManager();
System.setSecurityManager(new MockNoLoadingClassSecurityManager());
try {
Logger.getAnonymousLogger(VALID_RESOURCE_BUNDLE);
} finally {
System.setSecurityManager(oldMan);
}
}
public void testLoadResourceBundleNonExistent() {
try {
// Try a load a non-existent resource bundle.
LoggerExtension.loadResourceBundle("missinglogger.properties");
fail("Expected an exception.");
} catch (MissingResourceException ex) {
// Expected exception is precisely a MissingResourceException
assertTrue(ex.getClass() == MissingResourceException.class);
}
}
/**
* @tests java.util.logging.Logger#logrb(Level, String, String, String,
* String, Object)
*
public void test_init_logger()
throws Exception {
Properties p = new Properties();
p.put("testGetLogger_Normal_ANewLogger2.level", "ALL");
LogManager.getLogManager().readConfiguration(
EnvironmentHelper.PropertiesToInputStream(p));
assertNull(LogManager.getLogManager().getLogger(
"testGetLogger_Normal_ANewLogger2"));
SecurityManager originalSecurityManager = System.getSecurityManager();
try {
System.setSecurityManager(new SecurityManager());
// should not throw expection
Logger logger = Logger.getLogger("testGetLogger_Normal_ANewLogger2");
// should thrpw exception
try{
logger.setLevel(Level.ALL);
fail("should throw SecurityException");
} catch (SecurityException e){
// expected
}
try{
logger.setParent(Logger.getLogger("root"));
fail("should throw SecurityException");
} catch (SecurityException e){
// expected
}
} finally {
System.setSecurityManager(originalSecurityManager);
}
}
/*
* test initHandler
*/
public void test_initHandler() throws Exception {
InputStream logProps = ClassLoader.getSystemResourceAsStream(LOGGING_CONFIG_FILE);
LogManager lm = LogManager.getLogManager();
lm.readConfiguration(logProps);
Logger log = Logger.getLogger("");
// can log properly
Handler[] handlers = log.getHandlers();
assertEquals(2, handlers.length);
}
use of java.util.logging.LogManager in project jersey by jersey.
the class JerseyTest method getRootLoggers.
/**
* Retrieves a list of root loggers.
*
* @return list of root loggers.
*/
private Set<Logger> getRootLoggers() {
final LogManager logManager = LogManager.getLogManager();
final Enumeration<String> loggerNames = logManager.getLoggerNames();
final Set<Logger> rootLoggers = new HashSet<>();
while (loggerNames.hasMoreElements()) {
Logger logger = logManager.getLogger(loggerNames.nextElement());
if (logger != null) {
while (logger.getParent() != null) {
logger = logger.getParent();
}
rootLoggers.add(logger);
}
}
return rootLoggers;
}
use of java.util.logging.LogManager in project OpenAM by OpenRock.
the class SecureFileHandler method initializeVerifier.
/**
* Initialize SecureLog verifier
* @param verPass verifier password
* @param token AM token
*/
public static void initializeVerifier(AMPassword verPass, Object token) {
/* Remove the relevant verifier initialization code when deploying
* it finally. For the timebeing it will be done in the old way
* of doing it in the constructor thru initializeSecurity();
*/
try {
setVerPassword(verPass, token);
LogManager lmanager = LogManagerUtil.getLogManager();
String logPath = lmanager.getProperty(LogConstants.LOG_LOCATION);
if (!logPath.endsWith("/"))
logPath += "/";
LogManager manager = LogManagerUtil.getLogManager();
Enumeration e = manager.getLoggerNames();
while (e.hasMoreElements()) {
String FileName = (String) e.nextElement();
String verifierFileName = logPath + PREFIX + "ver." + FileName;
SecureLogHelper helper = getSecureLogHelper(FileName);
AMPassword logPassword = getLogPassword();
// explicit auditor role in DSAME to initialize ver.
if (helper != null) {
helper.initializeVerifier(verifierFileName, logPassword, verPassword);
try {
Debug.message(FileName + ":Trying to start the Verifier Thread");
Logger logger = (com.sun.identity.log.Logger) Logger.getLogger(FileName);
Handler[] handlers = logger.getHandlers();
((com.sun.identity.log.handlers.SecureFileHandler) handlers[0]).startVerifierThread();
Debug.message(FileName + ":Started Log Verifier thread");
} catch (Exception ex) {
Debug.error(FileName + ":Unable to start Verifier Thread", ex);
// throw custom exception
}
}
verificationInitialized = true;
}
} catch (Exception e) {
Debug.error("Error initializing Verification", e);
}
}
use of java.util.logging.LogManager in project ACS by ACS-Community.
the class AcsLogger method createUnconfiguredLogger.
/**
* Non-standard factory method to be used only for special offline or testing purposes
* where typically an AcsLogger must be provided by an alternative implementation of ContainerServices.
* The returned AcsLogger is just like a JDK Logger obtained from {@link Logger#getLogger(String, String)}.
* <p>
* Note that we do not supply a {@link LogConfig} and therefore the new AcsLogger cannot register itself
* for initial configuration or later configuration change notifications. <br>
* <b>It is the client's responsibility to configure the log level and parent logger of the returned AcsLogger!</b>
*
* @param name the logger's name
* @param resourceBundleName
* @return <code>AcsLogger</code> that is as close to a normal JDK Logger as possible.
* @throws IllegalArgumentException
* If a Logger of the given <code>name</code> exists but is not an <code>AcsLogger</code>,
* or if an AcsLogger of the given <code>name</code> exists but has a different <code>resourceBundleName</code>.
*/
public static AcsLogger createUnconfiguredLogger(String name, String resourceBundleName) {
// the following code is copied and modified from Logger.getLogger
LogManager manager = LogManager.getLogManager();
Logger jdkLogger = manager.getLogger(name);
if (jdkLogger != null && !(jdkLogger instanceof AcsLogger)) {
throw new IllegalArgumentException("Logger " + name + " already exists but is not of subtype AcsLogger.");
}
AcsLogger result = (AcsLogger) jdkLogger;
if (result == null) {
// Create a new logger.
// Note: we may get a MissingResourceException here.
result = new AcsLogger(name, resourceBundleName, null, true, null);
manager.addLogger(result);
result = (AcsLogger) manager.getLogger(name);
}
// however we check that the old and new bundle are consistent.
if (result.getResourceBundleName() != null && !result.getResourceBundleName().equals(resourceBundleName)) {
throw new IllegalArgumentException(result.getResourceBundleName() + " != " + resourceBundleName);
}
return result;
}
Aggregations