Skip to content

Commit

Permalink
chore: fix logger console usage
Browse files Browse the repository at this point in the history
  • Loading branch information
kettanaito committed Sep 17, 2024
1 parent 434e4cf commit fde2b4e
Showing 1 changed file with 24 additions and 0 deletions.
24 changes: 24 additions & 0 deletions src/core/ws/utils/attachWebSocketLogger.ts
Original file line number Diff line number Diff line change
Expand Up @@ -117,12 +117,15 @@ export function attachWebSocketLogger(
export function logConnectionOpen(client: WebSocketClientConnection) {
const publicUrl = toPublicUrl(client.url)

// eslint-disable-next-line no-console
console.groupCollapsed(
devUtils.formatMessage(`${getTimestamp()} %c▶%c ${publicUrl}`),
`color:${colors.blue}`,
'color:inherit',
)
// eslint-disable-next-line no-console
console.log('Client:', client.socket)
// eslint-disable-next-line no-console
console.groupEnd()
}

Expand All @@ -135,6 +138,7 @@ export async function logOutgoingClientMessage(
const byteLength = getMessageLength(event.data)
const publicData = await getPublicData(event.data)

// eslint-disable-next-line no-console
console.groupCollapsed(
devUtils.formatMessage(
`${getTimestamp({ milliseconds: true })} %c↑%c ${publicData} %c${byteLength}%c`,
Expand All @@ -144,7 +148,9 @@ export async function logOutgoingClientMessage(
'color:gray;font-weight:normal',
'color:inherit;font-weight:inherit',
)
// eslint-disable-next-line no-console
console.log(event)
// eslint-disable-next-line no-console
console.groupEnd()
}

Expand All @@ -158,6 +164,7 @@ export async function logOutgoingMockedClientMessage(
const byteLength = getMessageLength(event.data)
const publicData = await getPublicData(event.data)

// eslint-disable-next-line no-console
console.groupCollapsed(
devUtils.formatMessage(
`${getTimestamp({ milliseconds: true })} %c⇡%c ${publicData} %c${byteLength}%c`,
Expand All @@ -167,7 +174,9 @@ export async function logOutgoingMockedClientMessage(
'color:gray;font-weight:normal',
'color:inherit;font-weight:inherit',
)
// eslint-disable-next-line no-console
console.log(event)
// eslint-disable-next-line no-console
console.groupEnd()
}

Expand All @@ -183,6 +192,7 @@ export async function logIncomingClientMessage(
const byteLength = getMessageLength(event.data)
const publicData = await getPublicData(event.data)

// eslint-disable-next-line no-console
console.groupCollapsed(
devUtils.formatMessage(
`${getTimestamp({ milliseconds: true })} %c↓%c ${publicData} %c${byteLength}%c`,
Expand All @@ -192,7 +202,9 @@ export async function logIncomingClientMessage(
'color:gray;font-weight:normal',
'color:inherit;font-weight:inherit',
)
// eslint-disable-next-line no-console
console.log(event)
// eslint-disable-next-line no-console
console.groupEnd()
}

Expand All @@ -206,6 +218,7 @@ export async function logIncomingMockedClientMessage(
const byteLength = getMessageLength(event.data)
const publicData = await getPublicData(event.data)

// eslint-disable-next-line no-console
console.groupCollapsed(
devUtils.formatMessage(
`${getTimestamp({ milliseconds: true })} %c⇣%c ${publicData} %c${byteLength}%c`,
Expand All @@ -215,22 +228,27 @@ export async function logIncomingMockedClientMessage(
'color:gray;font-weight:normal',
'color:inherit;font-weight:inherit',
)
// eslint-disable-next-line no-console
console.log(event)
// eslint-disable-next-line no-console
console.groupEnd()
}

function logConnectionClose(event: CloseEvent) {
const target = event.target as WebSocket
const publicUrl = toPublicUrl(target.url)

// eslint-disable-next-line no-console
console.groupCollapsed(
devUtils.formatMessage(
`${getTimestamp({ milliseconds: true })} %c■%c ${publicUrl}`,
),
`color:${colors.blue}`,
'color:inherit',
)
// eslint-disable-next-line no-console
console.log(event)
// eslint-disable-next-line no-console
console.groupEnd()
}

Expand All @@ -240,6 +258,7 @@ export async function logIncomingServerMessage(
const byteLength = getMessageLength(event.data)
const publicData = await getPublicData(event.data)

// eslint-disable-next-line no-console
console.groupCollapsed(
devUtils.formatMessage(
`${getTimestamp({ milliseconds: true })} %c⇣%c ${publicData} %c${byteLength}%c`,
Expand All @@ -249,21 +268,26 @@ export async function logIncomingServerMessage(
'color:gray;font-weight:normal',
'color:inherit;font-weight:inherit',
)
// eslint-disable-next-line no-console
console.log(event)
// eslint-disable-next-line no-console
console.groupEnd()
}

function logClientError(event: Event) {
const socket = event.target as WebSocket
const publicUrl = toPublicUrl(socket.url)

// eslint-disable-next-line no-console
console.groupCollapsed(
devUtils.formatMessage(
`${getTimestamp({ milliseconds: true })} %c\u00D7%c ${publicUrl}`,
),
`color:${colors.blue}`,
'color:inherit',
)
// eslint-disable-next-line no-console
console.log(event)
// eslint-disable-next-line no-console
console.groupEnd()
}

0 comments on commit fde2b4e

Please sign in to comment.