File tree 4 files changed +15
-2
lines changed
4 files changed +15
-2
lines changed Original file line number Diff line number Diff line change 1
1
# CHANGELOG
2
+ ## [ 1.1.0] - 31-03-2024
3
+ ### Added
4
+ - Optional ` onRequest ` logging formatter for hooking onto onRequest. ([ #13 ] ( https://github.com/cybercoder-naj/logestic/issues/13 ) )
5
+
2
6
## [ 1.0.1] - 30-03-2024
3
7
### Added
4
8
- Type-safety to onSuccess method, based on attributes passed on ` use ` . ([ #6 ] ( https://github.com/cybercoder-naj/logestic/issues/6 ) )
Original file line number Diff line number Diff line change 1
1
{
2
2
"name" : " logestic" ,
3
- "version" : " 1.0.1 " ,
3
+ "version" : " 1.1.0 " ,
4
4
"author" : " Nishant Aanjaney Jalan <cybercoder.nishant@gmail.com>" ,
5
5
"description" : " An advanced and customisable logging library for ElysiaJS" ,
6
6
"keywords" : [
Original file line number Diff line number Diff line change @@ -129,8 +129,16 @@ export class Logestic<K extends keyof Attribute = keyof Attribute> {
129
129
format ( this : Logestic , formatAttr : Callback < K > ) {
130
130
return this . build ( )
131
131
. state ( 'logestic_timeStart' , 0n )
132
- . onRequest ( ( { store } ) => {
132
+ . onRequest ( ( { store, request } ) => {
133
133
store . logestic_timeStart = process . hrtime . bigint ( ) ;
134
+
135
+ if ( formatAttr . onRequest ) {
136
+ let msg = formatAttr . onRequest ( request ) ;
137
+ if ( this . showLevel ) {
138
+ msg = `${ colourLogType ( 'http' , this . logLevelColour ) } ${ msg } ` ;
139
+ }
140
+ this . log ( msg ) ;
141
+ }
134
142
} )
135
143
. onResponse ( { as : 'global' } , ctx => {
136
144
if ( ! this . httpLogging ) {
Original file line number Diff line number Diff line change @@ -36,6 +36,7 @@ export type Preset = 'common' | 'fancy';
36
36
* `Callback` is an object that contains functions to format successful and failed logs.
37
37
*/
38
38
export type Callback < K extends keyof Attribute > = {
39
+ onRequest ?: ( attr : Request ) => string ;
39
40
onSuccess : ( attr : Pick < Attribute , K > ) => string ;
40
41
onFailure : ( attr : ErrorAttribute ) => string ;
41
42
} ;
You can’t perform that action at this time.
0 commit comments