Comments (16)
I'd prefer not to make the effect type polymorphic. At that point we're just trying to be a better log4cats
, but it's far easier to own new markets than compete with existing ones.
from zio-logging.
I'd propose a slight modification on the above proposal:
trait AbstractLogging[Message] {
def logging: AbstractLogging.Service[Message]
}
object AbstractLogging {
trait Service[-R, -Message] {
def info(message: Message): ZIO[R, Nothing, Unit]
...
}
}
trait Logging extends AbstractLogging[String]
object Logging { type Service[-R] = AbstractLogging.Service[R, String] }
// In log-stage module:
trait StructuredLogging extends Logging[Message]
object StructuredLogging { type Service[-R] = AbstractLogging.Service[R, Message] }
Possibly we should add something like MDC:
trait Service[-R, Message] {
def context: FiberRef[Map[String, Message]]
def info(message: Message): ZIO[R, Nothing, Unit]
...
}
Then the context can be adjusted, although mapping that to MDC is obviously a lot of work and the subject of a pending PR.
Then the last point is whether or not to support the creation of loggers based on classes, etc., or whether "global loggers" are sufficient.
from zio-logging.
Oh, I know... I meant to point out that you are welcome to take whatever I have in that repo.
It would come down to implementations of Logger.Service
on how each framework handles the actual logging, of course.
from zio-logging.
In our case we create a logger with custom context containing requestid and passing it further explicitly. Though I'm not trying to say that it's the best option possible, just easiest.
from zio-logging.
I don't think it hurts to have context
, since we can always "compile that away" for logging implementations that don't support it (that is, embed context, if present, into the strings / messages passed to underlying implementation). Context, however, strikes me as an 80% solution: simple, good enough for the common case, and easily understandable.
from zio-logging.
@thiloplanz As mentioned by @jdegoes, there is a pending PR that allows FiberRefs
to be read unsafely from side effecting code - basically allowing the "mapping magic" you mentioned above. A proof of concept implementation of fiber aware MDC logging for log4j2 based on a slightly outdated version of the aforementioned PR can be found here.
from zio-logging.
This is a good idea. Are we trying to get this done in time for release 1.0?
from zio-logging.
This wouldn't work for our structured logging solution. I would propose this as a starting point:
trait Logging[F[_], Message] {
def info(message: Message): F[Unit]
//...
}
trait UnstructuredLogging[F[_]] extends Logging[F, String]
// `Message` is a data structure with an implicit materializer from LogStage
trait StructuredLogging[F[_]] extends Logging[F, Message] {
}
Also we may wish to add withCustomContext
method - logstage
users found it a very useful feature.
Some references to the code which we may wish to reuse:
from zio-logging.
Looks remarkably similar to https://github.com/NeQuissimus/zio-slf4j/blob/master/src/main/scala/logger.scala ?
I use https://github.com/NeQuissimus/zio-slf4j/blob/master/src/main/scala/package.scala#L8 to turn any A
into something log-able...
from zio-logging.
@NeQuissimus yes it is very similar. we would like to have very simple interface that can be back up with slf4j and other implementations. Moreover we would like to avoid dependencies to scalaz if possible.
from zio-logging.
@pshirshov why we need F[_]
? I was thinking that ZIO
would be enough in this case. We try to keep this interface very simple.
from zio-logging.
It's not neccessary to make it polymorphic, though it may be very useful at least for those who wish to reuse the same logger for any code outside of ZIO so they may put identity there. We have our own typeclass wrapping ZIO for basic usecases and in general it's very useful. Though I don't insist (but I still think it may be a very good idea to build a hierarchy of typeclasses)
from zio-logging.
Then the last point is whether or not to support the creation of loggers based on classes, etc., or whether "global loggers" are sufficient.
A macro can do it. Also we may provide a classic way to define location specifically for Logging
Then the context can be adjusted, although mapping that to MDC is obviously a lot of work and the subject of a pending PR.
I don't think that MDC-like approach is a good thing. Just custom-provided contexts are very efficient (and very easy to handle and debug). def apply(userContext: (String, String)*): AbstractLogging
should be just fine for 95% of the usecases (IMO) - user can always pass a logger bound to custom context while spawning a fork.
from zio-logging.
@pshirshov how would you handle things like request-id/correlation-id without MDC-like approach?
from zio-logging.
Having the Logging service explicitly support context
instead of passing it around separately seems much better to me, not only for reduced boilerplate, but also (and probably more importantly) because a Logging implementation could then also integrate that context
with the MDC capabilities of the underlying logging backend, so that not only our own ZIO-aware application code benefits from it, but all that low-level code that we call into and that in turn logs via SLF4J directly would also pick up our "correlation id" and include it in their logging output.
That FiberRef
<-> MDC
<-> ThreadLocal
mapping magic would be the most important feature for me.
from zio-logging.
I have a logging library https://github.com/leigh-perry/log4zio that might be a useful starting point for zio-logging. Its main selling point is contravariant-functor-style composition of loggers. It is ZIO-based without dependencies on Cats or Scalaz.
It is in line with @jdegoes initial sketch at the top of this issue.
from zio-logging.
Related Issues (20)
- `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
- Empty spans rendered as invalid json HOT 2
- class TypesafeConfigProvider is not found HOT 4
- Contributor's Guide page not found HOT 2
- slf4j bridge modules "enable" all log levels, causing performance issues HOT 1
- Custom Logger not adding annotations 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.