Giter Site home page Giter Site logo

Comments (1)

lmolkova avatar lmolkova commented on July 20, 2024 1

Determine how we want to JSON structured logging to look like

There are two options:

  1. Don't change anything for SLF4J 2.0. As a result, SLF4J 2.0 providers would get string message (which happens to be structured json) and won't see individual key-value-pairs

    • Pros: when writing logs to file/console, the default formatter would print log message as a whole.
    • Cons: when writing logs to structured destinations, the message will remain a string and will need additional parsing when querying data
  2. Leverage the structure and use SLF4J 2.0 addKeyValue methods to provide the context to the SDLF4J

    • Pros: when writing logs to structured destinations, users will get better experience
    • Cons: when writing to file/console, the default formatters will NOT include any context. And would just print the message

The middle ground:
E.g. we want to record the following log: connectionId=foo, error.type=canceled, message="Connection attempt failed"

With SLF4J 1.7 we record message as {"connectionId":"foo", "error.type":"canceled", "message":"Connection attempt failed"}
With SLF4J 2.0 we record structured things and a formatted message like

slf4JLogger.atInfo()
  .addKeyValue("connectionId", "foo")
  .addKeyValue("error.type", "canceled")
  .addKeyValue("message", "Connection attempt failed")
  .log("{\"connectionId\":\"foo\", \"error.type\":\"canceled\", \"message\":\"Connection attempt failed\"}")

This would be a default behavior resulting in:

  • giving all the structure to providers that support it
  • still having all the context and message in the formatted json string in the message for default formatters.

It'd result in duplication and we can consider letting users to configure it.


My proposal is to do 1.5 eventually, but stick with option 1 for now until we have any feedback/scenario for option 1.5.

By doing option 1, we effectively do

slf4JLogger.atInfo()
  .log("{\"connectionId\":\"foo\", \"error.type\":\"canceled\", \"message\":\"Connection attempt failed\"}")

and

  .addKeyValue("connectionId", "foo")
  .addKeyValue("error.type", "canceled")
  .addKeyValue("message", "Connection attempt failed")

is purely incremental change.

from azure-sdk-for-java.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.