Comments (9)
You can just use a MetadataKey<UserId>
and then your log statement will look like:
logger.atInfo().with(USER, id).log("Message: %s", param);
the key can just be:
public static final MetadataKey<UserId> USER = MetadataKey.single("user_id", UserId.class);
Then you can make a custom LoggerBackend
which can recognize the USER
key specially and do whatever it needs to do.
The reason that the FluentLogger
API is final is because by extending it you can change things like the format string it uses. It would be very unpleasant for users if you could have a Supplier<FluentLogger>
where you don't know if the instance you got uses printf formatting or brace-style formatting (or something else). These core parts of functionality need to be baked into the choice of logger implementation you are using.
Making a new logging API that extends the existing LoggingApi and a new logger class (subclass of AbstractLogger) is easy if you need to do that, but in your case you don't need to go down that route.
from flogger.
Oh and with this approach (if you use gRPC contexts) you can set that metadata once for a whole task, so you don't even need to set it on each log statement.
from flogger.
- I try with this:
public static final MetadataKey<Integer> ID = MetadataKey.single("id", Integer.class);
flogger-slf4j-backend:0.74
System.setProperty("flogger.backend_factory", "com.google.common.flogger.backend.slf4j.Slf4jBackendFactory#getInstance");
logger.at(Level.INFO)
.with(ID, 12)
.log("query=%s ,limit=%d, currentPage=%d, useLimit=%s", query, limit, currentPage, useLimit);
-
getting error: Caused by: java.lang.NoSuchFieldError: ID
-
deployed on glassfish & java 8
from flogger.
- I'll stick with slf4j and now is slf4j 2.0.0
- lack of documentation(not up to date)
from flogger.
Can you let us know what's not up to date ?
from flogger.
- Extensibility should be more explicit how to create forUserId extension
- backend for slf4j should have which version of slf4j and how to activate
from flogger.
- Logger Config on net I see some code snippets, but LoggerConfig is not part of lib, so is it possible to change log lavel at runtime?
from flogger.
- If you have examples in repository with what is possible this project will have more stars and attraction
from flogger.
Thanks for the feedback. LoggerConfig is no longer part of Flogger because Flogger is a facade and can emit logs to many different logging systems (each with their own configuration mechanism). LoggerConfig was JDK logger specific and thus useless to most other backends and it was a mistake to have packaged it as part of Flogger originally.
I definitely agree that the user-facing documents regarding what you can do with Flogger are very limited at the moment, and we'll try to improve that.
from flogger.
Related Issues (20)
- Benchmarks and String Creation HOT 19
- Architecture diagram for flogger
- 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
- Provide a log writer to produce JSON log items according to Elastic Common Schema HOT 8
- 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.