Skip to content

Commit b752c34

Browse files
committed
Verbose logging added to ILogMonitor.
1 parent 06e056e commit b752c34

5 files changed

Lines changed: 57 additions & 3 deletions

File tree

src/main/java/pl/mjaron/tinyloki/ErrorLogMonitor.java

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,17 @@
55
*/
66
public class ErrorLogMonitor implements ILogMonitor {
77

8+
@Override
9+
public boolean isVerbose() {
10+
return false;
11+
}
12+
13+
@Override
14+
public void logVerbose(String what) {
15+
}
16+
817
@Override
918
public void logInfo(final String what) {
10-
ILogMonitor.printInfo(what);
1119
}
1220

1321
@Override

src/main/java/pl/mjaron/tinyloki/ILogMonitor.java

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,18 @@
55
*/
66
public interface ILogMonitor {
77

8+
/**
9+
* Default meta-logging implementation.
10+
* <p>
11+
* Used internally by TinyLoki implementation for this library diagnostic purposes.
12+
*
13+
* @param what Log content.
14+
* @since 1.1.7
15+
*/
16+
static void printVerbose(final String what) {
17+
System.out.println("[TinyLoki][" + System.currentTimeMillis() + "][V] " + what);
18+
}
19+
820
/**
921
* Default meta-logging implementation.
1022
* <p>
@@ -27,6 +39,16 @@ static void printError(final String what) {
2739
System.err.println("[TinyLoki][" + System.currentTimeMillis() + "][E] " + what);
2840
}
2941

42+
/**
43+
* Tells whether verbose messages are logged by this log monitor.
44+
*
45+
* @return <code>true</code> when verbose messages are processed by this log monitor.
46+
* @since 1.1.7
47+
*/
48+
boolean isVerbose();
49+
50+
void logVerbose(final String what);
51+
3052
void logInfo(final String what);
3153

3254
void logError(final String what);

src/main/java/pl/mjaron/tinyloki/SilentLogMonitor.java

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,15 @@
66
* @since 1.0.0
77
*/
88
public class SilentLogMonitor implements ILogMonitor {
9+
@Override
10+
public boolean isVerbose() {
11+
return false;
12+
}
13+
14+
@Override
15+
public void logVerbose(String what) {
16+
}
17+
918
@Override
1019
public void logInfo(String what) {
1120
}

src/main/java/pl/mjaron/tinyloki/TinyLoki.java

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -513,11 +513,16 @@ public boolean closeSync() throws InterruptedException {
513513
protected void internalProcessLogs() throws InterruptedException {
514514
final byte[][] buffers = logCollector.collectAll();
515515
if (buffers == null) {
516-
logMonitor.logInfo("Buffers count: [0] (null).");
516+
if (logMonitor.isVerbose()) {
517+
logMonitor.logVerbose("Buffers count: [0] (null).");
518+
}
517519
return;
518520
}
519521

520-
logMonitor.logInfo("Buffers count: [" + buffers.length + "].");
522+
if (logMonitor.isVerbose()) {
523+
logMonitor.logVerbose("Buffers count: [" + buffers.length + "].");
524+
}
525+
521526
for (final byte[] logs : buffers) {
522527
final byte[] toSend;
523528
if (logEncoder == null) {

src/main/java/pl/mjaron/tinyloki/VerboseLogMonitor.java

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,16 @@ public VerboseLogMonitor(final boolean printMessages) {
1919
this.printMessages = printMessages;
2020
}
2121

22+
@Override
23+
public boolean isVerbose() {
24+
return true;
25+
}
26+
27+
@Override
28+
public void logVerbose(String what) {
29+
ILogMonitor.printVerbose(what);
30+
}
31+
2232
@Override
2333
public void logInfo(String what) {
2434
ILogMonitor.printInfo(what);

0 commit comments

Comments
 (0)