Java Log Message logLine(String filePath, String line)

Here you can find the source of logLine(String filePath, String line)

Description

log Line

License

Apache License

Declaration

public static void logLine(String filePath, String line) 

Method Source Code

//package com.java2s;
//License from project: Apache License 

import java.io.BufferedWriter;

import java.io.FileWriter;
import java.io.IOException;

import java.util.Date;

public class Main {
    public static void logLine(String filePath, String line) {
        if (filePath == null) {
            String log = (new Date()) + " : " + line + "\n";
            System.out.print(log);
        } else {/*from www  .  j  a  v  a 2 s.co  m*/
            try {

                BufferedWriter writer = new BufferedWriter(new FileWriter(filePath, true));
                //            writer.write((new Date())+" : "+line+"\n");
                writer.write(line + "\n");
                writer.flush();
                writer.close();
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
    }

    public static void logLine(String line) {
        logLine(null, line);
    }
}

Related

  1. log(String message)
  2. log(String message)
  3. log(String message, PrintStream out)
  4. log(String msg)
  5. LOG(String msg, PrintWriter writer)
  6. logMessage(String message)
  7. LogMsg(PrintStream logger, String msg)
  8. logMsg(String msg)
  9. LogMsg(String s)