Comments (8)
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.
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.
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.
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.
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.
You can find some good answers by searching for this on the internet:
- https://stackoverflow.com/questions/56262887/how-does-one-extend-the-flogger-fluent-api-for-domain-specific-attributes
- https://groups.google.com/g/flogger-discuss/c/J1pM68LpVvA/m/Y3pmcld-BQAJ
You could also ask directly on https://stackoverflow.com/ if those answers are not sufficient.
from flogger.
That helps. Thank you very much!
from flogger.
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)
- Benchmarks and String Creation HOT 19
- Architecture diagram for flogger
- Extensibility How to HOT 9
- Better document Flogger's status (active, maintained, in use at Google) HOT 5
- Support for java.util.ResourceBundle HOT 9
- Add tags from thread context to log HOT 17
- Use java.time.Duration for atMostEvery in LoggingApi. HOT 2
- Flag --incompatible_disable_starlark_host_transitions will break Flogger in Bazel 7.0 HOT 6
- Release schedule?
- Default JavaDocs generated for Flogger confusingly suggest it's deprecated (it isn't). HOT 2
- How to handle ScopedLoggingContext for new Threads / ThreadPools? HOT 1
- I don't believe ScopedLoggingContexts should obviously accept null "no-op" arguments. HOT 5
- Incorrect caller details logged with Flogger in spring boot HOT 2
- Error: 'JavaInfo' value has no field or method 'transitive_deps' HOT 5
- Error: 'JavaInfo' value has no field or method 'transitive_deps' HOT 5
- Next release HOT 2
- ThreadlocalRandom instead of ThreadLocal HOT 8
- java failed error executing Javac command from target //api:checks HOT 5
- test
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 flogger.