List of usage examples for java.util.logging FileHandler setEncoding
@Override public synchronized void setEncoding(String encoding) throws SecurityException, java.io.UnsupportedEncodingException
From source file:com.twitter.heron.common.utils.logging.LoggingHelper.java
/** * 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>//w ww . j a v a 2 s . c om * 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; }
From source file:nl.strohalm.cyclos.utils.logging.LoggingHandler.java
/** * Creates a new logger/* w w w . j a va2s . com*/ */ 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; }
From source file:org.apache.oodt.cas.pge.PGETaskInstance.java
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"); }/*w w w . j a va 2 s. c om*/ 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; }