This commit is contained in:
Flare Microsystems
2024-03-06 14:24:23 -08:00
parent 0fb5900a78
commit 3e225d4078
20 changed files with 1370 additions and 103 deletions

View 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 "";
}
}

View 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 = "";
}
}