Skip to content

Commit 5ac3c3b

Browse files
committed
fix: updated logger level when logging errors
Errors either bubble up or are handled at some point. Decision to log them out should be made there. IMO we should rarely use `error` level logs because errors are either caught and handled and therefor not exceptional. Or bubble to the top in which case the program crashes. [ci skip]
1 parent 47f209e commit 5ac3c3b

File tree

10 files changed

+17
-36
lines changed

10 files changed

+17
-36
lines changed

src/QUICClient.ts

Lines changed: 2 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -315,19 +315,8 @@ class QUICClient {
315315
*/
316316
protected handleEventQUICClientError = (evt: events.EventQUICClientError) => {
317317
const error = evt.detail;
318-
if (
319-
(error instanceof errors.ErrorQUICConnectionLocal ||
320-
error instanceof errors.ErrorQUICConnectionPeer) &&
321-
((!error.data.isApp &&
322-
error.data.errorCode === ConnectionErrorCode.NoError) ||
323-
(error.data.isApp && error.data.errorCode === 0))
324-
) {
325-
// Log out the excpetion as an info when it is graceful
326-
this.logger.info(utils.formatError(error));
327-
} else {
328-
// Log out the exception as an error when it is not graceful
329-
this.logger.error(utils.formatError(error));
330-
}
318+
// Log out the error
319+
this.logger.info(utils.formatError(error));
331320
if (
332321
error instanceof errors.ErrorQUICClientInternal ||
333322
error instanceof errors.ErrorQUICConnectionInternal

src/QUICConnection.ts

Lines changed: 2 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -181,19 +181,8 @@ class QUICConnection {
181181
) => {
182182
const error = evt.detail;
183183
this.errorLast = error;
184-
if (
185-
(error instanceof errors.ErrorQUICConnectionLocal ||
186-
error instanceof errors.ErrorQUICConnectionPeer) &&
187-
((!error.data.isApp &&
188-
error.data.errorCode === ConnectionErrorCode.NoError) ||
189-
(error.data.isApp && error.data.errorCode === 0))
190-
) {
191-
// Log out the excpetion as an info when it is graceful
192-
this.logger.info(utils.formatError(error));
193-
} else {
194-
// Log out the exception as an error when it is not graceful
195-
this.logger.error(utils.formatError(error));
196-
}
184+
// Log out error for debugging
185+
this.logger.info(utils.formatError(error));
197186
if (error instanceof errors.ErrorQUICConnectionInternal) {
198187
throw error;
199188
}

src/QUICServer.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,8 @@ class QUICServer {
7272
*/
7373
protected handleEventQUICServerError = (evt: events.EventQUICServerError) => {
7474
const error = evt.detail;
75-
this.logger.error(utils.formatError(error));
75+
// Log out error for debugging
76+
this.logger.info(utils.formatError(error));
7677
if (error instanceof errors.ErrorQUICServerInternal) {
7778
throw error;
7879
}

src/QUICSocket.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,8 @@ class QUICSocket {
5656

5757
protected handleEventQUICSocketError = (evt: events.EventQUICSocketError) => {
5858
const error = evt.detail;
59-
this.logger.error(utils.formatError(error));
59+
// Log out error for debugging
60+
this.logger.debug(utils.formatError(error));
6061
};
6162

6263
protected handleEventQUICSocketClose = async () => {

src/QUICStream.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -150,7 +150,8 @@ class QUICStream implements ReadableWritablePair<Uint8Array, Uint8Array> {
150150
protected handleEventQUICStreamError = (evt: events.EventQUICStreamError) => {
151151
const error = evt.detail;
152152
if (error instanceof errors.ErrorQUICStreamInternal) {
153-
this.logger.error(utils.formatError(error));
153+
// Log out error for debugging
154+
this.logger.debug(utils.formatError(error));
154155
throw error;
155156
}
156157
if (

tests/QUICClient.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ import * as testsUtils from './utils';
1515
import { generateTLSConfig, sleep } from './utils';
1616

1717
describe(QUICClient.name, () => {
18-
const logger = new Logger(`${QUICClient.name} Test`, LogLevel.SILENT, [
18+
const logger = new Logger(`${QUICClient.name} Test`, LogLevel.WARN, [
1919
new StreamHandler(
2020
formatting.format`${formatting.level}:${formatting.keys}:${formatting.msg}`,
2121
),

tests/QUICServer.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import * as errors from '@/errors';
1010
import * as testsUtils from './utils';
1111

1212
describe(QUICServer.name, () => {
13-
const logger = new Logger(`${QUICServer.name} Test`, LogLevel.SILENT, [
13+
const logger = new Logger(`${QUICServer.name} Test`, LogLevel.WARN, [
1414
new StreamHandler(
1515
formatting.format`${formatting.level}:${formatting.keys}:${formatting.msg}`,
1616
),

tests/QUICSocket.test.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ import * as events from '@/events';
1313
import * as testsUtils from './utils';
1414

1515
describe(QUICSocket.name, () => {
16-
const logger = new Logger(`${QUICSocket.name} Test`, LogLevel.SILENT, [
16+
const logger = new Logger(`${QUICSocket.name} Test`, LogLevel.WARN, [
1717
new StreamHandler(),
1818
]);
1919
// This has to be setup asynchronously due to key generation
@@ -296,7 +296,7 @@ describe(QUICSocket.name, () => {
296296
test('error and close event lifecycle', async () => {
297297
// We expect error logs
298298
const socketLogger = logger.getChild('abc');
299-
socketLogger.setLevel(LogLevel.SILENT);
299+
socketLogger.setLevel(LogLevel.WARN);
300300
const socket = new QUICSocket({
301301
logger: socketLogger,
302302
});
@@ -865,7 +865,7 @@ describe(QUICSocket.name, () => {
865865
};
866866
// We expect lots of error logs
867867
const socketLogger = logger.getChild('abc');
868-
socketLogger.setLevel(LogLevel.SILENT);
868+
socketLogger.setLevel(LogLevel.WARN);
869869
const socket = new QUICSocket({
870870
logger: socketLogger,
871871
});

tests/QUICStream.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import * as testsUtils from './utils';
1010
import { generateTLSConfig } from './utils';
1111

1212
describe(QUICStream.name, () => {
13-
const logger = new Logger(`${QUICStream.name} Test`, LogLevel.SILENT, [
13+
const logger = new Logger(`${QUICStream.name} Test`, LogLevel.WARN, [
1414
new StreamHandler(
1515
formatting.format`${formatting.level}:${formatting.keys}:${formatting.msg}`,
1616
),

tests/concurrency.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ import { generateTLSConfig, handleStreamProm, sleep } from './utils';
1212
import * as testsUtils from './utils';
1313

1414
describe('Concurrency tests', () => {
15-
const logger = new Logger(`${QUICClient.name} Test`, LogLevel.SILENT, [
15+
const logger = new Logger(`${QUICClient.name} Test`, LogLevel.WARN, [
1616
new StreamHandler(
1717
formatting.format`${formatting.level}:${formatting.keys}:${formatting.msg}`,
1818
),

0 commit comments

Comments
 (0)