File tree Expand file tree Collapse file tree 4 files changed +15
-2
lines changed Expand file tree Collapse file tree 4 files changed +15
-2
lines changed Original file line number Diff line number Diff line change 11# 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+
26## [ 1.0.1] - 30-03-2024
37### Added
48- 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 11{
22 "name" : " logestic" ,
3- "version" : " 1.0.1 " ,
3+ "version" : " 1.1.0 " ,
44 "author" :
" Nishant Aanjaney Jalan <[email protected] >" ,
55 "description" : " An advanced and customisable logging library for ElysiaJS" ,
66 "keywords" : [
Original file line number Diff line number Diff line change @@ -129,8 +129,16 @@ export class Logestic<K extends keyof Attribute = keyof Attribute> {
129129 format ( this : Logestic , formatAttr : Callback < K > ) {
130130 return this . build ( )
131131 . state ( 'logestic_timeStart' , 0n )
132- . onRequest ( ( { store } ) => {
132+ . onRequest ( ( { store, request } ) => {
133133 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+ }
134142 } )
135143 . onResponse ( { as : 'global' } , ctx => {
136144 if ( ! this . httpLogging ) {
Original file line number Diff line number Diff line change @@ -36,6 +36,7 @@ export type Preset = 'common' | 'fancy';
3636 * `Callback` is an object that contains functions to format successful and failed logs.
3737 */
3838export type Callback < K extends keyof Attribute > = {
39+ onRequest ?: ( attr : Request ) => string ;
3940 onSuccess : ( attr : Pick < Attribute , K > ) => string ;
4041 onFailure : ( attr : ErrorAttribute ) => string ;
4142} ;
You can’t perform that action at this time.
0 commit comments