Skip to content
Permalink
Browse files

Create Log.java

  • Loading branch information...
ShoutingCat committed Feb 24, 2019
0 parents commit b9a6f40ca91f095aa0a93cdf503d913847483022
Showing with 51 additions and 0 deletions.
  1. +51 −0 src/com/megabit/utils/log/Log.java
@@ -0,0 +1,51 @@
package com.megabit.utils.log;
import java.io.File;
import java.io.FileWriter;
import java.io.IOException;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;

public class Log {

static public boolean OPTION_TIMEON = false;
static SimpleDateFormat ft = new SimpleDateFormat ("[yyyy.MM.dd hh:mm:ss] : ");

static public void write(String msg, String filepath){

File file = new File(filepath);
FileWriter writer = null;

try{
// Using continuously writing
writer = new FileWriter(file, true);

// Adding Time format
if(OPTION_TIMEON){
Date dNow = new Date( );
writer.write(ft.format(dNow));
}
writer.write(msg);
writer.write("\r\n");
writer.flush();

// Abb.println("Done");
}catch(IOException e){
e.printStackTrace();
}finally{
try {
if(writer != null) writer.close();
} catch(IOException e){
e.printStackTrace();
}
}

}

static public void write(String msg, String... filepathes){
for(String filepath : filepathes){
write(msg, filepath);
}
}

}

0 comments on commit b9a6f40

Please sign in to comment.
You can’t perform that action at this time.