当前位置: 首页>>代码示例>>Java>>正文


Java FileHandler类代码示例

本文整理汇总了Java中java.util.logging.FileHandler的典型用法代码示例。如果您正苦于以下问题:Java FileHandler类的具体用法?Java FileHandler怎么用?Java FileHandler使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


FileHandler类属于java.util.logging包,在下文中一共展示了FileHandler类的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();
	}
}
 
开发者ID:ericaddison,项目名称:Dist_HW_2,代码行数:41,代码来源:Server.java

示例2: main

import java.util.logging.FileHandler; //导入依赖的package包/类
public static void main(String[] args) 
{
	try 
	{
		LogManager lm = LogManager.getLogManager();
		Logger logger = Logger.getLogger("BasicLogging");
		FileHandler fh = new FileHandler("log_test.txt");
		lm.addLogger(logger);
		logger.addHandler(fh);
		logger.log(Level.INFO, "test 1");
		logger.log(Level.INFO, "test 2");
		fh.close();
	}
	catch (Exception e) {
		System.err.println("Exception thrown: " + e);
		e.printStackTrace();
	}
}
 
开发者ID:shuqin,项目名称:ALLIN,代码行数:19,代码来源:BasicLogging.java

示例3: testFileHandlerClose

import java.util.logging.FileHandler; //导入依赖的package包/类
private static void testFileHandlerClose(File writableDir) throws IOException {
    File fakeLock = new File(writableDir, "log.log.lck");
    if (!createFile(fakeLock, false)) {
        throw new IOException("Can't create fake lock file: " + fakeLock);
    }
    try {
        List<File> before = listLocks(writableDir, true);
        System.out.println("before: " + before.size() + " locks found");
        FileHandler handler = createFileHandler(writableDir);
        System.out.println("handler created: " + handler);
        List<File> after = listLocks(writableDir, true);
        System.out.println("after creating handler: " + after.size() + " locks found");
        handler.close();
        System.out.println("handler closed: " + handler);
        List<File> afterClose = listLocks(writableDir, true);
        System.out.println("after closing handler: " + afterClose.size() + " locks found");
        afterClose.removeAll(before);
        if (!afterClose.isEmpty()) {
            throw new RuntimeException("Zombie lock file detected: " + afterClose);
        }
    } finally {
        if (fakeLock.canRead()) delete(fakeLock);
    }
    List<File> finalLocks = listLocks(writableDir, false);
    System.out.println("After cleanup: " + finalLocks.size() + " locks found");
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:27,代码来源:CheckZombieLockTest.java

示例4: 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);

}
 
开发者ID:drivenbyentropy,项目名称:aptasuite,代码行数:20,代码来源:AptaLogger.java

示例5: 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());
		}
	}
}
 
开发者ID:transwarpio,项目名称:rapidminer,代码行数:18,代码来源:LogService.java

示例6: 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;
}
 
开发者ID:LouisJenkinsCS,项目名称:Code-Glosser,代码行数:25,代码来源:Globals.java

示例7: 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);
}
 
开发者ID:gemxd,项目名称:gemfirexd-oss,代码行数:17,代码来源:GemFireXDDataExtractorImpl.java

示例8: 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);
}
 
开发者ID:isse-augsburg,项目名称:minibrass,代码行数:25,代码来源:MiniBrassCompiler.java

示例9: init

import java.util.logging.FileHandler; //导入依赖的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;
}
 
开发者ID:mateli,项目名称:OpenCyclos,代码行数:28,代码来源:LoggingHandlerImpl.java

示例10: 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");
   }
}
 
开发者ID:LibreOffice,项目名称:noa-libre,代码行数:35,代码来源:OfficeBeanTest.java

示例11: 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);
  }
}
 
开发者ID:alexkogon,项目名称:grid-refactor-remote-server,代码行数:21,代码来源:LoggingManager.java

示例12: 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);
    }

}
 
开发者ID:OgarProject,项目名称:Ogar2-Server,代码行数:31,代码来源:OgarServer.java

示例13: 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);
}
 
开发者ID:ivannp,项目名称:tradelib,代码行数:24,代码来源:Utils.java

示例14: 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);
	}
}
 
开发者ID:bisguard,项目名称:bisdk,代码行数:19,代码来源:Test.java

示例15: main

import java.util.logging.FileHandler; //导入依赖的package包/类
public static void main(String[] args) throws IOException {

        /* Ensure directory has been created */
        new File("logs").mkdir();

        /* Get the date to be used in the filename */
        DateFormat df = new SimpleDateFormat("yyyyMMddhhmmss");
        Date now = new Date();
        String date = df.format(now);

        /* Set up the filename in the logs directory */
        String logFileName = "logs/testlog-" + date + ".txt";

        /* Set up logger */
        FileHandler myFileHandler = new FileHandler(logFileName);
        myFileHandler.setFormatter(new SimpleFormatter());
        Logger ocajLogger = Logger.getLogger("OCAJ Logger");
        ocajLogger.setLevel(Level.ALL);
        ocajLogger.addHandler(myFileHandler);

        /* Log Message */
        ocajLogger.info("\nThis is a logged information message.");

        /* Close the file */
        myFileHandler.close();
    }
 
开发者ID:mdeverdelhan,项目名称:OCA-Java-SE-7-Programmer-I,代码行数:27,代码来源:TestClass.java


注:本文中的java.util.logging.FileHandler类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。