Comments (14)
Your requirements have been now implemented in #44.
from roarr.
How are you using sequence value?
from roarr.
@gajus The way that I'd like it to work is the following:
HTTP Request A to GET /endpoint comes
Log sequence 1
Log sequence 2
Log sequence 3
HTTP Request B to GET /endpoint comes
Log sequence 1
Log sequence 2
Log sequence 3
Right now Request B will create logs with sequence 4 to 6. I use a global singleton logger as is suggested in the README. Per incoming request I call logger.child(...)
in an express middleware before any log methods are called.
Resetting sequences per request would help my team clearly see in a log aggregation tool which actions happened in what order for a particular request action/event
from roarr.
Logically, it could not work that way. You need some sort of unique identifier of a sequence.
Otherwise, it would not be clear how logs would be produced for operations that are executed in parallel, like:
Promise.all([require('https://a'), require('https://b')])
from roarr.
Are you thinking of the calls above as being made within the logged application, or into the logged application?
The scenario I'm working with is about the latter, just want to make sure.
So for parallel requests into the application per request I will be making child loggers scoped to that particular request. Now I just want the sequence to be able to be scoped per logger instance, rather than the sequence used globally across all logger instances
from roarr.
So for parallel requests into the application per request I will be making child loggers scoped to that particular request. Now I just want the sequence to be able to be scoped per logger instance, rather than the sequence used globally across all logger instances
Can you produce an example of an expected log output?
from roarr.
Can you produce an example of an expected log output?
Sure thing:
{"context":{"path":"/endpoint","logLevel":30},"message":"Log event 1","sequence":1,"time":1624305447427,"version":"1.0.0"}
{"context":{"path":"/endpoint","logLevel":30},"message":"Log event 2","sequence":2,"time":1624305447427,"version":"1.0.0"}
{"context":{"path":"/endpoint","logLevel":30},"message":"Log event 1","sequence":1,"time":1624305451751,"version":"1.0.0"}
{"context":{"path":"/endpoint","logLevel":30},"message":"Log event 2","sequence":2,"time":1624305451751,"version":"1.0.0"}
So the above is the ideal case for me (the zero-th sequence is at the start of the application). Above I made 2 GET /endpoint
calls
In reality this is what I receive
{"context":{"path":"/endpoint","logLevel":30},"message":"Log event 1","sequence":1,"time":1624305447427,"version":"1.0.0"}
{"context":{"path":"/endpoint","logLevel":30},"message":"Log event 2","sequence":2,"time":1624305447427,"version":"1.0.0"}
{"context":{"path":"/endpoint","logLevel":30},"message":"Log event 1","sequence":3,"time":1624305451751,"version":"1.0.0"}
{"context":{"path":"/endpoint","logLevel":30},"message":"Log event 2","sequence":4,"time":1624305451751,"version":"1.0.0"}
from roarr.
There is no guarantee in what order those comments are printed, i.e. You would actually get logs:
{"context":{"path":"/endpoint","logLevel":30},"message":"Log event 1","sequence":1,"time":1624305447427,"version":"1.0.0"}
{"context":{"path":"/endpoint","logLevel":30},"message":"Log event 1","sequence":1,"time":1624305451751,"version":"1.0.0"}
{"context":{"path":"/endpoint","logLevel":30},"message":"Log event 2","sequence":2,"time":1624305451751,"version":"1.0.0"}
{"context":{"path":"/endpoint","logLevel":30},"message":"Log event 2","sequence":2,"time":1624305447427,"version":"1.0.0"}
from roarr.
The only to make something like this to work would be to have "threadId" (or some other variable) that is created every time a new async context is created. I cannot think of a simple way to implement that.
from roarr.
There is no guarantee in what order those comments are printed, i.e. You would actually get logs:
{"context":{"path":"/endpoint","logLevel":30},"message":"Log event 1","sequence":1,"time":1624305447427,"version":"1.0.0"} {"context":{"path":"/endpoint","logLevel":30},"message":"Log event 1","sequence":1,"time":1624305451751,"version":"1.0.0"} {"context":{"path":"/endpoint","logLevel":30},"message":"Log event 2","sequence":2,"time":1624305451751,"version":"1.0.0"} {"context":{"path":"/endpoint","logLevel":30},"message":"Log event 2","sequence":2,"time":1624305447427,"version":"1.0.0"}
Oh yes agreed that can happen, but that is fine for me since in the real thing I will have request IDs forwarded to the application from outside. So a bit of jumbled re-ordering is fine. My example was probably too simplistic to showcase my tolerance for re-ordering across parallel execution
The main aim is just to have the sequence "restarted"/"reset" per distinct request. My thought was that if a sequence
argument can be provided through the .child(...)
API, the provided sequence can be used instead of incrementing the global sequence value. Would something like this be okay and align with your thoughts?
from roarr.
@gajus just wondering if you had the chance to see and think about my reply above
from roarr.
For your specific case, can you not just add a second sequence ID?
child
allows you to define arbitrary middleware.
All you have to do is create a sequence
property in context
.
I cannot see broad applications for what is being asked.
Closing the issue, but please continue discussion if I am missing anything.
I do want to find a way to track individual async operations, though. That's a separate issue it seems.
from roarr.
from roarr.
@gajus sorry I haven't been monitoring the notifications. But amazing! Thank you for the work
from roarr.
Related Issues (20)
- Rename "warn" to "warning"
- Rename "logLevelName" to "severityName"
- Cannot re-assign log level using transformer HOT 2
- Allow filtering by logger name HOT 8
- [TS] Context types HOT 1
- version 7.1.0 started giving compile errors HOT 1
- JsonObject<T> -- Index signature for type 'string' is missing in type HOT 1
- Allow adopt to extend context using a function, just like child does HOT 1
- Add warnOnce and other methods HOT 4
- Improve message filtering HOT 1
- Consider simplifying log function interface HOT 2
- Send logs from browser to server HOT 1
- Need to upgrade the major version number? HOT 8
- MaxListenersExceededWarning: Possible EventEmitter memory leak detected HOT 3
- No logging inside Docker containers HOT 1
- Package version 7.15.3 has a node engine version breaking change HOT 1
- Respect ROARR_LOG while running Jest UI tests
- How is roarr non blocking? HOT 1
- Feature Request: Improved logic for truncation of context
- [Question] Where is the schema-based serialisation
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 roarr.