https://github.com/sjmyuan/jlogger
A Scala library to print log in JSON format
https://github.com/sjmyuan/jlogger
json log logger scala
Last synced: 6 months ago
JSON representation
A Scala library to print log in JSON format
- Host: GitHub
- URL: https://github.com/sjmyuan/jlogger
- Owner: sjmyuan
- License: mit
- Created: 2021-10-20T12:52:05.000Z (over 4 years ago)
- Default Branch: master
- Last Pushed: 2022-01-01T09:14:27.000Z (over 4 years ago)
- Last Synced: 2024-04-24T10:27:29.717Z (about 2 years ago)
- Topics: json, log, logger, scala
- Language: Scala
- Homepage:
- Size: 149 KB
- Stars: 0
- Watchers: 3
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
## jlogger
This is a Scala library to print the log in JSON format
### Installation
Add the following dependency to you `build.sbt`
```scala
libraryDependencies += "io.github.sjmyuan" %% "jlogger" % "0.0.2",
```
### UML

### Example
#### Print log with self4j
```scala
import io.github.sjmyuan.jlogger.SimpleJsonLogger
import cats.effect.IO
import cats.effect.IOApp
import org.slf4j.LoggerFactory
object App extends IOApp {
val logger = new Self4jJsonLogger[IO](LoggerFactory.getLogger(getClass()))
val program = for {
_ <-logger.warn("This is a json logger")
_ <-logger.error("This is a json logger")
_ <-logger.info("This is a json logger")
} yield()
program.unsafeRunSync()
}
```
#### Print log with println
```scala
import io.github.sjmyuan.jlogger.SimpleJsonLogger
import cats.effect.IO
import cats.effect.IOApp
object App extends IOApp {
val logger = new SimpleJsonLogger[IO]()
val program = for {
_ <-logger.warn("This is a json logger")
_ <-logger.error("This is a json logger")
_ <-logger.info("This is a json logger")
} yield()
program.unsafeRunSync()
}
```