chore: truncate long protocol logs (#20412)
This affects the logs in the `DEBUG=pw:protocol` mode so that they never span more then 10 lines of 80-character-width terminal.
This commit is contained in:
parent
cf0ca2e662
commit
5b93c1d2f9
|
|
@ -22,6 +22,8 @@ import { debugLogger } from '../common/debugLogger';
|
|||
import type { RegisteredListener } from '../utils/eventsHelper';
|
||||
import { eventsHelper } from '../utils/eventsHelper';
|
||||
|
||||
const MAX_LOG_LENGTH = process.env.MAX_LOG_LENGTH ? +process.env.MAX_LOG_LENGTH : Infinity;
|
||||
|
||||
class Helper {
|
||||
static completeUserURL(urlString: string): string {
|
||||
if (urlString.startsWith('localhost') || urlString.startsWith('127.0.0.1'))
|
||||
|
|
@ -84,8 +86,12 @@ class Helper {
|
|||
return (direction: 'send' | 'receive', message: object) => {
|
||||
if (protocolLogger)
|
||||
protocolLogger(direction, message);
|
||||
if (debugLogger.isEnabled('protocol'))
|
||||
debugLogger.log('protocol', (direction === 'send' ? 'SEND ► ' : '◀ RECV ') + JSON.stringify(message));
|
||||
if (debugLogger.isEnabled('protocol')) {
|
||||
let text = JSON.stringify(message);
|
||||
if (text.length > MAX_LOG_LENGTH)
|
||||
text = text.substring(0, MAX_LOG_LENGTH / 2) + ' <<<<<( LOG TRUNCATED )>>>>> ' + text.substring(text.length - MAX_LOG_LENGTH / 2);
|
||||
debugLogger.log('protocol', (direction === 'send' ? 'SEND ► ' : '◀ RECV ') + text);
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue