From c4bcd42a63754742c9a9d1152ee8dd695fa0525d Mon Sep 17 00:00:00 2001 From: prateekatknoldus Date: Fri, 7 Jan 2022 21:23:21 +0530 Subject: [PATCH] Added example for AnyLogging --- README.md | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index a0f6469..6e69709 100644 --- a/README.md +++ b/README.md @@ -77,7 +77,7 @@ In case of `LazyLogging` and `StrictLogging`, the underlying SLF4J logger is nam these traits are mixed: ```scala -class MyClass extends LazyLogging { +class LazyLoggingExample extends LazyLogging { logger.debug("This is very convenient ;-)") logger.whenDebugEnabled { @@ -87,6 +87,19 @@ class MyClass extends LazyLogging { } ``` +```scala +class AnyLoggingExample extends AnyLogging { + override protected val logger: Logger = Logger("name") + + logger.info("This is Any Logging ;-)") + + logger.whenInfoEnabled { + println("This would only execute when the info level is enabled.") + (1 to 10).foreach(x => println("Scala logging is great!")) + } +} +``` + `LoggerTakingImplicit` provides the same methods as `Logger` class, but with additional implicit parameter `A`. During creation of the `LoggerTakingImplicit` evidence `CanLog[A]` is required. It may be useful when contextual parameter (e.g. _Correlation ID_) is being passed around and you would like to include it in the log messages: