Skip to content

Commit

Permalink
fix: use stream passthrough
Browse files Browse the repository at this point in the history
  • Loading branch information
robertsLando committed Sep 12, 2024
1 parent c93dfa7 commit ca79c73
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 10 deletions.
13 changes: 9 additions & 4 deletions api/app.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ import { readFile, realpath } from 'fs/promises'
import { generate } from 'selfsigned'
import ZnifferManager, { ZnifferConfig } from './lib/ZnifferManager'
import { getAllNamedScaleGroups, getAllSensors } from '@zwave-js/core'
import { Writable } from 'stream'

const createCertificate = promisify(generate)

Expand Down Expand Up @@ -440,10 +441,14 @@ async function destroyPlugins() {

function setupInterceptor() {
// intercept logs and redirect them to socket
loggers.logStream._write = function (data, _, next) {
socketManager.io.emit(socketEvents.debug, data.toString())
next()
}
loggers.logStream.pipe(
new Writable({
write(chunk, encoding, callback) {
socketManager.io.emit(socketEvents.debug, chunk.toString())
callback()
},
}),
)
}

async function parseDir(dir: string): Promise<StoreFileEntry[]> {
Expand Down
9 changes: 3 additions & 6 deletions api/lib/logger.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import * as path from 'path'
import { readdir, stat, unlink } from 'fs/promises'
import { Stats } from 'fs'
import escapeStringRegexp from '@esm2cjs/escape-string-regexp'
import { Writable } from 'stream'
import { PassThrough } from 'stream'

const { format, transports, addColors } = winston
const { combine, timestamp, label, printf, colorize, splat } = format
Expand Down Expand Up @@ -103,11 +103,8 @@ export function customFormat(
return combine(...formats)
}

export const logStream = new Writable()
logStream._write = function (chunk, encoding, done) {
// noop
done()
}
export const logStream = new PassThrough()

/**
* Create the base transports based on settings provided
*/
Expand Down

0 comments on commit ca79c73

Please sign in to comment.