本文整理匯總了Java中java.util.logging.StreamHandler.setLevel方法的典型用法代碼示例。如果您正苦於以下問題:Java StreamHandler.setLevel方法的具體用法?Java StreamHandler.setLevel怎麽用?Java StreamHandler.setLevel使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類java.util.logging.StreamHandler
的用法示例。
在下文中一共展示了StreamHandler.setLevel方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: createLogger
import java.util.logging.StreamHandler; //導入方法依賴的package包/類
protected static Logger createLogger() {
// Initialize logging
StreamHandler handler = new StreamHandler(System.out, new SimpleFormatter());
handler.setLevel(Level.ALL);
Logger logger = Logger.getLogger(GeFLoRegistry.class.getName());
logger.addHandler(handler);
/*
* Change the level if you want to...
* - disable logging to Level.OFF
* - enable logging to Level.ALL
*/
logger.setLevel(Level.ALL);
return logger;
}
示例2: testLogger
import java.util.logging.StreamHandler; //導入方法依賴的package包/類
private void testLogger( StreamHandler afh ) {
Handler[] handlers = LOGGER.getHandlers();
for ( Handler handler : handlers ) {
try {
LOGGER.removeHandler( handler );
} catch ( Exception e ) {
e.printStackTrace();
}
}
afh.setFormatter( new SimpleFormatter() );
afh.setLevel( Level.FINEST );
LOGGER.addHandler( afh );
LOGGER.setLevel( Level.FINEST );
final int threadCount = 20;
final int logEntryCount = 100000;
generateLogs( threadCount, logEntryCount );
afh.close();
}
示例3: testIsLoggable_NoFilter
import java.util.logging.StreamHandler; //導入方法依賴的package包/類
public void testIsLoggable_NoFilter() {
StreamHandler h = new StreamHandler(new ByteArrayOutputStream(),
new SimpleFormatter());
LogRecord r = new LogRecord(Level.INFO, null);
assertTrue(h.isLoggable(r));
h.setLevel(Level.WARNING);
assertFalse(h.isLoggable(r));
h.setLevel(Level.CONFIG);
assertTrue(h.isLoggable(r));
r.setLevel(Level.OFF);
h.setLevel(Level.OFF);
assertFalse(h.isLoggable(r));
}
示例4: testIsLoggable_WithFilter
import java.util.logging.StreamHandler; //導入方法依賴的package包/類
public void testIsLoggable_WithFilter() {
StreamHandler h = new StreamHandler(new ByteArrayOutputStream(),
new SimpleFormatter());
LogRecord r = new LogRecord(Level.INFO, null);
h.setFilter(new MockFilter());
assertFalse(h.isLoggable(r));
assertSame(r, CallVerificationStack.getInstance().pop());
h.setLevel(Level.CONFIG);
assertFalse(h.isLoggable(r));
assertSame(r, CallVerificationStack.getInstance().pop());
h.setLevel(Level.WARNING);
assertFalse(h.isLoggable(r));
assertTrue(CallVerificationStack.getInstance().empty());
}
示例5: main
import java.util.logging.StreamHandler; //導入方法依賴的package包/類
public static void main(String[] args) {
Jive6ContributorProfileProvider provider = new Jive6ContributorProfileProvider();
provider.appConfiguration = new AppConfiguration("adp");
String providerUsername = "";
String providerPassword = "";
ContributorProfileProviderConfig contributorProfileProviderConfig = new ContributorProfileProviderConfig(
"https://developer.jboss.org", providerUsername, providerPassword);
provider.appConfiguration.setContributorProfileProviderConfig(contributorProfileProviderConfig);
provider.init();
// Set up logging
provider.log = Logger.getLogger(Jive6ContributorProfileProvider.class.getName());
provider.log.setLevel(Level.FINEST);
Logger rootLogger = Logger.getLogger("");
StreamHandler handler = new StreamHandler(System.out, new SimpleFormatter());
handler.setLevel(Level.FINEST);
rootLogger.addHandler(handler);
ContributorProfile profile = provider.getProfile("lkrzyzanek");
provider.destroy();
System.out.println("profile: " + profile);
}
示例6: testDepResolver
import java.util.logging.StreamHandler; //導入方法依賴的package包/類
public void testDepResolver() throws URISyntaxException, CatalogModelException, IOException {
Logger logger = Logger.getLogger(CatalogModelTest.class.getName());
logger.setLevel(Level.ALL);
StreamHandler sh = new MyHandler(System.out, new SimpleFormatter());
sh.setLevel(logger.getLevel());
//logger.addHandler(sh);
CatalogFileWrapperDOMImpl.TEST_ENVIRONMENT = true;
File catFile = new File(System.getProperty("java.io.tmpdir")+File.separator+CatalogWriteModel.PUBLIC_CATALOG_FILE_NAME+CatalogWriteModel.CATALOG_FILE_EXTENSION+".girish");
catFile.delete();
catFile.createNewFile();
FileObject catFO = FileUtil.toFileObject(FileUtil.normalizeFile(catFile));
URL url = getClass().getResource("dummyFile.txt");
FileObject peerfo = FileUtil.toFileObject(new File(url.toURI()).getAbsoluteFile());
System.out.println(catFile);
CatalogWriteModel drz = new MyCatalogWriteModel(catFO);
//CatalogWriteModel drz = new MyCatalogWriteModel(new File(System.getProperty("java.io.tmpdir")));
drz.addURI(new URI("dummy/dummy"), peerfo);
int length = drz.getCatalogEntries().size();
assertEquals(1, length);
//System.out.println("%%%%"+drz.getModelSource(new URI("dummy/dummy")).getFileObject());
//System.out.println("$$$$"+LSResourceResolverFactory.getDefault().resolveResource(null, null, null, "dummy/dummy", url.toURI().toString()).getSystemId());
//assertTrue(LSResourceResolverFactory.getDefault().resolveResource(null, null, null, "dummy/dummy", url.toURI().toString()).getSystemId().endsWith("dummyFile.txt"));
FileObject fob = (FileObject) drz.getModelSource(new URI("dummy/dummy")).getLookup().lookup(FileObject.class);
assertNotNull(fob);
drz.removeURI(new URI("dummy/dummy"));
length = drz.getCatalogEntries().size();
assertEquals(0, length);
}
示例7: streamHandler
import java.util.logging.StreamHandler; //導入方法依賴的package包/類
private static synchronized Handler streamHandler() {
if (streamHandler == null) {
StreamHandler sth = new StreamHandler (OLD_ERR, NbFormatter.FORMATTER);
sth.setLevel(Level.ALL);
streamHandler = NbLogging.createDispatchHandler(sth, 500);
}
return streamHandler;
}
示例8: setupLoggers
import java.util.logging.StreamHandler; //導入方法依賴的package包/類
/**
* Sets up loggers to print to stdout (rather than stderr) and log to ~/Shuffleboard/shuffleboard.log
*/
private void setupLoggers() throws IOException {
//Set up the global level logger. This handles IO for all loggers.
final Logger globalLogger = LogManager.getLogManager().getLogger("");
// Remove the default handlers that stream to System.err
for (Handler handler : globalLogger.getHandlers()) {
globalLogger.removeHandler(handler);
}
final Handler fileHandler = new FileHandler(Storage.getStorageDir() + "/shuffleboard.log");
fileHandler.setLevel(Level.INFO); // Only log INFO and above to disk
globalLogger.setLevel(Level.CONFIG); // Log CONFIG and higher
// We need to stream to System.out instead of System.err
final StreamHandler sh = new StreamHandler(System.out, new SimpleFormatter()) {
@Override
public synchronized void publish(final LogRecord record) { // NOPMD this is the same signature as the superclass
super.publish(record);
// For some reason this doesn't happen automatically.
// This will ensure we get all of the logs printed to the console immediately instead of at shutdown
flush();
}
};
sh.setLevel(Level.CONFIG); // Log CONFIG and higher to stdout
globalLogger.addHandler(sh);
globalLogger.addHandler(fileHandler);
fileHandler.setFormatter(new SimpleFormatter()); //log in text, not xml
globalLogger.config("Configuration done."); //Log that we are done setting up the logger
globalLogger.config("Shuffleboard app version: " + Shuffleboard.class.getPackage().getImplementationVersion());
}
示例9: testIsLoggable_NoOutputStream
import java.util.logging.StreamHandler; //導入方法依賴的package包/類
public void testIsLoggable_NoOutputStream() {
StreamHandler h = new StreamHandler();
LogRecord r = new LogRecord(Level.INFO, null);
assertFalse(h.isLoggable(r));
h.setLevel(Level.WARNING);
assertFalse(h.isLoggable(r));
h.setLevel(Level.CONFIG);
assertFalse(h.isLoggable(r));
r.setLevel(Level.OFF);
h.setLevel(Level.OFF);
assertFalse(h.isLoggable(r));
}
示例10: testPublish_NoOutputStream
import java.util.logging.StreamHandler; //導入方法依賴的package包/類
public void testPublish_NoOutputStream() {
StreamHandler h = new StreamHandler();
LogRecord r = new LogRecord(Level.INFO, "testPublish_NoOutputStream");
h.publish(r);
h.setLevel(Level.WARNING);
h.publish(r);
h.setLevel(Level.CONFIG);
h.publish(r);
r.setLevel(Level.OFF);
h.setLevel(Level.OFF);
h.publish(r);
}
示例11: testPublish_NoFilter
import java.util.logging.StreamHandler; //導入方法依賴的package包/類
public void testPublish_NoFilter() {
ByteArrayOutputStream aos = new ByteArrayOutputStream();
StreamHandler h = new StreamHandler(aos, new MockFormatter());
LogRecord r = new LogRecord(Level.INFO, "testPublish_NoFilter");
h.setLevel(Level.INFO);
h.publish(r);
h.flush();
assertEquals("MockFormatter_Head" + "testPublish_NoFilter", aos
.toString());
h.setLevel(Level.WARNING);
h.publish(r);
h.flush();
assertEquals("MockFormatter_Head" + "testPublish_NoFilter", aos
.toString());
h.setLevel(Level.CONFIG);
h.publish(r);
h.flush();
assertEquals("MockFormatter_Head" + "testPublish_NoFilter"
+ "testPublish_NoFilter", aos.toString());
r.setLevel(Level.OFF);
h.setLevel(Level.OFF);
h.publish(r);
h.flush();
assertEquals("MockFormatter_Head" + "testPublish_NoFilter"
+ "testPublish_NoFilter", aos.toString());
}
示例12: testPublish_WithFilter
import java.util.logging.StreamHandler; //導入方法依賴的package包/類
public void testPublish_WithFilter() {
ByteArrayOutputStream aos = new ByteArrayOutputStream();
StreamHandler h = new StreamHandler(aos, new MockFormatter());
h.setFilter(new MockFilter());
LogRecord r = new LogRecord(Level.INFO, "testPublish_WithFilter");
h.setLevel(Level.INFO);
h.publish(r);
h.flush();
assertEquals("", aos.toString());
assertSame(r, CallVerificationStack.getInstance().pop());
h.setLevel(Level.WARNING);
h.publish(r);
h.flush();
assertEquals("", aos.toString());
assertTrue(CallVerificationStack.getInstance().empty());
h.setLevel(Level.CONFIG);
h.publish(r);
h.flush();
assertEquals("", aos.toString());
assertSame(r, CallVerificationStack.getInstance().pop());
r.setLevel(Level.OFF);
h.setLevel(Level.OFF);
h.publish(r);
h.flush();
assertEquals("", aos.toString());
assertTrue(CallVerificationStack.getInstance().empty());
}
示例13: testPublish_Null_NoOutputStream
import java.util.logging.StreamHandler; //導入方法依賴的package包/類
public void testPublish_Null_NoOutputStream() {
StreamHandler h = new StreamHandler();
h.publish(null);
// regression test for Harmony-1279
MockFilter filter = new MockFilter();
h.setLevel(Level.FINER);
h.setFilter(filter);
LogRecord record = new LogRecord(Level.FINE, "abc");
h.publish(record);
// verify that filter.isLoggable is not called, because there's no
// associated output stream.
assertTrue(CallVerificationStack.getInstance().empty());
}
示例14: ProtTestLogger
import java.util.logging.StreamHandler; //導入方法依賴的package包/類
public ProtTestLogger(String loggerName) {
this.loggerName = loggerName;
if (loggers.containsKey(loggerName))
throw new ProtTestInternalException("ProtTestLogger with name "
+ loggerName + " already exists. "
+ " Use getLogger() instead");
this.loggerLevel = Level.ALL;
// Add standard output handler
this.handlers = new ArrayList<Handler>();
stdHandler = new StreamHandler(System.out, new ProtTestLogFormatter());
stdHandler.setLevel(Level.OFF);
handlers.add(stdHandler);
}
示例15: createStreamHandler
import java.util.logging.StreamHandler; //導入方法依賴的package包/類
public static StreamHandler createStreamHandler(OutputStream stream, Level level, Formatter formatter) {
StreamHandler streamHandler = new StreamHandler(stream, formatter) {
@Override
public synchronized void publish(LogRecord record) {
super.publish(record);
super.flush();
}
};
streamHandler.setLevel(level);
return streamHandler;
}