本文整理匯總了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;
}
示例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();
}
}
示例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);
}
}
示例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;
}
示例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;
}
示例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);
}
}