Comments (5)
It would still need a standard way to generate UUID's with the ZIO library, which I don't think there is right now.
from zio-logging.
I see what you mean but I'm not exactly convinced to your approach
in pipe example
val pipe = for {
user <- UserRepository.findById(userId).logError(e => s"Error finding user: $e")
credit <- BalanceRepository.getBalanceByUserId(userId).logInfo(b => s"Balance of $b found")
} yield ()
I like logError
part but not logInfo
part. I would write this
val pipe = for {
user <- UserRepository.findById(userId).logError(e => s"Error finding user: $e")
credit <- BalanceRepository.getBalanceByUserId(userId)
_ <- log.info(b => s"Balance of $b found")
} yield ()
for withCorrelatationId
and withLoggerName
I would say no. I prefer to have something like
import LogAnnotation._
log.annotate(CorrelationId(), Name("UserBalanceService"), OtherRandomAnnotation("foo")) {
pipe
}
what do you think @renancaju about this?
from zio-logging.
About the logInfo
bit, yeah, I guess it's not great. But imagine you just want to log the result like this:
_ <- BalanceRepository.getBalanceByUserId(userId).logInfo(_.toString)
I feel it would be better than:
balance <- BalanceRepository.getBalanceByUserId(userId)
_ <- log.info(balance.toString)
About the annotation composability you proposed, you mean making LogAnnotation
a trait and creating case classes extending that trait like CorrelationId
, Name
, etc? Or those case classes would extends some other trait that would be like LogAnnotation recipes?
One thing I like better in the syntax I proposed is that you avoid nesting and give emphasis to the business logic (the pipe
) instead of logging (which is the first thing that appears if you use the current syntax).
Of course, these are opinions based on my usage only and totally subjective. Other people might feel differently.
from zio-logging.
as you mentioned this is all subjective. For me for
in scala or do
in haskell ware created to help organize code in sequence vertically so argument with one liner in for
doesn't resonate with me :)
even with today structure you can do this
log.locally(CorrelationId(Some(uuid)).andThen(Name("loggerName" :: Nil)){ pipe }
maybe it's a matter to add shortcut for that. What do you think?
from zio-logging.
Sorry, I guess I missed the apply
method on LogAnnotation
that returns a LogContext => LogContext
, which makes everything compose nicely...
I guess the only improvement in my suggestions would be regarding the generation of UUID
s automatically. But since there is no standard way of doing so with ZIO, I guess it would not be in the scope of zio-logging. Maybe an external zio-utils package could solve it.
Sorry to waste your time! For me it was really valuable, cause I learned something from this interaction 😄
from zio-logging.
Related Issues (20)
- Different logger format when use Slf4jBridge HOT 3
- Support slf4j markers in SLF4J backend HOT 4
- Shall we add support for scala 2.13.9? HOT 1
- Why is the log of resource release not output when interuppted? HOT 4
- Effectful logging instrumentation HOT 1
- `zio.logging.LogAnnotation` does not work when `version > 2.0.1` HOT 11
- `label` has invalid format when using `SL4J` HOT 1
- Support SLF4J 2.0.x for slf4j-bridge HOT 1
- logErrorCause does not show nested/suppressed/chained exceptions HOT 9
- Ability to filter and properly format logs received from Slf4J API HOT 1
- Feature request: support glob-like wildcard path matching for LogFilters HOT 1
- SLFJ4 binding can drop log records about application startup failure HOT 1
- ZIO logging 2.1.8 causes SLF4j log replay HOT 4
- slf4j v2 logging backend
- improve support for structured logging (Json and possibly other formats) HOT 5
- Official documentation not updated with latest changes HOT 3
- naming clash
- zio-logging 2.1.11 does not work with zio 2.0.11 HOT 3
- Missing structured annotations with consoleJsonLogger HOT 2
- multiple spans and attributes are concatenated without whitespace HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from zio-logging.