Skip to content

Commit 5be2aa2

Browse files
committed
fix: warning spacing
1 parent a67de6a commit 5be2aa2

File tree

6 files changed

+180
-145
lines changed

6 files changed

+180
-145
lines changed

lib/formatters.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,7 @@ export class Formatter {
133133
if (!this.emojiMap?.[level]) return '';
134134
const endlen = 5;
135135
const emoji = this.emojiMap[level];
136-
const padding = isWideEmoji(emoji(this.supportsUnicode)) ? ' ' : ' ';
136+
const padding = ' ';
137137
const formattedLevel = this.chalk[colorMap[level]](level.toUpperCase());
138138
const endPadding = endlen - level.length;
139139
return (

scripts/create-sample-output.ts

Lines changed: 141 additions & 142 deletions
Original file line numberDiff line numberDiff line change
@@ -4,120 +4,119 @@ const _prettify = createPrettify();
44
// eslint-disable-next-line @typescript-eslint/no-unsafe-argument
55
const 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

122121
console.log(
123122
prettify({
@@ -136,34 +135,34 @@ console.log(
136135

137136
console.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

168167
const err = new Error('Different error keys supported by default too!');
169168
console.log(

scripts/sample-http.ts

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
import {prettify as createPrettify} from '../index.ts';
2+
3+
const _prettify = createPrettify();
4+
const prettify = (obj: Record<string, unknown>) =>
5+
_prettify(obj)?.replace(/\n$/, '');
6+
7+
const createBasicMessage = (level: number, withStatusCode: boolean, inc = 0) =>
8+
prettify({
9+
level,
10+
msg: withStatusCode ? 'Request Complete' : 'Some data in the request',
11+
time: new Date().toISOString(),
12+
req: {
13+
id: inc + 1,
14+
method: 'GET',
15+
url: '/api/basic',
16+
},
17+
res: {
18+
statusCode: withStatusCode ? 200 : undefined,
19+
},
20+
data: {
21+
sample: 'data',
22+
},
23+
});
24+
25+
console.log(createBasicMessage(10, false, 0));
26+
console.log(createBasicMessage(10, true, 1));
27+
console.log(createBasicMessage(20, false, 2));
28+
console.log(createBasicMessage(20, true, 3));
29+
console.log(createBasicMessage(30, false, 4));
30+
console.log(createBasicMessage(30, true, 5));
31+
console.log(createBasicMessage(40, false, 6));
32+
console.log(createBasicMessage(40, true, 7));
33+
console.log(createBasicMessage(50, false, 8));
34+
console.log(createBasicMessage(50, true, 9));
35+
console.log(createBasicMessage(60, false, 10));
36+
console.log(createBasicMessage(60, true, 11));

test/formatters.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ test('formatLevel', async (t) => {
3030
t.is(info, '✨ INFO ');
3131

3232
const warn = stripAnsi(formatLevel(40));
33-
t.is(warn, '⚠️ WARN ');
33+
t.is(warn, '⚠️ WARN ');
3434

3535
const error = stripAnsi(formatLevel(50));
3636
t.is(error, '🚨 ERROR');

test/snapshots/pino.test.ts.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -158,7 +158,7 @@ Generated by [AVA](https://avajs.dev).
158158

159159
> Snapshot 4
160160
161-
`[90m[7:00:00.000 pm][39m ⚠️ [33mWARN[39m [33mwarn message[39m␊
161+
`[90m[7:00:00.000 pm][39m ⚠️ [33mWARN[39m [33mwarn message[39m␊
162162
`
163163

164164
> Snapshot 5

test/snapshots/pino.test.ts.snap

-4 Bytes
Binary file not shown.

0 commit comments

Comments
 (0)