Git Product home page Git Product logo

Comments (8)

chaoren avatar chaoren commented on May 18, 2024

You can use a MetadataKey for this, no? logJson seems like an unnecessary addition that goes against the fluent design of the flogger API.

from flogger.

hlemcke avatar hlemcke commented on May 18, 2024

The fluent Api is and should stay as a basic design rule. Json logging would only be an addition. I would appreciate to have two methods like:

  • withData(Map<String,Object> jsonMap) to set data used in all following log entries from this logger
  • logJson(String message, Map<String,Object> jsonMap) to log entries according to Elastic Common Schema

from flogger.

chaoren avatar chaoren commented on May 18, 2024

The fluent design is kind of the whole point of Flogger. It's even in the name! It's repeated several times throughout https://google.github.io/flogger/anatomy that this is a very intentional design choice.

For example https://google.github.io/flogger/anatomy#fluent-api

Flogger’s API is designed to require only a single conceptual log method in its API.

If we are to add logJson for this "Elastic Common Schema," then we'd be expected to add a different log method for all the different schemas out there. We'd end up with log, logJson, logXml, logCsv, etc, for every data format imaginable. A single log method plus whatever configuration you want in the fluent chain leading up to it already provides everything necessary to achieve what you're asking for. There is absolutely zero need for a separate log method.

from flogger.

chaoren avatar chaoren commented on May 18, 2024

You could just write a flogger extension so instead of needing logJson(String message, Map<String,Object> jsonMap), you can just do withJson(Map<String,Object> jsonMap).log(String message). Please see https://google.github.io/flogger/anatomy for why we don't want logJson to be a single method.

from flogger.

hlemcke avatar hlemcke commented on May 18, 2024

Hi charoren. Thanks for still helping me out. It definitiely feels best to go with something like withJson(Map<String,Object> jsonMap).log(String message)! Do you have any hint where I can find some examples how to implement this?

from flogger.

chaoren avatar chaoren commented on May 18, 2024

You can find some good answers by searching for this on the internet:

You could also ask directly on https://stackoverflow.com/ if those answers are not sufficient.

from flogger.

hlemcke avatar hlemcke commented on May 18, 2024

That helps. Thank you very much!

from flogger.

hagbard avatar hagbard commented on May 18, 2024

See my new site dedicated to providing better Flogger documentation:
https://hagbard.github.io/the-flogger-manual/advanced/#metadata-contexts-and-scopes

You can implement passing the data without need for a new API method by using a suitably named metadata key:

private static final MetadataKey<MyJsonMapType> JSON_MAP = MetadataKey.single("json_map", MyJsonMapType.class);

logger.atWarning().with(JSON_MAP, map).log(...);

Passing structured or semi-structured data is exactly what metadata is for.

Also, if you want the same values passed to lots of log statements, use ScopedLoggingContexts rather than passing values in.
This also gives you access to Tags, which might be just what you want.

HOWEVER, what the logger backend does with this is a different issue. What do you actually want the output to be (you might need a new backend or a customized MetadataKey) ?

from flogger.

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.