From f56efb74b8d545943c87779a35e500cb962dd306 Mon Sep 17 00:00:00 2001 From: Anselm McClain Date: Mon, 14 Oct 2024 15:03:08 -0700 Subject: [PATCH 1/2] Updated behavior of `withInfo` and `withDebug` + Only log a "started" message if logging enabled at `DEBUG` or `TRACE`, respectively. + Allows admins to see start messages for more important `withInfo` logs, without necessarily printing both lines for all `withDebug` calls. --- CHANGELOG.md | 6 ++++++ src/main/groovy/io/xh/hoist/log/LogSupport.groovy | 6 +++++- 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index dcdca6b1..54c3636c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -14,6 +14,12 @@ * Improved the handling of track log timestamps - these can now be supplied by the client and are no longer bound to insert time of DB record. Latest Hoist React uses *start* of the tracked activity. +### ⚙️ Technical + +* Updated behavior of `withInfo` and `withDebug` log utils to print a "started" message if logging + enabled at `DEBUG` or `TRACE`, respectively. Allows admins to see start messages for more + important `withInfo` logs, without necessarily printing both lines for all `withDebug` calls. + ## 23.0.0 - 2024-09-27 ### 💥 Breaking Changes (upgrade difficulty: 🟢 LOW) diff --git a/src/main/groovy/io/xh/hoist/log/LogSupport.groovy b/src/main/groovy/io/xh/hoist/log/LogSupport.groovy index d70d8418..60ef5f02 100644 --- a/src/main/groovy/io/xh/hoist/log/LogSupport.groovy +++ b/src/main/groovy/io/xh/hoist/log/LogSupport.groovy @@ -126,7 +126,11 @@ trait LogSupport { private T loggedDo(Logger log, Level level, Object msgs, Closure c) { Map meta = getMeta() ?: [:]; - if (log.debugEnabled) { + // Log *start* of closure execution if logging enabled @ one level finer than the main log level. + // Ie setting level to debug will start showing INFO start msgs, up to trace to show DEBUG start msgs. + if ( + (level == INFO && log.debugEnabled) || (level == DEBUG && log.traceEnabled) || level == TRACE + ) { meta << [_status: 'started'] logAtLevel(log, level, msgs, meta) } From 43a568ea61869ab00b66c120be760b4fecdc55cc Mon Sep 17 00:00:00 2001 From: lbwexler Date: Mon, 14 Oct 2024 18:52:14 -0400 Subject: [PATCH 2/2] Tweak approved by ATM --- src/main/groovy/io/xh/hoist/log/LogSupport.groovy | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/src/main/groovy/io/xh/hoist/log/LogSupport.groovy b/src/main/groovy/io/xh/hoist/log/LogSupport.groovy index 60ef5f02..5a679c0d 100644 --- a/src/main/groovy/io/xh/hoist/log/LogSupport.groovy +++ b/src/main/groovy/io/xh/hoist/log/LogSupport.groovy @@ -126,11 +126,9 @@ trait LogSupport { private T loggedDo(Logger log, Level level, Object msgs, Closure c) { Map meta = getMeta() ?: [:]; - // Log *start* of closure execution if logging enabled @ one level finer than the main log level. - // Ie setting level to debug will start showing INFO start msgs, up to trace to show DEBUG start msgs. - if ( - (level == INFO && log.debugEnabled) || (level == DEBUG && log.traceEnabled) || level == TRACE - ) { + // Log *start* of closure execution if at a fine run-time level. Use debug to get + // start msgs for your 'withInfo' logs, trace for your 'withDebug/withTrace' + if ((log.debugEnabled && level == INFO) || log.traceEnabled) { meta << [_status: 'started'] logAtLevel(log, level, msgs, meta) }