| 72 | import java.util.concurrent.atomic.AtomicBoolean; |
| 73 | |
| 74 | public class LogFactory implements Closeable { |
| 75 | |
| 76 | public static final String CONFIG_SYSTEM_PROPERTY = "out"; |
| 77 | public static final String DEBUG_TRIGGER = "ebug"; |
| 78 | public static final String DEBUG_TRIGGER_ENV = "QDB_DEBUG"; |
| 79 | // name of default logging configuration file (in jar and in $root/conf/ dir) |
| 80 | public static final String DEFAULT_CONFIG_NAME = "log.conf"; |
| 81 | // placeholder that can be used in log.conf to point to $root/log/ dir |
| 82 | public static final String LOG_DIR_VAR = "${log.dir}"; |
| 83 | private static final String DEFAULT_CONFIG = "/io/questdb/site/conf/" + DEFAULT_CONFIG_NAME; |
| 84 | private static final int DEFAULT_LOG_LEVEL = LogLevel.INFO | LogLevel.ERROR | LogLevel.CRITICAL | LogLevel.ADVISORY; |
| 85 | private static final int DEFAULT_MSG_SIZE = 4 * 1024; |
| 86 | private static final int DEFAULT_QUEUE_DEPTH = 1024; |
| 87 | private static final String EMPTY_STR = ""; |
| 88 | private static final LengthDescendingComparator LDC = new LengthDescendingComparator(); |
| 89 | private static final CharSequenceHashSet reserved = new CharSequenceHashSet(); |
| 90 | private static LogFactory INSTANCE; |
| 91 | private static boolean envEnabled = true; |
| 92 | private static boolean guaranteedLogging = false; |
| 93 | private static String rootDir; |
| 94 | private final Clock clock; |
| 95 | private final AtomicBoolean closed = new AtomicBoolean(); |
| 96 | private final ObjList<DeferredLogger> deferredLoggers = new ObjList<>(); |
| 97 | private final ObjHashSet<LogWriter> jobs = new ObjHashSet<>(); |
| 98 | private final AtomicBoolean running = new AtomicBoolean(); |
| 99 | private final CharSequenceObjHashMap<ScopeConfiguration> scopeConfigMap = new CharSequenceObjHashMap<>(); |
| 100 | private final ObjList<ScopeConfiguration> scopeConfigs = new ObjList<>(); |
| 101 | private final StringSink sink = new StringSink(); |
| 102 | private final WorkerPool loggingWorkerPool; |
| 103 | private boolean configured = false; |
| 104 | private int queueDepth = DEFAULT_QUEUE_DEPTH; |
| 105 | private int recordLength = DEFAULT_MSG_SIZE; |
| 106 | |
| 107 | public LogFactory() { |
| 108 | this(MicrosecondClockImpl.INSTANCE); |
| 109 | } |
| 110 | |
| 111 | private LogFactory(Clock clock) { |
| 112 | this.clock = clock; |
| 113 | loggingWorkerPool = new WorkerPool(new WorkerPoolConfiguration() { |
| 114 | @Override |
| 115 | public Metrics getMetrics() { |
| 116 | return Metrics.DISABLED; |
| 117 | } |
| 118 | |
| 119 | @Override |
| 120 | public String getPoolName() { |
| 121 | return "logging"; |
| 122 | } |
| 123 | |
| 124 | @Override |
| 125 | public int getWorkerCount() { |
| 126 | return 1; |
| 127 | } |
| 128 | |
| 129 | @Override |
| 130 | public boolean isDaemonPool() { |
| 131 | return true; |