本文整理汇总了Java中java.util.logging.ConsoleHandler类的典型用法代码示例。如果您正苦于以下问题:Java ConsoleHandler类的具体用法?Java ConsoleHandler怎么用?Java ConsoleHandler使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
ConsoleHandler类属于java.util.logging包,在下文中一共展示了ConsoleHandler类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: Server
import java.util.logging.ConsoleHandler; //导入依赖的package包/类
public Server(String fileName, boolean restart) {
super();
parseServerFile(fileName);
seatAssignments = new ArrayList<>(nSeats);
for (int i = 0; i < nSeats; i++)
seatAssignments.add("");
log.getParent().removeHandler(log.getParent().getHandlers()[0]);
try {
// check if logs dir exists
File logDir = new File("./logs/");
if( !(logDir.exists()) )
logDir.mkdir();
FileHandler fh = new FileHandler("logs/server_log_" + serverID + ".log");
fh.setFormatter(new SimpleFormatter());
fh.setLevel(logLevel);
log.addHandler(fh);
ConsoleHandler ch = new ConsoleHandler();
ch.setLevel(logLevel);
log.addHandler(ch);
log.setLevel(logLevel);
log.info("Server initializing...");
log.info("ServerID = " + serverID);
log.info("nServers = " + nServers);
log.info("nSeats = " + nSeats);
log.info("my tcp port = " + tcpPort);
for (int i = 0; i < nServers; i++)
log.info("Server " + i + ": " + servers.get(i) + ":" + ports.get(i));
log.info("Server init complete");
log.info("--------------------------------");
mutex = new LamportMutex(servers, ports, this, restart);
mutex.init();
} catch (SecurityException | IOException e) {
e.printStackTrace();
}
}
示例2: unitLogging
import java.util.logging.ConsoleHandler; //导入依赖的package包/类
public static void unitLogging()
{
// Start with a fresh root set at warning
Logger root = LogManager.getLogManager().getLogger("");
root.setLevel(Level.WARNING);
for(Handler handler : root.getHandlers()) { root.removeHandler(handler); }
//Logger.getLogger("java.util.prefs").setLevel(Level.SEVERE);
Logger.getLogger("org.postgresql.jdbc").setLevel(Level.OFF);
Logger.getLogger("org.postgresql.Driver").setLevel(Level.OFF);
Logger.getLogger("org.wwscc").setLevel(Level.ALL);
ConsoleHandler ch = new ConsoleHandler();
ch.setLevel(Level.ALL);
ch.setFormatter(new SingleLineFormatter());
root.addHandler(ch);
}
示例3: setupLogger
import java.util.logging.ConsoleHandler; //导入依赖的package包/类
@Before
public void setupLogger() throws Exception {
Level level = Level.INFO;
Thread.setDefaultUncaughtExceptionHandler(new Thread.UncaughtExceptionHandler() {
@Override
public void uncaughtException(Thread t, Throwable e) {
System.err.println("uncaughtException from thread " + t.getName() + ": " + e);
e.printStackTrace();
}
});
java.util.logging.LogManager.getLogManager().reset();
ConsoleHandler ch = new ConsoleHandler();
ch.setLevel(level);
SimpleFormatter f = new SimpleFormatter();
ch.setFormatter(f);
java.util.logging.Logger.getLogger("").setLevel(level);
java.util.logging.Logger.getLogger("").addHandler(ch);
}
示例4: doDeadlockConsoleAndStdErr
import java.util.logging.ConsoleHandler; //导入依赖的package包/类
private void doDeadlockConsoleAndStdErr(final ConsoleHandler ch) {
class H extends Handler implements Runnable {
public void publish(LogRecord record) {
try {
RequestProcessor.getDefault().post(this).waitFinished(100);
} catch (InterruptedException ex) {
// ex.printStackTrace();
}
}
public void flush() {
}
public void close() throws SecurityException {
}
public void run() {
ch.publish(new LogRecord(Level.WARNING, "run"));
}
}
H handler = new H();
Logger.getLogger("stderr").addHandler(handler);
System.err.println("Ahoj");
}
示例5: init
import java.util.logging.ConsoleHandler; //导入依赖的package包/类
/**
* Creates a new logger
*/
private Logger init(final Level level, final String file) {
final LogSettings logSettings = settingsService.getLogSettings();
final Logger logger = Logger.getAnonymousLogger();
logger.setLevel(level);
logger.setUseParentHandlers(false);
try {
final FileUnits units = logSettings.getMaxLengthPerFileUnits();
final FileHandler fileHandler = new FileHandler(file, units.calculate(logSettings.getMaxLengthPerFile()), logSettings.getMaxFilesPerLog(), true);
fileHandler.setFormatter(logFormatter);
fileHandler.setEncoding(settingsService.getLocalSettings().getCharset());
logger.addHandler(fileHandler);
} catch (final Exception e) {
final ConsoleHandler consoleHandler = new ConsoleHandler();
consoleHandler.setFormatter(logFormatter);
try {
consoleHandler.setEncoding(settingsService.getLocalSettings().getCharset());
} catch (final Exception e1) {
// Just ignore
}
logger.addHandler(consoleHandler);
logger.log(Level.WARNING, "Unable to create logger for file " + file);
}
return logger;
}
示例6: main
import java.util.logging.ConsoleHandler; //导入依赖的package包/类
/**
* Main entry point for the OpenOffice.org Bean Test.
*
* @param args arguments of the test
*
* @author Andreas Bröker
* @date 21.05.2006
*/
public static void main(String[] args) throws OfficeApplicationException {
LogManager.getLogManager().reset();
ConsoleHandler consoleHandler = new ConsoleHandler();
consoleHandler.setLevel(Level.FINEST);
LOGGER.addHandler(consoleHandler);
LOGGER.setLevel(Level.FINEST);
try {
FileHandler fileHandler = new FileHandler("log.xml");
fileHandler.setLevel(Level.FINEST);
LOGGER.addHandler(fileHandler);
} catch (Throwable throwable) {
}
OfficeBeanTest testOfficeBean = new OfficeBeanTest();
if (args.length == 0) {
testOfficeBean.test(null);
}else if (args.length == 1) {
testOfficeBean.test(args[0]);
}else if(args.length==4){
testOfficeBean.remoteTestPDF(new File(args[2]), new File(args[3]), args[0], Integer.valueOf(args[1]));
}else{
System.out.println("usage:\nOfficeBeanTest host port source-odt target-pdf\nOfficeBeanTest officeHome");
}
}
示例7: setupLogger
import java.util.logging.ConsoleHandler; //导入依赖的package包/类
@Before
public void setupLogger() throws Exception {
Level level = Level.SEVERE;
Thread.setDefaultUncaughtExceptionHandler(new Thread.UncaughtExceptionHandler() {
@Override
public void uncaughtException(Thread t, Throwable e) {
System.err.println("uncaughtException from thread " + t.getName() + ": " + e);
e.printStackTrace();
}
});
java.util.logging.LogManager.getLogManager().reset();
ConsoleHandler ch = new ConsoleHandler();
ch.setLevel(level);
SimpleFormatter f = new SimpleFormatter();
ch.setFormatter(f);
java.util.logging.Logger.getLogger("").setLevel(level);
java.util.logging.Logger.getLogger("").addHandler(ch);
}
示例8: testConstructor_InvalidProperties
import java.util.logging.ConsoleHandler; //导入依赖的package包/类
public void testConstructor_InvalidProperties() throws Exception {
Properties p = new Properties();
p.put("java.util.logging.ConsoleHandler.level", INVALID_LEVEL);
p.put("java.util.logging.ConsoleHandler.filter", className);
p.put("java.util.logging.ConsoleHandler.formatter", className);
p.put("java.util.logging.ConsoleHandler.encoding", "XXXX");
LogManager.getLogManager().readConfiguration(
EnvironmentHelper.PropertiesToInputStream(p));
assertEquals(LogManager.getLogManager().getProperty(
"java.util.logging.ConsoleHandler.level"), INVALID_LEVEL);
assertEquals(LogManager.getLogManager().getProperty(
"java.util.logging.ConsoleHandler.encoding"), "XXXX");
ConsoleHandler h = new ConsoleHandler();
assertSame(h.getLevel(), Level.INFO);
assertTrue(h.getFormatter() instanceof SimpleFormatter);
assertNull(h.getFilter());
assertNull(h.getEncoding());
h.publish(new LogRecord(Level.SEVERE, "test"));
assertNull(h.getEncoding());
}
示例9: testPublish_AfterResetSystemErr
import java.util.logging.ConsoleHandler; //导入依赖的package包/类
public void testPublish_AfterResetSystemErr() throws Exception {
Properties p = new Properties();
p.put("java.util.logging.ConsoleHandler.formatter", className
+ "$MockFormatter");
LogManager.getLogManager().readConfiguration(
EnvironmentHelper.PropertiesToInputStream(p));
ConsoleHandler h = new ConsoleHandler();
h.setFilter(new MockFilter());
System.setErr(new PrintStream(new ByteArrayOutputStream()));
LogRecord r = new LogRecord(Level.INFO, "testPublish_WithFilter");
h.setLevel(Level.INFO);
h.publish(r);
assertNull(CallVerificationStack.getInstance().pop());
assertSame(r, CallVerificationStack.getInstance().pop());
assertEquals("", this.errSubstituteStream.toString());
}
示例10: setupLogging
import java.util.logging.ConsoleHandler; //导入依赖的package包/类
private void setupLogging() {
log.setUseParentHandlers(false);
LogFormatter formatter = new LogFormatter();
ConsoleHandler ch = new ConsoleHandler();
ch.setFormatter(formatter);
if (isDebugging()) {
log.setLevel(Level.FINEST);
ch.setLevel(Level.FINEST);
} else {
log.setLevel(Level.INFO);
ch.setLevel(Level.INFO);
}
log.addHandler(ch);
try {
FileHandler fh = new FileHandler("server.log");
fh.setFormatter(formatter);
if (isDebugging()) {
fh.setLevel(Level.FINEST);
} else {
ch.setLevel(Level.INFO);
}
log.addHandler(fh);
} catch (IOException ex) {
log.log(Level.SEVERE, "Error while adding FileHandler to logger. Logs will not be output to a file.", ex);
}
}
示例11: start
import java.util.logging.ConsoleHandler; //导入依赖的package包/类
@Override
public StandardOutputCapture start() {
super.start();
boolean shouldReadLoggingConfigFile = System.getProperty(READ_LOGGING_CONFIG_FILE_PROPERTY, "true").equals("true");
if (!shouldReadLoggingConfigFile) {
SingleMessageLogger.nagUserOfDiscontinuedProperty(READ_LOGGING_CONFIG_FILE_PROPERTY,
"Change your test to work with your java.util.logging configuration file settings.");
}
if (!reset) {
LogManager.getLogManager().reset();
if (shouldReadLoggingConfigFile) {
try {
LogManager.getLogManager().readConfiguration();
} catch (IOException error) {
Logger.getLogger("").addHandler(new ConsoleHandler());
}
} else {
Logger.getLogger("").addHandler(new ConsoleHandler());
}
reset = true;
}
return this;
}
示例12: enableHttp2FrameLogging
import java.util.logging.ConsoleHandler; //导入依赖的package包/类
private static void enableHttp2FrameLogging() {
frameLogger = Logger.getLogger(Http2.class.getName());
frameLogger.setLevel(Level.FINE);
ConsoleHandler handler = new ConsoleHandler();
handler.setLevel(Level.FINE);
handler.setFormatter(new SimpleFormatter() {
@Override public String format(LogRecord record) {
return Util.format("%s%n", record.getMessage());
}
});
frameLogger.addHandler(handler);
}
示例13: LoggingConfig
import java.util.logging.ConsoleHandler; //导入依赖的package包/类
public LoggingConfig() {
try {
// Load a properties file from class path java.util.logging.config.file
final LogManager logManager = LogManager.getLogManager();
URL configURL = getClass().getResource("/logging.properties");
if (configURL != null) {
try (InputStream is = configURL.openStream()) {
logManager.readConfiguration(is);
}
} else {
// Programmatic configuration
System.setProperty("java.util.logging.SimpleFormatter.format",
"%1$tY-%1$tm-%1$td %1$tH:%1$tM:%1$tS.%1$tL %4$-7s [%3$s] %5$s %6$s%n");
final ConsoleHandler consoleHandler = new ConsoleHandler();
consoleHandler.setLevel(Level.FINEST);
consoleHandler.setFormatter(new SimpleFormatter());
final Logger app = Logger.getLogger("app");
app.setLevel(Level.FINEST);
app.addHandler(consoleHandler);
}
} catch (Exception e) {
e.printStackTrace();
}
}
示例14: ServerRunner
import java.util.logging.ConsoleHandler; //导入依赖的package包/类
/**
* Constructor.
*/
public ServerRunner() {
log.setLevel(Level.ALL);
ConsoleHandler handler = new ConsoleHandler();
handler.setFormatter(new SimpleFormatter());
handler.setLevel(Level.ALL);
log.addHandler(handler);
}
示例15: setUp
import java.util.logging.ConsoleHandler; //导入依赖的package包/类
public void setUp()
{
agentId = new TeamedAgentId("Agent01");
agentId.setTeamId( new TeamId("teamRED"));
agentLogger = new AgentLogger(agentId);
LifecycleBus bus = new LifecycleBus(agentLogger);
Logger sharedLogger = Logger.getLogger("SharedLogger");
sharedLogger.addHandler( new ConsoleHandler() );
sharedLogger.setLevel( Level.INFO );
agentLogger.setLevel(Level.INFO);
agentLogger.addDefaultConsoleHandler();
sharedWV = new EventDrivenSharedWorldViewStub( sharedLogger );
ComponentStub starter = new ComponentStub(agentLogger, bus);
localWV = new EventDrivenLocalWorldViewStub( new ComponentDependencies( ComponentDependencyType.STARTS_WITH ).add(starter), bus, agentLogger, sharedWV, agentId);
starter.getController().manualStart("TEST");
localWV.setCurrentTime( TimeKey.get(0));
}