Skip to content

Commit

Permalink
Optimised entrypoint() call
Browse files Browse the repository at this point in the history
  • Loading branch information
ekoutanov committed Apr 26, 2018
1 parent e576978 commit 0a450fb
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 24 deletions.
39 changes: 20 additions & 19 deletions src/main/java/com/obsidiandynamics/zerolog/Zlg.java
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ interface LogChain {
LogChain entrypoint(String entrypoint);

/**
* Feeds the log chain into a consumer.
* Feeds the log chain into a consumer and then completes the log chain.
*
* @param logChainConsumer Consumer for the log chain.
*/
Expand All @@ -65,6 +65,7 @@ default void _done(Consumer<LogChain> logChainConsumer) {
void _done();

default boolean log() {
entrypoint(ENTRYPOINT);
_done();
return true;
}
Expand All @@ -75,75 +76,75 @@ default boolean log() {
boolean isEnabled(int level);

default void e(String message) {
level(LogLevel.ERROR).format(message).entrypoint(ENTRYPOINT)._done();
level(LogLevel.ERROR).format(message)._done();
}

default void e(String summary, Throwable cause) {
level(LogLevel.ERROR).format(summary).threw(cause).entrypoint(ENTRYPOINT)._done();
level(LogLevel.ERROR).format(summary).threw(cause)._done();
}

default void e(String format, Consumer<LogChain> logChainConsumer) {
level(LogLevel.ERROR).format(format).entrypoint(ENTRYPOINT)._done(logChainConsumer);
level(LogLevel.ERROR).format(format)._done(logChainConsumer);
}

default void w(String message) {
level(LogLevel.WARN).format(message).entrypoint(ENTRYPOINT)._done();
level(LogLevel.WARN).format(message)._done();
}

default void w(String summary, Throwable cause) {
level(LogLevel.WARN).format(summary).threw(cause).entrypoint(ENTRYPOINT)._done();
level(LogLevel.WARN).format(summary).threw(cause)._done();
}

default void w(String format, Consumer<LogChain> logChainConsumer) {
level(LogLevel.WARN).format(format).entrypoint(ENTRYPOINT)._done(logChainConsumer);
level(LogLevel.WARN).format(format)._done(logChainConsumer);
}

default void i(String message) {
level(LogLevel.INFO).format(message).entrypoint(ENTRYPOINT)._done();
level(LogLevel.INFO).format(message)._done();
}

default void i(String summary, Throwable cause) {
level(LogLevel.INFO).format(summary).threw(cause).entrypoint(ENTRYPOINT)._done();
level(LogLevel.INFO).format(summary).threw(cause)._done();
}

default void i(String format, Consumer<LogChain> logChainConsumer) {
level(LogLevel.INFO).format(format).entrypoint(ENTRYPOINT)._done(logChainConsumer);
level(LogLevel.INFO).format(format)._done(logChainConsumer);
}

default void c(String message) {
level(LogLevel.CONF).format(message).entrypoint(ENTRYPOINT)._done();
level(LogLevel.CONF).format(message)._done();
}

default void c(String summary, Throwable cause) {
level(LogLevel.CONF).format(summary).threw(cause).entrypoint(ENTRYPOINT)._done();
level(LogLevel.CONF).format(summary).threw(cause)._done();
}

default void c(String format, Consumer<LogChain> logChainConsumer) {
level(LogLevel.CONF).format(format).entrypoint(ENTRYPOINT)._done(logChainConsumer);
level(LogLevel.CONF).format(format)._done(logChainConsumer);
}

default void d(String message) {
level(LogLevel.DEBUG).format(message).entrypoint(ENTRYPOINT)._done();
level(LogLevel.DEBUG).format(message)._done();
}

default void d(String summary, Throwable cause) {
level(LogLevel.DEBUG).format(summary).threw(cause).entrypoint(ENTRYPOINT)._done();
level(LogLevel.DEBUG).format(summary).threw(cause)._done();
}

default void d(String format, Consumer<LogChain> logChainConsumer) {
level(LogLevel.DEBUG).format(format).entrypoint(ENTRYPOINT)._done(logChainConsumer);
level(LogLevel.DEBUG).format(format)._done(logChainConsumer);
}

default void t(String message) {
level(LogLevel.TRACE).format(message).entrypoint(ENTRYPOINT)._done();
level(LogLevel.TRACE).format(message)._done();
}

default void t(String summary, Throwable cause) {
level(LogLevel.TRACE).format(summary).threw(cause).entrypoint(ENTRYPOINT)._done();
level(LogLevel.TRACE).format(summary).threw(cause)._done();
}

default void t(String format, Consumer<LogChain> logChainConsumer) {
level(LogLevel.TRACE).format(format).entrypoint(ENTRYPOINT)._done(logChainConsumer);
level(LogLevel.TRACE).format(format)._done(logChainConsumer);
}

static ZlgBuilder forName(String name) {
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/com/obsidiandynamics/zerolog/ZlgImpl.java
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ final class LogChainImpl implements LogChain {
private int argc;
private Object[] argv = new Object[MAX_ARGS];
private Throwable throwable;
private String entrypoint = LogChain.ENTRYPOINT;
private String entrypoint = Zlg.ENTRYPOINT;

private void reset() {
tag = null;
Expand All @@ -35,7 +35,7 @@ private void reset() {
}
argc = 0;
throwable = null;
entrypoint = LogChain.ENTRYPOINT;
entrypoint = Zlg.ENTRYPOINT;
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ public void testEntryRetention() {
final String format = "entry #%d";
final Exception cause = new Exception("simulated");
for (int i = 0; i < numEntries; i++) {
zlg.level(logLevel).format(format).arg(i).tag(String.valueOf(i)).threw(cause)._done();
zlg.level(logLevel).format(format).arg(i).tag(String.valueOf(i)).threw(cause).log();
}

final List<Entry> entries = target.entries().list();
Expand Down
3 changes: 1 addition & 2 deletions src/test/java/com/obsidiandynamics/zerolog/ZlgTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ public void testDefaultMessageMethods() {
verify(chain).log();

verify(z, times(6)).level(anyInt());
verify(chain, times(6)).entrypoint(notNull());
verify(chain, times(1)).entrypoint(notNull());
verify(chain, times(7))._done();
verifyNoMoreInteractions(chain);
}
Expand Down Expand Up @@ -91,7 +91,6 @@ public void testDefaultSummaryAndThrowableMethods() {

verify(z, times(6)).level(anyInt());
verify(chain, times(6)).threw(eq(cause));
verify(chain, times(6)).entrypoint(notNull());
verify(chain, times(6))._done();
verifyNoMoreInteractions(chain);
}
Expand Down

0 comments on commit 0a450fb

Please sign in to comment.