???
This commit is contained in:
31
src/com/flaremicro/util/logging/LogFormatter.java
Normal file
31
src/com/flaremicro/util/logging/LogFormatter.java
Normal file
@@ -0,0 +1,31 @@
|
||||
package com.flaremicro.util.logging;
|
||||
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.logging.Formatter;
|
||||
import java.util.logging.Handler;
|
||||
import java.util.logging.Level;
|
||||
import java.util.logging.LogRecord;
|
||||
|
||||
|
||||
public class LogFormatter extends Formatter {
|
||||
String sep = System.getProperty("line.separator");
|
||||
SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
|
||||
@Override
|
||||
public String format(LogRecord record) {
|
||||
String fmessage = "";
|
||||
if(record.getLevel() == Level.SEVERE)
|
||||
fmessage += "["+format.format(System.currentTimeMillis())+"][SEVERE]";
|
||||
else if(record.getLevel() == Level.WARNING)
|
||||
fmessage += "["+format.format(System.currentTimeMillis())+"][WARNING]";
|
||||
else if(record.getLevel() == Level.INFO)
|
||||
fmessage += "["+format.format(System.currentTimeMillis())+"][INFO]";
|
||||
return fmessage += this.formatMessage(record) + sep;
|
||||
}
|
||||
public String getHead(Handler h) {
|
||||
return "";
|
||||
}
|
||||
|
||||
public String getTail(Handler h) {
|
||||
return "";
|
||||
}
|
||||
}
|
||||
38
src/com/flaremicro/util/logging/LogOutputStream.java
Normal file
38
src/com/flaremicro/util/logging/LogOutputStream.java
Normal file
@@ -0,0 +1,38 @@
|
||||
package com.flaremicro.util.logging;
|
||||
|
||||
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.OutputStream;
|
||||
import java.util.logging.Level;
|
||||
import java.util.logging.Logger;
|
||||
|
||||
public class LogOutputStream extends OutputStream {
|
||||
|
||||
String buffer = "";
|
||||
Logger logger;
|
||||
Level level;
|
||||
|
||||
public LogOutputStream(Logger logger, Level level)
|
||||
{
|
||||
this.logger = logger;
|
||||
this.level = level;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void write(int b) throws IOException {
|
||||
buffer += (char)((byte)b);
|
||||
if(buffer.endsWith("\n") || buffer.endsWith("\r\n"))
|
||||
{
|
||||
buffer = buffer.replace("\r", "").replace("\n", "");
|
||||
flush();
|
||||
}
|
||||
}
|
||||
|
||||
public void flush()
|
||||
{
|
||||
logger.log(level, buffer);
|
||||
buffer = "";
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user