本文整理匯總了Java中java.util.logging.SimpleFormatter類的典型用法代碼示例。如果您正苦於以下問題:Java SimpleFormatter類的具體用法?Java SimpleFormatter怎麽用?Java SimpleFormatter使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。
SimpleFormatter類屬於java.util.logging包,在下文中一共展示了SimpleFormatter類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: Server
import java.util.logging.SimpleFormatter; //導入依賴的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: createLogger
import java.util.logging.SimpleFormatter; //導入依賴的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;
}
示例3: LogService
import java.util.logging.SimpleFormatter; //導入依賴的package包/類
private LogService(Logger logger) {
super(logger);
// setup a log file if the execution mode can access the filesystem (e.g. not for RA)
// we want our logfile to look the same regardless of any user settings, so ignore
// a possible user logging property config file
if (RapidMiner.getExecutionMode().canAccessFilesystem()) {
try {
FileHandler logFileHandler = new FileHandler(FileSystemService.getLogFile().getAbsolutePath(), false);
logFileHandler.setLevel(Level.ALL);
logFileHandler.setFormatter(new SimpleFormatter());
LogService.getRoot().addHandler(logFileHandler);
} catch (IOException e) {
LogService.getRoot().log(Level.WARNING, "com.rapidminer.logservice.logfile.failed_to_init", e.getMessage());
}
}
}
示例4: initGlobals
import java.util.logging.SimpleFormatter; //導入依賴的package包/類
/**
* Initializes all globals to a default state. Used so that in the case of a
* memory leak, the previous values are not accidentally used.
*/
public static void initGlobals() {
System.setProperty("java.util.logging.SimpleFormatter.format",
"(%1$tc) [%4$s] ~%2$s~%nMessage: \"%5$s\"%n");
try {
handler = new FileHandler("log.txt");
handler.setLevel(Level.INFO);
handler.setFormatter(new SimpleFormatter());
// Ensure we only log to log file.
LOGGER.setUseParentHandlers(false);
LOGGER.addHandler(handler);
LOGGER.setLevel(Level.INFO);
} catch (IOException | SecurityException ex) {
throw new RuntimeException("Failed to initialized logger... " + ex.getMessage());
}
PROJECT_FOLDER = null;
URI_PREFIX = null;
CURRENT_FILE = null;
}
示例5: configureLogger
import java.util.logging.SimpleFormatter; //導入依賴的package包/類
protected void configureLogger() throws SecurityException, IOException {
if (logger == null) {
logger = Logger.getLogger(LOGGER_NAME);
}
logger.setUseParentHandlers(false);
logFileHandler = new FileHandler(logFilePath);
logFileHandler.setFormatter(new SimpleFormatter());
Level logLevel = Level.INFO;
try {
logLevel = Level.parse(logLevelString);
} catch (IllegalArgumentException e) {
logInfo("Unrecognized log level :" + logLevelString + " defaulting to :" + logLevel);
}
logFileHandler.setLevel(logLevel);
logger.addHandler(logFileHandler);
}
示例6: main
import java.util.logging.SimpleFormatter; //導入依賴的package包/類
public static void main(String[] args) throws SecurityException, IOException {
Logger logger = Logger.getGlobal();
logger.setLevel(Level.FINER);
System.setProperty("java.util.logging.SimpleFormatter.format", "%1$tF %1$tT %4$s %2$s %5$s%6$s%n");
SimpleFormatter formatterTxt = new SimpleFormatter();
FileHandler logFile = new FileHandler("log2.txt");
logFile.setLevel(Level.FINER);
logFile.setFormatter(formatterTxt);
logger.addHandler(logFile);
// Create and set handler
Handler systemOut = new StdoutConsoleHandler();
systemOut.setLevel(Level.ALL);
logger.addHandler(systemOut);
logger.setLevel(Level.SEVERE);
// Prevent logs from processed by default Console handler.
logger.setUseParentHandlers(false); // Solution 1
new MiniBrassCompiler().doMain(args);
}
示例7: setupLogger
import java.util.logging.SimpleFormatter; //導入依賴的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: setupLogger
import java.util.logging.SimpleFormatter; //導入依賴的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);
}
示例9: testConstructor_InvalidProperties
import java.util.logging.SimpleFormatter; //導入依賴的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());
}
示例10: enableHttp2FrameLogging
import java.util.logging.SimpleFormatter; //導入依賴的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);
}
示例11: LoggingConfig
import java.util.logging.SimpleFormatter; //導入依賴的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();
}
}
示例12: ServerRunner
import java.util.logging.SimpleFormatter; //導入依賴的package包/類
/**
* Constructor.
*/
public ServerRunner() {
log.setLevel(Level.ALL);
ConsoleHandler handler = new ConsoleHandler();
handler.setFormatter(new SimpleFormatter());
handler.setLevel(Level.ALL);
log.addHandler(handler);
}
示例13: getLogger
import java.util.logging.SimpleFormatter; //導入依賴的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;
}
示例14: initLogs
import java.util.logging.SimpleFormatter; //導入依賴的package包/類
/**
* 初始化日誌記錄
*/
private void initLogs() {
try {
File file = new File(System.getProperty("user.dir") + "/logs");
if (!file.exists()) {
file.mkdirs();
}
FileHandler fileHandler = new FileHandler(file.getPath() + "/log.log");
fileHandler.setLevel(Level.ALL);
fileHandler.setFormatter(new SimpleFormatter());
LOGGER.addHandler(fileHandler);
} catch (Exception ex) {
LOGGER.log(Level.SEVERE, null, ex);
}
}
示例15: init
import java.util.logging.SimpleFormatter; //導入依賴的package包/類
@PostConstruct
public void init() {
try {
File log = new File(logFile);
File parentDir = log.getParentFile();
if (!parentDir.exists()) {
parentDir.mkdirs();
}
FileHandler fh = new FileHandler(logFile);
logger.addHandler(fh);
SimpleFormatter formatter = new SimpleFormatter();
fh.setFormatter(formatter);
} catch (Exception e) {
throw new WebApplicationException(e, Response.Status.INTERNAL_SERVER_ERROR);
}
}