本文整理汇总了Java中java.util.logging.Handler.setFormatter方法的典型用法代码示例。如果您正苦于以下问题:Java Handler.setFormatter方法的具体用法?Java Handler.setFormatter怎么用?Java Handler.setFormatter使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类java.util.logging.Handler
的用法示例。
在下文中一共展示了Handler.setFormatter方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getLogger
import java.util.logging.Handler; //导入方法依赖的package包/类
/**
* Creates a static {@code Logger} instance.
*
* @return a static {@code Logger} with properties:
* <ul>
* <li>Name: {@code "DefaultDatabaseConfigurator"}.</li>
* <li>Output file pattern:
* {@code user.home/.kawansoft/log/AceQL.log}.</li>
* <li>Formatter: {@code SimpleFormatter}.</li>
* <li>Limit: 200Mb.</li>
* <li>Count (number of files to use): 2.</li>
* </ul>
*/
@Override
public Logger getLogger() throws IOException {
if (ACEQL_LOGGER != null) {
return ACEQL_LOGGER;
}
File logDir = new File(SystemUtils.USER_HOME + File.separator + ".kawansoft" + File.separator + "log");
logDir.mkdirs();
String pattern = logDir.toString() + File.separator + "AceQL.log";
ACEQL_LOGGER = Logger.getLogger(DefaultDatabaseConfigurator.class.getName());
Handler fh = new FileHandler(pattern, 200 * 1024 * 1024, 2, true);
fh.setFormatter(new SimpleFormatter());
ACEQL_LOGGER.addHandler(fh);
return ACEQL_LOGGER;
}
示例2: AswLogger
import java.util.logging.Handler; //导入方法依赖的package包/类
private AswLogger() {
LogManager logManager = LogManager.getLogManager();
try {
logManager.readConfiguration(new FileInputStream(LOGGING_CONFIG_FILE));
} catch (Exception e) {
/* di solito l'eccezione si verifica perche' non trova il file logging.properties */
/* Stampa il messaggio dell'eccezione */
// System.err.println(e);
/* definisce una configurazione alternativa */
logManager.reset();
Handler handler = new ConsoleHandler();
handler.setFormatter( new TextFormatter() );
Logger.getLogger("").addHandler( handler );
}
}
示例3: setupLoggers
import java.util.logging.Handler; //导入方法依赖的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());
}
示例4: setupDefaultConsoleLogger
import java.util.logging.Handler; //导入方法依赖的package包/类
public static void setupDefaultConsoleLogger() {
Handler[] hs = Logger.getLogger("").getHandlers();
for (int i = 0; i < hs.length; i++) {
Logger.getLogger("").removeHandler(hs[i]);
}
Handler h = new ConsoleHandler();
h.setFormatter(new MASConsoleLogFormatter());
Logger.getLogger("").addHandler(h);
Logger.getLogger("").setLevel(Level.INFO);
}
示例5: initLogging
import java.util.logging.Handler; //导入方法依赖的package包/类
public static void initLogging(InputStream ins) throws IOException {
LogManager.getLogManager().readConfiguration(ins);
Logger rootLogger = LogManager.getLogManager().getLogger("");
Handler[] handlers = rootLogger.getHandlers();
for (Handler handler : handlers) {
handler.setFormatter(new LogFormatter());
}
}
示例6: log
import java.util.logging.Handler; //导入方法依赖的package包/类
public static void log(ChessBoard cb, Throwable t) {
try {
// print to System.out
t.printStackTrace(System.out);
// setup logger
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd_HH.mm.ss.SSS");
String completeFilePath = "%t/" + "chess22k_" + sdf.format(new Date()) + ".log";
Handler fh = new FileHandler(completeFilePath, true);
fh.setFormatter(new SimpleFormatter());
logger.addHandler(fh);
// redirect System.out
ByteArrayOutputStream baos = new ByteArrayOutputStream();
PrintStream ps = new PrintStream(baos);
System.setOut(ps);
// print info
System.out.println("");
System.out.println("");
System.out.println("start fen");
System.out.println(MainEngine.startFen);
System.out.println("");
System.out.println("crashed fen");
System.out.println(cb);
System.out.println("");
Statistics.print();
System.out.flush();
// print exception
logger.info(baos.toString());
logger.log(Level.SEVERE, "An exception occurred", t);
} catch (IOException e) {
e.printStackTrace();
} finally {
System.exit(1);
}
}
示例7: getPackageLogger
import java.util.logging.Handler; //导入方法依赖的package包/类
private Logger getPackageLogger() {
if (logger == null) {
String prop = System.getProperty(packageName, DEFAULT_NAME);
for (int i = 1; i < LEVELS.length; i++) {
if (prop.toLowerCase().equals(LEVEL_NAMES[i].toLowerCase())) {
level = LEVELS[i];
break;
}
}
LogManager.getLogManager().addLogger(new Logger(packageName, null)
{});
logger = LogManager.getLogManager().getLogger(packageName);
if (logger == null) {
System.out.println(packageName + ": "
+ rb.getString("CANT_GET_LOGGER"));
return Logger.getLogger("global");
}
try {
logger.setLevel(level);
Handler handler = new ConsoleHandler();
handler.setLevel(level);
// Default handlers don't provide class name or method name, so roll our own
logger.setUseParentHandlers(false);
Formatter formatter = new Formatter() {
public String format(LogRecord record) {
StringBuffer s = new StringBuffer();
s.append(record.getLevel().getLocalizedName());
s.append(' ');
if (record.getLoggerName() != null) {
s.append('[');
s.append(record.getLoggerName());
s.append("]: ");
}
if (record.getSourceClassName() != null) {
s.append("| ");
if (record.getLevel().equals(Level.FINEST)) {
String className = record.getSourceClassName();
s.append(className.substring(Math.max(className.lastIndexOf('.')+1,0)));
} else {
s.append(record.getSourceClassName());
}
s.append(' ');
}
if (record.getSourceMethodName() != null) {
s.append("| ");
s.append(record.getSourceMethodName());
s.append("( ");
Object[] parms = record.getParameters();
if (parms != null) {
for (int i = 0; i < parms.length; i++) {
if (i != 0) {
s.append(", ");
}
s.append(parms[i]);
}
}
s.append(" ) ");
}
if (record.getThrown() != null) {
s.append("| ");
s.append(record.getThrown());
}
if (record.getMessage() != null) {
s.append('|');
s.append(record.getMessage());
}
s.append('\n');
return s.toString();
}
};
handler.setFormatter(formatter);
logger.addHandler(handler);
}
catch (SecurityException e) {
}
}
return logger;
}
示例8: init
import java.util.logging.Handler; //导入方法依赖的package包/类
/**
* Configures JDK logging to use this class for everything
*/
static void init() {
Handler[] handlers = logger.getHandlers();
for (Handler handler : handlers)
handler.setFormatter(briefLogFormatter);
}