use of java.util.logging.FileHandler in project 360-Engine-for-Android by 360.
the class LogUtils method enableLogcat.
/**
* Enable logging.
*/
public static void enableLogcat() {
mEnabled = true;
/**
* Enable the SD Card logger *
*/
sLogger = Logger.getLogger(APP_NAME_PREFIX);
try {
FileHandler fileHandler = new FileHandler(APP_FILE_NAME, LOG_FILE_LIMIT, LOG_FILE_COUNT);
fileHandler.setFormatter(new Formatter() {
@Override
public String format(final LogRecord logRecord) {
StringBuilder sb = new StringBuilder();
sb.append(DATE_FORMAT.format(new Date(logRecord.getMillis())));
sb.append(" ");
sb.append(logRecord.getMessage());
sb.append("\n");
return sb.toString();
}
});
sLogger.addHandler(fileHandler);
} catch (IOException e) {
logE("LogUtils.logToFile() IOException, data will not be logged " + "to file", e);
sLogger = null;
}
if (Settings.ENABLED_PROFILE_ENGINES) {
/**
* Enable the SD Card profiler *
*/
sProfileLogger = Logger.getLogger("profiler");
try {
FileHandler fileHandler = new FileHandler("/sdcard/engineprofiler.log", LOG_FILE_LIMIT, LOG_FILE_COUNT);
fileHandler.setFormatter(new Formatter() {
@Override
public String format(final LogRecord logRecord) {
StringBuilder sb = new StringBuilder();
sb.append(DATE_FORMAT.format(new Date(logRecord.getMillis())));
sb.append("|");
sb.append(logRecord.getMessage());
sb.append("\n");
return sb.toString();
}
});
sProfileLogger.addHandler(fileHandler);
} catch (IOException e) {
logE("LogUtils.logToFile() IOException, data will not be logged " + "to file", e);
sProfileLogger = null;
}
}
}
use of java.util.logging.FileHandler in project malmo by Microsoft.
the class TCPUtils method setLogging.
public static void setLogging(SeverityLevel slevel) {
logging = slevel != SeverityLevel.LOG_NONE;
if (logging == true && filehandler == null) {
try {
Date d = new Date();
String filename = "TCP" + DateFormatUtils.format(d, "yyyy-MM-dd HH-mm-ss") + ".log";
filehandler = new FileHandler("logs" + File.separator + filename);
filehandler.setFormatter(new UTCFormatter());
} catch (SecurityException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
// Don't flood the parent log.
logger.setUseParentHandlers(false);
logger.addHandler(filehandler);
}
logger.setLevel(slevel.getLevel());
loggingSeverityLevel = slevel;
}
use of java.util.logging.FileHandler in project MyPet by xXKeyleXx.
the class MyPetLogger method setupDebugLogger.
protected boolean setupDebugLogger() {
if (getHandlers().length > 0) {
for (Handler h : getHandlers()) {
if (h.toString().equals("MyPet-Debug-Logger-FileHandler")) {
if (Configuration.Log.LEVEL.equalsIgnoreCase("OFF")) {
removeHandler(h);
h.close();
return false;
}
debugLogFileHandler = (FileHandler) h;
return true;
}
}
}
if (Configuration.Log.LEVEL.equalsIgnoreCase("OFF")) {
return false;
}
if (debugLogFileHandler != null) {
addHandler(debugLogFileHandler);
return true;
}
try {
File logsFolder = new File(MyPetApi.getPlugin().getDataFolder(), "logs");
logsFolder.mkdirs();
File logFile = new File(logsFolder, File.separator + "MyPet.log");
FileHandler fileHandler = new FileHandler(logFile.getAbsolutePath(), true) {
@Override
public String toString() {
return "MyPet-Debug-Logger-FileHandler";
}
};
Level level;
try {
level = Level.parse(Configuration.Log.LEVEL);
} catch (IllegalArgumentException e) {
level = Level.OFF;
this.warning(e.getMessage());
}
fileHandler.setLevel(level);
System.out.println("Level: " + level);
fileHandler.setFormatter(new LogFormat());
addHandler(fileHandler);
debugLogFileHandler = fileHandler;
return true;
} catch (IOException e) {
e.printStackTrace();
return false;
}
}
use of java.util.logging.FileHandler in project Payara by payara.
the class LoggingAnnotationsTest method initializeLoggingAnnotationsTest.
@BeforeClass
public static void initializeLoggingAnnotationsTest() throws Exception {
File basePath = new File(BASE_PATH);
basePath.mkdirs();
// Add a file handler with UniformLogFormatter
uniformFormatHandler = new FileHandler(ULF_LOG);
uniformFormatHandler.setLevel(Level.FINE);
uniformFormatHandler.setFormatter(new UniformLogFormatter());
// Add a file handler with ODLLogFormatter
odlFormatHandler = new FileHandler(ODL_LOG);
odlFormatHandler.setLevel(Level.FINE);
odlFormatHandler.setFormatter(new ODLLogFormatter());
consoleHandler = new ConsoleHandler();
consoleHandler.setFormatter(new UniformLogFormatter());
LOGGER.addHandler(uniformFormatHandler);
LOGGER.addHandler(odlFormatHandler);
Boolean enableConsoleHandler = Boolean.getBoolean(LoggingAnnotationsTest.class.getName() + ".enableConsoleHandler");
if (enableConsoleHandler) {
LOGGER.addHandler(consoleHandler);
}
LOGGER.setUseParentHandlers(false);
LOGGER.setLevel(Level.FINE);
}
Aggregations