@@ -4,120 +4,119 @@ const _prettify = createPrettify();
44// eslint-disable-next-line @typescript-eslint/no-unsafe-argument
55const prettify = ( obj : any ) => _prettify ( obj ) ?. replace ( / \n $ / , '' ) ;
66
7- // const createBasicMessage = (level: number) =>
8- // prettify({
9- // level,
10- // msg: 'Just the most basic message',
11- // });
12-
13- // console.log(createBasicMessage(10));
14- // console.log(createBasicMessage(20));
15- // console.log(createBasicMessage(30));
16- // console.log(createBasicMessage(40));
17- // console.log(createBasicMessage(50));
18- // console.log(createBasicMessage(60));
19-
20- // console.log();
21-
22- // console.log(
23- // 'unformatted output and non-pino output from your app still gets printed, you do not lose ability to console.log anytime you want still!',
24- // );
25-
26- // console.log();
27-
28- // console.log(
29- // prettify({
30- // level: 30,
31- // msg: 'Log lines improve as data is added to the pino log object! Checkout this logger ns field.',
32- // }),
33- // );
34-
35- // console.log(
36- // prettify({
37- // level: 30,
38- // msg: 'This logger has a name! Check it out!',
39- // name: 'NAME',
40- // }),
41- // );
42-
43- // console.log();
44-
45- // // eslint-disable-next-line max-params
46- // const createLogLine = (
47- // level: number,
48- // ns: string,
49- // extra?: any,
50- // msg?: string,
51- // status = true,
52- // ) =>
53- // prettify({
54- // level,
55- // name: 'HTTP',
56- // msg: msg ?? `This is a ${ns} message`,
57- // time: new Date(),
58- // req: {
59- // method: 'POST',
60- // url: `/api/${ns}`,
61- // id: 1,
62- // },
63- // res: {
64- // statusCode: status
65- // ? {
66- // trace: 200,
67- // info: 204,
68- // debug: 200,
69- // warn: 404,
70- // error: 400,
71- // fatal: 500,
72- // }[ns]
73- // : 0,
74- // },
75- // responseTime: Math.random() * 1000,
76- // ...extra,
77- // });
78-
79- // console.log(
80- // prettify({
81- // level: 40,
82- // msg: 'The next few logs will show some http logging! Let\'s give the logger the name "HTTP"',
83- // }),
84- // );
85-
86- // console.log(createLogLine(10, 'trace'));
87- // console.log(createLogLine(20, 'debug'));
88- // console.log(createLogLine(30, 'info'));
89- // console.log(
90- // createLogLine(
91- // 30,
92- // 'info',
93- // null,
94- // 'This is a info message with an unknown status code',
95- // false,
96- // ),
97- // );
98- // console.log(createLogLine(40, 'warn'));
99- // console.log(createLogLine(50, 'error'));
100- // console.log(createLogLine(60, 'fatal'));
101-
102- // console.log();
103-
104- // console.log(
105- // prettify({
106- // level: 20,
107- // msg: 'How does my extra data get displayed?',
108- // any: 'extra data get displayed by',
109- // default: 'in a beautifully formatted, compact object',
110- // just: 'below the log line'.split(' '),
111- // nested: {
112- // data: {
113- // is: 'totally fine',
114- // },
115- // blacklisted: 'and whitelisted fields work for nested data too!',
116- // },
117- // }),
118- // );
119-
120- // console.log();
7+ const createBasicMessage = ( level : number ) =>
8+ prettify ( {
9+ level,
10+ msg : 'Just the most basic message' ,
11+ } ) ;
12+
13+ console . log ( createBasicMessage ( 10 ) ) ;
14+ console . log ( createBasicMessage ( 20 ) ) ;
15+ console . log ( createBasicMessage ( 30 ) ) ;
16+ console . log ( createBasicMessage ( 40 ) ) ;
17+ console . log ( createBasicMessage ( 50 ) ) ;
18+ console . log ( createBasicMessage ( 60 ) ) ;
19+
20+ console . log ( ) ;
21+
22+ console . log (
23+ 'unformatted output and non-pino output from your app still gets printed, you do not lose ability to console.log anytime you want still!' ,
24+ ) ;
25+
26+ console . log ( ) ;
27+
28+ console . log (
29+ prettify ( {
30+ level : 30 ,
31+ msg : 'Log lines improve as data is added to the pino log object! Checkout this logger ns field.' ,
32+ } ) ,
33+ ) ;
34+
35+ console . log (
36+ prettify ( {
37+ level : 30 ,
38+ msg : 'This logger has a name! Check it out!' ,
39+ name : 'NAME' ,
40+ } ) ,
41+ ) ;
42+
43+ console . log ( ) ;
44+
45+ const createLogLine = (
46+ level : number ,
47+ ns : string ,
48+ extra ?: any ,
49+ msg ?: string ,
50+ status = true ,
51+ ) =>
52+ prettify ( {
53+ level,
54+ name : 'HTTP' ,
55+ msg : msg ?? `This is a ${ ns } message` ,
56+ time : new Date ( ) ,
57+ req : {
58+ method : 'POST' ,
59+ url : `/api/${ ns } ` ,
60+ id : 1 ,
61+ } ,
62+ res : {
63+ statusCode : status
64+ ? {
65+ trace : 200 ,
66+ info : 204 ,
67+ debug : 200 ,
68+ warn : 404 ,
69+ error : 400 ,
70+ fatal : 500 ,
71+ } [ ns ]
72+ : 0 ,
73+ } ,
74+ responseTime : Math . random ( ) * 1000 ,
75+ ...extra ,
76+ } ) ;
77+
78+ console . log (
79+ prettify ( {
80+ level : 40 ,
81+ msg : 'The next few logs will show some http logging! Let\'s give the logger the name "HTTP"' ,
82+ } ) ,
83+ ) ;
84+
85+ console . log ( createLogLine ( 10 , 'trace' ) ) ;
86+ console . log ( createLogLine ( 20 , 'debug' ) ) ;
87+ console . log ( createLogLine ( 30 , 'info' ) ) ;
88+ console . log (
89+ createLogLine (
90+ 30 ,
91+ 'info' ,
92+ null ,
93+ 'This is a info message with an unknown status code' ,
94+ false ,
95+ ) ,
96+ ) ;
97+ console . log ( createLogLine ( 40 , 'warn' ) ) ;
98+ console . log ( createLogLine ( 50 , 'error' ) ) ;
99+ console . log ( createLogLine ( 60 , 'fatal' ) ) ;
100+
101+ console . log ( ) ;
102+
103+ console . log (
104+ prettify ( {
105+ level : 20 ,
106+ msg : 'How does my extra data get displayed?' ,
107+ any : 'extra data get displayed by' ,
108+ default : 'in a beautifully formatted, compact object' ,
109+ just : 'below the log line' . split ( ' ' ) ,
110+ nested : {
111+ data : {
112+ is : 'totally fine' ,
113+ } ,
114+ blacklisted : 'and whitelisted fields work for nested data too!' ,
115+ } ,
116+ } ) ,
117+ ) ;
118+
119+ console . log ( ) ;
121120
122121console . log (
123122 prettify ( {
@@ -136,34 +135,34 @@ console.log(
136135
137136console . log ( ) ;
138137
139- // const aggErr1 = new Error('aggy errors are easy');
140- // const aggErr2 = new Error('throw em all the time!');
141- // console.log(
142- // prettify({
143- // level: 60,
144- // time: new Date(),
145- // msg: 'What about aggregate errors??',
146- // err: {
147- // message: 'the primary aggregate error',
148- // aggregateErrors: [
149- // {
150- // message: aggErr1.message,
151- // stack: aggErr1.stack,
152- // extra: 'data',
153- // gets: "added just like you'd expect!!",
154- // errors: 'from anywhere look great',
155- // },
156- // {
157- // message: aggErr2.message,
158- // stack: aggErr2.stack,
159- // extra: 'data',
160- // gets: "added just like you'd expect!!",
161- // errors: 'from anywhere look great',
162- // },
163- // ],
164- // },
165- // }),
166- // );
138+ const aggErr1 = new Error ( 'aggy errors are easy' ) ;
139+ const aggErr2 = new Error ( 'throw em all the time!' ) ;
140+ console . log (
141+ prettify ( {
142+ level : 60 ,
143+ time : new Date ( ) ,
144+ msg : 'What about aggregate errors??' ,
145+ err : {
146+ message : 'the primary aggregate error' ,
147+ aggregateErrors : [
148+ {
149+ message : aggErr1 . message ,
150+ stack : aggErr1 . stack ,
151+ extra : 'data' ,
152+ gets : "added just like you'd expect!!" ,
153+ errors : 'from anywhere look great' ,
154+ } ,
155+ {
156+ message : aggErr2 . message ,
157+ stack : aggErr2 . stack ,
158+ extra : 'data' ,
159+ gets : "added just like you'd expect!!" ,
160+ errors : 'from anywhere look great' ,
161+ } ,
162+ ] ,
163+ } ,
164+ } ) ,
165+ ) ;
167166
168167const err = new Error ( 'Different error keys supported by default too!' ) ;
169168console . log (
0 commit comments