Skip to content

Commit

Permalink
feat(logs): regex to remove ANSI escape in redis
Browse files Browse the repository at this point in the history
  • Loading branch information
Mathu-lmn committed Jul 28, 2024
1 parent dd6f70f commit 891a1ad
Showing 1 changed file with 10 additions and 0 deletions.
10 changes: 10 additions & 0 deletions src/realms/rest/emitter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -91,12 +91,22 @@ export const emitterMessage = Type.Union(

export type EmitterMessage = Static<typeof emitterMessage>

// eslint-disable-next-line no-control-regex
const ANSI_ESCAPE = /\x1b\[[0-9;]*m/g;

function removeAnsiColorCodes(str: string):string {
return str.replace(ANSI_ESCAPE, "");
}

export const prepareRedisListeners = () => {
const redisSubscriptionClient = new RedisClient()
redisSubscriptionClient.client.subscribe("emitter")
redisSubscriptionClient.client.on("message", (channel, message) => {
if (channel === "emitter") {
const body = JSON.parse(message.toString()) as EmitterMessage
if (body.type === "serverLog") {
body.payload.message = removeAnsiColorCodes(body.payload.message)
}
emitter.emit(body.type, body.payload)
}
})
Expand Down

0 comments on commit 891a1ad

Please sign in to comment.