本文整理汇总了Java中java.util.logging.FileHandler.setLevel方法的典型用法代码示例。如果您正苦于以下问题:Java FileHandler.setLevel方法的具体用法?Java FileHandler.setLevel怎么用?Java FileHandler.setLevel使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类java.util.logging.FileHandler
的用法示例。
在下文中一共展示了FileHandler.setLevel方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: Server
import java.util.logging.FileHandler; //导入方法依赖的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: AptaLogger
import java.util.logging.FileHandler; //导入方法依赖的package包/类
private AptaLogger() throws IOException{
//instance the file handler
filepath = Paths.get(Configuration.getParameters().getString("Experiment.projectPath"), "log_" + formatter.format(new Date()) + ".txt").toString();
fileHandler = new FileHandler(filepath,true);
fileHandler.setLevel(Level.ALL); // We want everything logged on file
//instance the logger
logger = Logger.getLogger(AptaLogger.class.getName());
logger.setUseParentHandlers(false);
logger.setLevel(Level.ALL);
//instance formatter, set formatting, and handler
formatterTxt = new AptaLoggerFormat();
fileHandler.setFormatter(formatterTxt);
logger.addHandler(fileHandler);
}
示例3: LogService
import java.util.logging.FileHandler; //导入方法依赖的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.FileHandler; //导入方法依赖的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.FileHandler; //导入方法依赖的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.FileHandler; //导入方法依赖的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: main
import java.util.logging.FileHandler; //导入方法依赖的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");
}
}
示例8: addNewSeleniumFileHandler
import java.util.logging.FileHandler; //导入方法依赖的package包/类
private static File addNewSeleniumFileHandler(Logger currentLogger,
LoggingOptions options) {
try {
FileHandler fileHandler;
final File logFile;
logFile = options.getLogOutFile();
fileHandler = seleniumFileHandlers.get(logFile);
if (fileHandler == null) {
fileHandler = registerNewSeleniumFileHandler(logFile);
}
fileHandler.setFormatter(new TerseFormatter(true));
currentLogger.setLevel(Level.FINE);
fileHandler.setLevel(Level.FINE);
currentLogger.addHandler(fileHandler);
return logFile;
} catch (IOException e) {
throw new RuntimeException(e);
}
}
示例9: setupLogging
import java.util.logging.FileHandler; //导入方法依赖的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);
}
}
示例10: setupLogging
import java.util.logging.FileHandler; //导入方法依赖的package包/类
public static void setupLogging(boolean logToConsole, String logFile) throws Exception {
// Setup the logging
System.setProperty(
"java.util.logging.SimpleFormatter.format",
"%1$tY-%1$tm-%1$td %1$tH:%1$tM:%1$tS: %4$s: %5$s%n%6$s%n");
LogManager.getLogManager().reset();
Logger rootLogger = Logger.getLogger("");
if(logFile != null) {
FileHandler logHandler = new FileHandler(logFile, 8*1024*1024, 2, true);
logHandler.setFormatter(new SimpleFormatter());
logHandler.setLevel(Level.FINEST);
rootLogger.addHandler(logHandler);
}
if(logToConsole) {
ConsoleHandler consoleHandler = new ConsoleHandler();
consoleHandler.setFormatter(new SimpleFormatter());
consoleHandler.setLevel(Level.INFO);
rootLogger.addHandler(consoleHandler);
}
rootLogger.setLevel(Level.INFO);
}
示例11: initLog
import java.util.logging.FileHandler; //导入方法依赖的package包/类
private static void initLog()
{
Formatter simpleFormatter;
try
{
String path = new File(".").getCanonicalPath();
String logName = String.valueOf(System.currentTimeMillis());
simpleFormatter = new SimpleFormatter();
fileHandler = new FileHandler(path + logName + ".log");
fileHandler.setFormatter(simpleFormatter);
fileHandler.setLevel(Level.ALL);
}
catch (IOException e)
{
errorLog.log(Level.WARNING, e.getMessage(), e);
}
}
示例12: LogService
import java.util.logging.FileHandler; //导入方法依赖的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());
}
}
}
示例13: createHandler
import java.util.logging.FileHandler; //导入方法依赖的package包/类
@SuppressLint("SimpleDateFormat")
protected FileHandler createHandler(String finalPath) throws IOException {
FileHandler h = new FileHandler(finalPath, MAX_SIZE, 3, true);
final DateFormat format = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSS");
final String sep = System.getProperty("line.separator");
h.setFormatter(new Formatter() {
@Override
public String format(LogRecord r) {
String date = format.format(new Date(r.getMillis()));
return String.format(Locale.US, "%s [%s]: (%d) %s%s", date, r.getLevel(), r.getThreadID(), r.getMessage(), sep);
}
});
h.setLevel(Level.ALL);
return h;
}
示例14: config
import java.util.logging.FileHandler; //导入方法依赖的package包/类
/**
* Configure Logger
*
* @throws IOException
*/
protected void config() throws IOException
{
if( Boolean.parseBoolean(this.config.get("log_console_status", "false")) ){
consoleHandler = new ConsoleHandler();
log.addHandler(consoleHandler);
if( this.config.get("log_console_level", "SEVERE").equals("ALL") ){
consoleHandler.setLevel(Level.ALL);
}else if( this.config.get("log_console_level", "SEVERE").equals("CONFIG") ){
consoleHandler.setLevel(Level.CONFIG);
}else if( this.config.get("log_console_level", "SEVERE").equals("FINE") ){
consoleHandler.setLevel(Level.FINE);
}else if( this.config.get("log_console_level", "SEVERE").equals("FINER") ){
consoleHandler.setLevel(Level.FINER);
}else if( this.config.get("log_console_level", "SEVERE").equals("FINEST") ){
consoleHandler.setLevel(Level.FINEST);
}else if( this.config.get("log_console_level", "SEVERE").equals("INFO") ){
consoleHandler.setLevel(Level.INFO);
}else if( this.config.get("log_console_level", "SEVERE").equals("OFF") ){
consoleHandler.setLevel(Level.OFF);
}else if( this.config.get("log_console_level", "SEVERE").equals("SEVERE") ){
consoleHandler.setLevel(Level.SEVERE);
}else if( this.config.get("log_console_level", "SEVERE").equals("WARNING") ){
consoleHandler.setLevel(Level.WARNING);
}
}
if( Boolean.parseBoolean(this.config.get("log_file_status", "false")) ){
fileHandler = new FileHandler(this.config.get("log_file_path", "src/main/java/resources/app.log"),
Integer.parseInt(this.config.get("log_file_limit", "1")),
Integer.parseInt(this.config.get("log_file_count", "200000")),
Boolean.parseBoolean(this.config.get("log_file_append", "true"))
);
log.addHandler(fileHandler);
if( this.config.get("log_file_level", "SEVERE").equals("ALL") ){
fileHandler.setLevel(Level.ALL);
}else if( this.config.get("log_file_level", "SEVERE").equals("CONFIG") ){
fileHandler.setLevel(Level.CONFIG);
}else if( this.config.get("log_file_level", "SEVERE").equals("FINE") ){
fileHandler.setLevel(Level.FINE);
}else if( this.config.get("log_file_level", "SEVERE").equals("FINER") ){
fileHandler.setLevel(Level.FINER);
}else if( this.config.get("log_file_level", "SEVERE").equals("FINEST") ){
fileHandler.setLevel(Level.FINEST);
}else if( this.config.get("log_file_level", "SEVERE").equals("INFO") ){
fileHandler.setLevel(Level.INFO);
}else if( this.config.get("log_file_level", "SEVERE").equals("OFF") ){
fileHandler.setLevel(Level.OFF);
}else if( this.config.get("log_file_level", "SEVERE").equals("SEVERE") ){
fileHandler.setLevel(Level.SEVERE);
}else if( this.config.get("log_file_level", "SEVERE").equals("WARNING") ){
fileHandler.setLevel(Level.WARNING);
}
}
}
示例15: initLogs
import java.util.logging.FileHandler; //导入方法依赖的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);
}
}