Java Utililty Methods Log to File

List of utility methods to do Log to File

Description

The list of methods to do Log to File are organized into topic(s).

Method

voidlogError(ILog log, String message)
Log the specified error.
logError(log, null, message);
voidlogError(String message)
log Error
getErrStream().println("!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!");
getErrStream().println(formatMessage(message));
getErrStream().println("!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!");
voidlogError(String msg)
log Error
System.err.println(getDateTime("yyyy-MM-dd HH:mm:ss") + ": " + msg);
voidlogErrPrint(String s)
logPrintErr() prints the String s to System.err with a timestamp indicating the hour and minute it was printed.
cal.setTimeInMillis(System.currentTimeMillis());
System.err
        .println(nf(cal.get(Calendar.HOUR_OF_DAY), 2) + ":" + nf(cal.get(Calendar.MINUTE), 2) + "|  " + s);
if (logger != null)
    logger.warning(s);
voidlogger(String s)
logger
System.out.println(formatter.format(new Date()) + " *** " + s);
voidloggerOld(String s)
logger Old
try {
    BufferedWriter out = new BufferedWriter(new FileWriter("snagr.log", true));
    Date d = new Date();
    String dt = formatter.format(d);
    String outTxt = dt + " *** " + s + "\n";
    System.out.print(outTxt);
    out.write(outTxt);
    out.close();
...
voidlogInfo(ILog log, String message)
Log the specified information.
logInfo(log, message, new Object[0]);
StringlogRecordToString(LogRecord record)
log Record To String
return new SimpleDateFormat("HH:mm:ss").format(record.getMillis()) + " [" + record.getLevel() + "] "
        + (record.getLoggerName() == null ? "" : "[" + record.getLoggerName() + "] ") + record.getMessage();
voidlogToFile(String filePath, String message)
If filepath is absolute, we append in that file If it is relative, we append in tmpDir+file.separator+filePath
String logsAbsoluteFilePath;
File testF = new File(filePath);
if (testF.isAbsolute())
    logsAbsoluteFilePath = filePath;
else {
    String tmpDirPath = System.getProperty("java.io.tmpdir");
    if (!tmpDirPath.endsWith(File.separator))
        tmpDirPath += File.separator;
...
voidlogToFile(String string, String logFile)
log To File
logToFile(string, logFile, true, true);