Skip to content

Commit 7442b15

Browse files
prateekatknoldusanalytically
authored andcommitted
Added example for AnyLogging
1 parent ee49fc8 commit 7442b15

File tree

1 file changed

+14
-1
lines changed

1 file changed

+14
-1
lines changed

README.md

+14-1
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ In case of `LazyLogging` and `StrictLogging`, the underlying SLF4J logger is nam
7777
these traits are mixed:
7878

7979
```scala
80-
class MyClass extends LazyLogging {
80+
class LazyLoggingExample extends LazyLogging {
8181
logger.debug("This is very convenient ;-)")
8282

8383
logger.whenDebugEnabled {
@@ -87,6 +87,19 @@ class MyClass extends LazyLogging {
8787
}
8888
```
8989

90+
```scala
91+
class AnyLoggingExample extends AnyLogging {
92+
override protected val logger: Logger = Logger("name")
93+
94+
logger.info("This is Any Logging ;-)")
95+
96+
logger.whenInfoEnabled {
97+
println("This would only execute when the info level is enabled.")
98+
(1 to 10).foreach(x => println("Scala logging is great!"))
99+
}
100+
}
101+
```
102+
90103
`LoggerTakingImplicit` provides the same methods as `Logger` class, but with additional implicit parameter `A`.
91104
During creation of the `LoggerTakingImplicit` evidence `CanLog[A]` is required.
92105
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:

0 commit comments

Comments
 (0)