| 39 | import static io.questdb.ParanoiaState.*; |
| 40 | |
| 41 | public class LogConsoleWriter extends SynchronizedJob implements Closeable, LogWriter { |
| 42 | private static final int DEBUG_LOG_HISTORY_LENGTH = 25; |
| 43 | private final long fd = Files.getStdOutFdInternal(); |
| 44 | private final int level; |
| 45 | private final LogHistory logHistory; |
| 46 | private final RingQueue<LogRecordUtf8Sink> ring; |
| 47 | private final SCSequence subSeq; |
| 48 | private LogInterceptor interceptor; |
| 49 | private final QueueConsumer<LogRecordUtf8Sink> myConsumer = this::toStdOut; |
| 50 | |
| 51 | public LogConsoleWriter(RingQueue<LogRecordUtf8Sink> ring, SCSequence subSeq, int level) { |
| 52 | this.ring = ring; |
| 53 | this.subSeq = subSeq; |
| 54 | this.level = level; |
| 55 | if (LOG_PARANOIA_MODE == LOG_PARANOIA_MODE_BASIC) { |
| 56 | System.out.println("BASIC LOG PARANOIA MODE ACTIVE"); |
| 57 | logHistory = null; |
| 58 | } else if (LOG_PARANOIA_MODE == LOG_PARANOIA_MODE_AGGRESSIVE) { |
| 59 | System.out.println("AGGRESSIVE LOG PARANOIA MODE ACTIVE"); |
| 60 | logHistory = new LogHistory(); |
| 61 | } else { |
| 62 | logHistory = null; |
| 63 | } |
| 64 | } |
| 65 | |
| 66 | @Override |
| 67 | public void bindProperties(LogFactory factory) { |
| 68 | } |
| 69 | |
| 70 | @Override |
| 71 | public void close() { |
| 72 | } |
| 73 | |
| 74 | @Override |
| 75 | public boolean runSerially() { |
| 76 | return subSeq.consumeAll(ring, myConsumer); |
| 77 | } |
| 78 | |
| 79 | public void setInterceptor(LogInterceptor interceptor) { |
| 80 | this.interceptor = interceptor; |
| 81 | } |
| 82 | |
| 83 | private void toStdOut(LogRecordUtf8Sink sink) { |
| 84 | try { |
| 85 | if ((sink.getLevel() & this.level) != 0) { |
| 86 | if (interceptor != null) { |
| 87 | interceptor.onLog(sink); |
| 88 | } |
| 89 | if (LOG_PARANOIA_MODE != LOG_PARANOIA_MODE_NONE) { |
| 90 | toStdOutWithErrorDetection(sink); |
| 91 | } else { |
| 92 | Files.append(fd, sink.ptr(), sink.size()); |
| 93 | } |
| 94 | } |
| 95 | } catch (Throwable th) { |
| 96 | System.out.println("Exception while writing a log line"); |
| 97 | th.printStackTrace(System.out); |
| 98 | } |
nothing calls this directly
no test coverage detected
searching dependent graphs…