本文整理汇总了Java中java.util.logging.ConsoleHandler.setFormatter方法的典型用法代码示例。如果您正苦于以下问题:Java ConsoleHandler.setFormatter方法的具体用法?Java ConsoleHandler.setFormatter怎么用?Java ConsoleHandler.setFormatter使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类java.util.logging.ConsoleHandler
的用法示例。
在下文中一共展示了ConsoleHandler.setFormatter方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: 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);
}
示例2: 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);
}
示例3: 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;
}
示例4: 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);
}
示例5: setUpConsoleHandler
import java.util.logging.ConsoleHandler; //导入方法依赖的package包/类
/** Set up console handler */
public static Handler setUpConsoleHandler() {
final ConsoleHandler handler = new ConsoleHandler() {
@Override
protected void setOutputStream(final OutputStream out) throws SecurityException {
super.setOutputStream(System.out);
}
};
handler.setLevel(Level.ALL);
final Formatter formatter = new Formatter() {
@Override
public String format(final LogRecord record) {
return record.getMessage();
}
};
handler.setFormatter(formatter);
return handler;
}
示例6: 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);
}
示例7: 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();
}
}
示例8: 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);
}
示例9: createMetricUpdateTracer
import java.util.logging.ConsoleHandler; //导入方法依赖的package包/类
private static Logger createMetricUpdateTracer() {
Logger logger = Logger.getLogger(TracingMetricRegistry.class.getName() + ".metricUpdates");
ConsoleHandler handler = new ConsoleHandler();
handler.setFormatter(new Formatter() {
@Override
public String format(LogRecord record) {
return ">>" + record.getMessage() + "\n";
}
});
logger.addHandler(handler);
logger.setUseParentHandlers(false);
handler.setLevel(Level.ALL);
//logger.setLevel(Level.ALL);
return logger;
}
示例10: init
import java.util.logging.ConsoleHandler; //导入方法依赖的package包/类
@Override
public synchronized void init(ProcessingEnvironment processingEnv) {
super.init(processingEnv);
final Optional<String> jtsgenLogLevel = Optional.ofNullable(processingEnv.getOptions().get("jtsgenLogLevel"));
String packageName = AbstractProcessorWithLogging.class.getPackage().getName();
final Logger logger = Logger.getLogger(packageName);
if (jtsgenLogLevel.isPresent()) {
Level level = jtsgenLogLevel
.map(
(x) -> {
try {
return Level.parse(x.trim().toUpperCase());
} catch (IllegalArgumentException ex) {
return Level.OFF;
}
}
).orElse(Level.INFO);
Formatter oneLineFormatter = new OneLineFormatter();
ConsoleHandler consoleHandler = new ConsoleHandler();
consoleHandler.setLevel(level);
consoleHandler.setFormatter(oneLineFormatter);
logger.setUseParentHandlers(false);
logger.setLevel(level);
// consoleHandler.setFormatter(oneLineFormatter);
logger.addHandler(consoleHandler);
LOG.log(Level.FINER,() -> String.format("LogLevel %s = %s ", packageName, level.getName()));
} else {
logger.setLevel(Level.OFF);
}
}
示例11: addDefaultConsoleHandler
import java.util.logging.ConsoleHandler; //导入方法依赖的package包/类
private static void addDefaultConsoleHandler(Logger logger, String errorMessage,
String logFilePath) {
ConsoleHandler consoleHandler = new ConsoleHandler();
consoleHandler.setFormatter(new GemFireFormatter());
logger.addHandler(consoleHandler);
System.err
.println("ERROR: Could not log to file: " + logFilePath + ". Reason: " + errorMessage);
System.err.println("Logs will be written on Console.");
try {
Thread.sleep(3000); // sleep for 3 secs for the message to appear
} catch (InterruptedException ignore) {
}
}
示例12: start
import java.util.logging.ConsoleHandler; //导入方法依赖的package包/类
public void start() throws LoginException, InterruptedException, RateLimitedException {
running = true;
// init logger
AnsiConsole.systemInstall();
log = Logger.getLogger("Kyoko");
log.setUseParentHandlers(false);
ColoredFormatter formatter = new ColoredFormatter();
ConsoleHandler handler = new ConsoleHandler();
handler.setFormatter(formatter);
log.addHandler(handler);
log.info("Kyoko v" + Constants.VERSION + " is starting...");
i18n.loadMessages();
JDABuilder builder = new JDABuilder(AccountType.BOT);
if (settings.getToken() != null) {
if (settings.getToken().equalsIgnoreCase("Change me")) {
System.out.println("No token specified, please set it in config.json");
System.exit(1);
}
builder.setToken(settings.getToken());
}
boolean gameEnabled = false;
if (settings.getGame() != null && !settings.getGame().isEmpty()) {
gameEnabled = true;
builder.setGame(Game.of("booting..."));
}
builder.setAutoReconnect(true);
builder.setBulkDeleteSplittingEnabled(false);
builder.addEventListener(eventHandler);
builder.setAudioEnabled(true);
builder.setStatus(OnlineStatus.IDLE);
jda = builder.buildBlocking();
log.info("Invite link: " + "https://discordapp.com/oauth2/authorize?&client_id=" + jda.getSelfUser().getId() + "&scope=bot&permissions=" + Constants.PERMISSIONS);
if (gameEnabled) {
Thread t = new Thread(new Kyoko.BlinkThread());
t.start();
}
registerCommands();
}
示例13: appSetup
import java.util.logging.ConsoleHandler; //导入方法依赖的package包/类
/**
* Do some common setup for all applications at startup
* @param name the application name used for Java logging and database logging
*/
public static void appSetup(String name)
{
// Set our platform wide L&F
System.setProperty("swing.defaultlaf", "javax.swing.plaf.nimbus.NimbusLookAndFeel");
UIDefaults defaults = UIManager.getLookAndFeelDefaults();
defaults.put("Table.gridColor", new Color(140,140,140));
defaults.put("Table.showGrid", true);
// Set the program name which is used by PostgresqlDatabase to identify the app in logs
System.setProperty("program.name", name);
// Start with a fresh root set at warning
Logger root = LogManager.getLogManager().getLogger("");
Formatter format = new SingleLineFormatter();
root.setLevel(Level.WARNING);
for(Handler handler : root.getHandlers()) {
root.removeHandler(handler);
}
// Set prefs levels before windows preference load barfs useless data on the user
Logger.getLogger("java.util.prefs").setLevel(Level.SEVERE);
// postgres JDBC spits out a lot of data even though we catch the exception
Logger.getLogger("org.postgresql.jdbc").setLevel(Level.OFF);
Logger.getLogger("org.postgresql.Driver").setLevel(Level.OFF);
// Add console handler if running in debug mode
if (Prefs.isDebug()) {
ConsoleHandler ch = new ConsoleHandler();
ch.setLevel(Level.ALL);
ch.setFormatter(format);
root.addHandler(ch);
}
// For our own logs, we can set super fine level or info depending on if debug mode and attach dialogs to those
Logger applog = Logger.getLogger("org.wwscc");
applog.setLevel(Prefs.isDebug() ? Level.FINEST : Level.INFO);
applog.addHandler(new AlertHandler());
Thread.setDefaultUncaughtExceptionHandler(new UncaughtExceptionHandler() {
@Override
public void uncaughtException(Thread t, Throwable e) {
applog.log(Level.WARNING, String.format("\bUncaughtException in %s: %s", t, e), e);
}});
try {
File logdir = Prefs.getLogDirectory().toFile();
if (!logdir.exists())
if (!logdir.mkdirs())
throw new IOException("Can't create log directory " + logdir);
FileHandler fh = new FileHandler(new File(logdir, name+".%g.log").getAbsolutePath(), 1000000, 10, true);
fh.setFormatter(format);
fh.setLevel(Level.ALL);
root.addHandler(fh);
} catch (IOException ioe) {
JOptionPane.showMessageDialog(FocusManager.getCurrentManager().getActiveWindow(),
"Unable to enable logging to file: " + ioe, "Log Error", JOptionPane.ERROR_MESSAGE);
}
// force the initialization of IdGenerator on another thread so app can start now without an odd delay later
new Thread() {
public void run() {
IdGenerator.generateId();
}
}.start();
}
示例14: setLogging
import java.util.logging.ConsoleHandler; //导入方法依赖的package包/类
static private void setLogging(int logging) {
Level logLevel = getLogLevel(logging%10);
Logger.getLogger("org.jboss.wfink.eap71.playground").setLevel(logLevel);
logLevel = getLogLevel((logging/10)%10);
Logger.getLogger("org.xnio").setLevel(logLevel);
Logger.getLogger("org.jboss.remoting").setLevel(logLevel); //classes are remoting3
logLevel = getLogLevel((logging/100)%10);
Logger.getLogger("org.jboss.ejb.client").setLevel(logLevel);
logLevel = getLogLevel((logging/1000)%10);
Logger.getLogger("org.wildfly").setLevel(logLevel);
// Logger.getLogger("org.jboss.invocation").setLevel(logLevel);
// change default ConsoleHandler
Logger root = Logger.getLogger("");
Handler[] handlers = root.getHandlers();
for (int i = 0; i < handlers.length; i++) {
root.removeHandler(handlers[i]);
}
ConsoleHandler handler = new ConsoleHandler();
handler.setFormatter(new PlaygroundFormatter());
handler.setLevel(Level.ALL);
root.addHandler(handler);
}
示例15: setup
import java.util.logging.ConsoleHandler; //导入方法依赖的package包/类
static public void setup() throws IOException {
// Get root logger object
Logger rootLogger = Logger.getLogger("");
rootLogger.removeHandler(rootLogger.getHandlers()[0]);
// Create new ConsoleHandler
ConsoleHandler ch = new ConsoleHandler();
ch.setLevel(Level.FINEST);
ch.setFormatter(new LoggerFormat());
// Add handler to logger and set level
rootLogger.addHandler(ch);
rootLogger.setLevel(Level.FINEST);
}