www in docker support
This commit is contained in:
parent
539a848e95
commit
c227fce036
2145 changed files with 399596 additions and 58 deletions
|
|
@ -0,0 +1,16 @@
|
|||
package org.jcodec.common.logging;
|
||||
|
||||
import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
|
||||
public class BufferLogSink implements LogSink {
|
||||
private List<Message> messages = new LinkedList<>();
|
||||
|
||||
public void postMessage(Message msg) {
|
||||
this.messages.add(msg);
|
||||
}
|
||||
|
||||
public List<Message> getMessages() {
|
||||
return this.messages;
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,5 @@
|
|||
package org.jcodec.common.logging;
|
||||
|
||||
public enum LogLevel {
|
||||
DEBUG, INFO, WARN, ERROR;
|
||||
}
|
||||
|
|
@ -0,0 +1,5 @@
|
|||
package org.jcodec.common.logging;
|
||||
|
||||
public interface LogSink {
|
||||
void postMessage(Message paramMessage);
|
||||
}
|
||||
|
|
@ -0,0 +1,81 @@
|
|||
package org.jcodec.common.logging;
|
||||
|
||||
import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
|
||||
public class Logger {
|
||||
private static List<LogSink> stageSinks = new LinkedList<>();
|
||||
|
||||
private static List<LogSink> sinks;
|
||||
|
||||
public static void debug(String message) {
|
||||
message(LogLevel.DEBUG, message, null);
|
||||
}
|
||||
|
||||
public static void debug(String message, Object... args) {
|
||||
message(LogLevel.DEBUG, message, args);
|
||||
}
|
||||
|
||||
public static void info(String message) {
|
||||
message(LogLevel.INFO, message, null);
|
||||
}
|
||||
|
||||
public static void info(String message, Object... args) {
|
||||
message(LogLevel.INFO, message, args);
|
||||
}
|
||||
|
||||
public static void warn(String message) {
|
||||
message(LogLevel.WARN, message, null);
|
||||
}
|
||||
|
||||
public static void warn(String message, Object... args) {
|
||||
message(LogLevel.WARN, message, args);
|
||||
}
|
||||
|
||||
public static void error(String message) {
|
||||
message(LogLevel.ERROR, message, null);
|
||||
}
|
||||
|
||||
public static void error(String message, Object... args) {
|
||||
message(LogLevel.ERROR, message, args);
|
||||
}
|
||||
|
||||
private static void message(LogLevel level, String message, Object[] args) {
|
||||
Message msg;
|
||||
if (globalLogLevel.ordinal() >= level.ordinal())
|
||||
return;
|
||||
if (sinks == null)
|
||||
synchronized (Logger.class) {
|
||||
if (sinks == null) {
|
||||
sinks = stageSinks;
|
||||
stageSinks = null;
|
||||
if (sinks.isEmpty())
|
||||
sinks.add(OutLogSink.createOutLogSink());
|
||||
}
|
||||
}
|
||||
if (LogLevel.DEBUG.equals(globalLogLevel)) {
|
||||
StackTraceElement tr = Thread.currentThread().getStackTrace()[3];
|
||||
msg = new Message(level, tr.getFileName(), tr.getClassName(), tr.getMethodName(), tr.getLineNumber(), message, args);
|
||||
} else {
|
||||
msg = new Message(level, "", "", "", 0, message, args);
|
||||
}
|
||||
for (LogSink logSink : sinks)
|
||||
logSink.postMessage(msg);
|
||||
}
|
||||
|
||||
private static LogLevel globalLogLevel = LogLevel.INFO;
|
||||
|
||||
public static synchronized void setLevel(LogLevel level) {
|
||||
globalLogLevel = level;
|
||||
}
|
||||
|
||||
public static synchronized LogLevel getLevel() {
|
||||
return globalLogLevel;
|
||||
}
|
||||
|
||||
public static void addSink(LogSink sink) {
|
||||
if (stageSinks == null)
|
||||
throw new IllegalStateException("Logger already started");
|
||||
stageSinks.add(sink);
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,56 @@
|
|||
package org.jcodec.common.logging;
|
||||
|
||||
public class Message {
|
||||
private LogLevel level;
|
||||
|
||||
private String fileName;
|
||||
|
||||
private String className;
|
||||
|
||||
private int lineNumber;
|
||||
|
||||
private String message;
|
||||
|
||||
private String methodName;
|
||||
|
||||
private Object[] args;
|
||||
|
||||
public Message(LogLevel level, String fileName, String className, String methodName, int lineNumber, String message, Object[] args) {
|
||||
this.level = level;
|
||||
this.fileName = fileName;
|
||||
this.className = className;
|
||||
this.methodName = methodName;
|
||||
this.message = methodName;
|
||||
this.lineNumber = lineNumber;
|
||||
this.message = message;
|
||||
this.args = args;
|
||||
}
|
||||
|
||||
public LogLevel getLevel() {
|
||||
return this.level;
|
||||
}
|
||||
|
||||
public String getFileName() {
|
||||
return this.fileName;
|
||||
}
|
||||
|
||||
public String getClassName() {
|
||||
return this.className;
|
||||
}
|
||||
|
||||
public String getMethodName() {
|
||||
return this.methodName;
|
||||
}
|
||||
|
||||
public int getLineNumber() {
|
||||
return this.lineNumber;
|
||||
}
|
||||
|
||||
public String getMessage() {
|
||||
return this.message;
|
||||
}
|
||||
|
||||
public Object[] getArgs() {
|
||||
return this.args;
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,66 @@
|
|||
package org.jcodec.common.logging;
|
||||
|
||||
import java.io.PrintStream;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import org.jcodec.common.tools.MainUtils;
|
||||
|
||||
public class OutLogSink implements LogSink {
|
||||
private static String empty = " ";
|
||||
|
||||
public static interface MessageFormat {
|
||||
String formatMessage(Message param1Message);
|
||||
}
|
||||
|
||||
public static class SimpleFormat implements MessageFormat {
|
||||
private String fmt;
|
||||
|
||||
private static Map<LogLevel, MainUtils.ANSIColor> colorMap = new HashMap<>();
|
||||
|
||||
static {
|
||||
colorMap.put(LogLevel.DEBUG, MainUtils.ANSIColor.BROWN);
|
||||
colorMap.put(LogLevel.INFO, MainUtils.ANSIColor.GREEN);
|
||||
colorMap.put(LogLevel.WARN, MainUtils.ANSIColor.MAGENTA);
|
||||
colorMap.put(LogLevel.ERROR, MainUtils.ANSIColor.RED);
|
||||
}
|
||||
|
||||
public SimpleFormat(String fmt) {
|
||||
this.fmt = fmt;
|
||||
}
|
||||
|
||||
public String formatMessage(Message msg) {
|
||||
String str = this.fmt.replace("#level", String.valueOf(msg.getLevel()))
|
||||
.replace("#color_code", String.valueOf(30 + colorMap.get(msg.getLevel()).ordinal()))
|
||||
.replace("#class", msg.getClassName()).replace("#method", msg.getMethodName())
|
||||
.replace("#file", msg.getFileName()).replace("#line", String.valueOf(msg.getLineNumber()))
|
||||
.replace("#message", msg.getMessage());
|
||||
return str;
|
||||
}
|
||||
}
|
||||
|
||||
public static SimpleFormat DEFAULT_FORMAT = new SimpleFormat(
|
||||
MainUtils.colorString("[#level]", "#color_code") + MainUtils.colorString("[#level]", "#color_code") + "\t#message");
|
||||
|
||||
private PrintStream out;
|
||||
|
||||
private MessageFormat fmt;
|
||||
|
||||
private LogLevel minLevel;
|
||||
|
||||
public static OutLogSink createOutLogSink() {
|
||||
return new OutLogSink(System.out, DEFAULT_FORMAT, LogLevel.INFO);
|
||||
}
|
||||
|
||||
public OutLogSink(PrintStream out, MessageFormat fmt, LogLevel minLevel) {
|
||||
this.out = out;
|
||||
this.fmt = fmt;
|
||||
this.minLevel = minLevel;
|
||||
}
|
||||
|
||||
public void postMessage(Message msg) {
|
||||
if (msg.getLevel().ordinal() < this.minLevel.ordinal())
|
||||
return;
|
||||
String str = this.fmt.formatMessage(msg);
|
||||
this.out.println(str);
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue