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


Java FileHandler.setEncoding方法代码示例

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


在下文中一共展示了FileHandler.setEncoding方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: 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

示例2: logToFile

import java.util.logging.FileHandler; //导入方法依赖的package包/类
public static void logToFile(Logger logger, String name, Level level) {
    try {
        File aux = new File(".");
        String parent = aux.getCanonicalPath();
        File f = new File(parent + File.separator + "log");
        if (!f.isDirectory()) {
            boolean made = f.mkdir();
            if (!made) {
                logger.warning("Impossible to create log directory");
            }
        }
        String path = parent + File.separator + "log" + File.separator
                + name + "%u.log";
        FileHandler fh = new FileHandler(path);
        fh.setFormatter(new SimpleFormatter());
        fh.setEncoding("UTF-8");
        logger.addHandler(fh);
        logger.setLevel(level);
    } catch (IOException e) {
        logger.warning("Error configuring the log file.");
        e.printStackTrace();
    }
}
 
开发者ID:gsi-upm,项目名称:BeastTool,代码行数:24,代码来源:LogActivator.java

示例3: log2File

import java.util.logging.FileHandler; //导入方法依赖的package包/类
/**
 * Constructor
 * 
 */
public static void log2File(Logger logger, String name, Level fileHandlerLevel,
		Level consoleHandlerLevel, String dir) {
	try {
		File aux = new File(".");
		String parent = aux.getCanonicalPath();
		File f = new File(parent + File.separator + dir + File.separator + "logs");
		if (!f.isDirectory()) {
			boolean made = f.mkdirs();
			if (!made) {
				logger.warning("Impossible to create log directory");
				System.exit(1);
			}
		}
		logger.setUseParentHandlers(false);
		logger.setLevel(Level.ALL);
		String path = parent + File.separator + dir + File.separator + "logs" + File.separator
				+ name + "%u.log";
		int maxsizeMB = 20;
		int maxfiles = 20;
		FileHandler fh = new FileHandler(path, maxsizeMB * 1024 * 1000, maxfiles);
		fh.setFormatter(new SimpleFormatter());
		fh.setEncoding("UTF-8");
		fh.setLevel(fileHandlerLevel);
		logger.addHandler(fh);
		ConsoleHandler ch = new ConsoleHandler();
		ch.setFormatter(new SimpleFormatter());
		ch.setEncoding("UTF-8");
		ch.setLevel(consoleHandlerLevel);
		logger.addHandler(ch);
	} catch (IOException e) {
		logger.warning("Error configuring the log file.");
		logger.warning(e.getMessage());
		System.exit(1);
	}
}
 
开发者ID:gsi-upm,项目名称:BARMAS,代码行数:40,代码来源:LogConfigurator.java

示例4: createLogger

import java.util.logging.FileHandler; //导入方法依赖的package包/类
protected Logger createLogger() throws IOException, PGEException {
   File logDir = new File(pgeConfig.getExeDir(), "logs");
   if (!(logDir.exists() || logDir.mkdirs())) {
      throw new PGEException("mkdirs for logs directory return false");
   }

   Logger logger = Logger.getLogger(PGETaskInstance.class.getName()
         + "." + workflowInstId);
   FileHandler handler = new FileHandler(
         new File(logDir, createLogFileName()).getAbsolutePath());
   handler.setEncoding("UTF-8");
   handler.setFormatter(new SimpleFormatter());
   logger.addHandler(handler);
   return logger;
}
 
开发者ID:apache,项目名称:oodt,代码行数:16,代码来源:PGETaskInstance.java

示例5: getFileHandler

import java.util.logging.FileHandler; //导入方法依赖的package包/类
/**
 * Initialize a <tt>FileHandler</tt> to write to a set of files
 * with optional append.  When (approximately) the given limit has
 * been written to one file, another file will be opened.  The
 * output will cycle through a set of count files.
 * The pattern of file name should be: ${processId}.log.index
 * <p>
 * The <tt>FileHandler</tt> is configured based on <tt>LogManager</tt>
 * properties (or their default values) except that the given pattern
 * argument is used as the filename pattern, the file limit is
 * set to the limit argument, and the file count is set to the
 * given count argument, and the append mode is set to the given
 * <tt>append</tt> argument.
 * <p>
 * The count must be at least 1.
 *
 * @param limit the maximum number of bytes to write to any one file
 * @param count the number of files to use
 * @param append specifies append mode
 * @throws IOException if there are IO problems opening the files.
 * @throws SecurityException if a security manager exists and if
 * the caller does not have <tt>LoggingPermission("control")</tt>.
 * @throws IllegalArgumentException if {@code limit < 0}, or {@code count < 1}.
 * @throws IllegalArgumentException if pattern is an empty string
 */
public static FileHandler getFileHandler(String processId,
                                         String loggingDir,
                                         boolean append,
                                         ByteAmount limit,
                                         int count) throws IOException, SecurityException {

  String pattern = loggingDir + "/" + processId + ".log.%g";


  FileHandler fileHandler = new FileHandler(pattern, (int) limit.asBytes(), count, append);
  fileHandler.setFormatter(new SimpleFormatter());
  fileHandler.setEncoding(StandardCharsets.UTF_8.toString());

  return fileHandler;
}
 
开发者ID:twitter,项目名称:heron,代码行数:41,代码来源:LoggingHelper.java

示例6: log2File

import java.util.logging.FileHandler; //导入方法依赖的package包/类
/**
 * Constructor
 * 
 */
public static void log2File(Logger logger, String name, Level fileHandlerLevel, Level consoleHandlerLevel,
		String dir) {
	try {
		File aux = new File(".");
		String parent = aux.getCanonicalPath();
		File f;
		if (dir == null || dir.equals("") || dir.equals(".")) {
			f = new File(parent + File.separator + "logs");
		} else {
			f = new File(parent + File.separator + dir + File.separator + "logs");
		}
		if (!f.isDirectory()) {
			boolean made = f.mkdirs();
			if (!made) {
				logger.warning("Impossible to create log directory");
				System.exit(1);
			}
		}
		logger.setUseParentHandlers(false);
		logger.setLevel(Level.ALL);
		String path;
		if (dir == null || dir.equals("") || dir.equals(".")) {
			path = parent + File.separator + "logs" + File.separator + name + "%u.log";
		} else {
			path = parent + File.separator + dir + File.separator + "logs" + File.separator + name + "%u.log";
		}
		int maxsizeMB = 20;
		int maxfiles = 20;
		FileHandler fh = new FileHandler(path, maxsizeMB * 1024 * 1000, maxfiles);
		fh.setFormatter(new SimpleFormatter());
		fh.setEncoding("UTF-8");
		fh.setLevel(fileHandlerLevel);
		logger.addHandler(fh);
		ConsoleHandler ch = new ConsoleHandler();
		ch.setFormatter(new SimpleFormatter());
		ch.setEncoding("UTF-8");
		ch.setLevel(consoleHandlerLevel);
		logger.addHandler(ch);
	} catch (IOException e) {
		logger.warning("Error configuring the log file.");
		logger.warning(e.getMessage());
		System.exit(1);
	}
}
 
开发者ID:gsi-upm,项目名称:shanks-wsn-module,代码行数:49,代码来源:LogConfigurator.java


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