-
Notifications
You must be signed in to change notification settings - Fork 13
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Loading status checks…
feat: load config from pino on startup (#90)
* feat: load config from pino on startup * docs: typo in README Co-authored-by: James Sumners <321201+jsumners@users.noreply.github.com> * feat: updated types to include expectPinoConfig --------- Co-authored-by: James Sumners <321201+jsumners@users.noreply.github.com>
- Loading branch information
1 parent
c27de94
commit 0ba2e9f
Showing
11 changed files
with
581 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
'use strict' | ||
|
||
const build = require('../..') | ||
|
||
module.exports = async function (threadStreamOpts) { | ||
const { port, opts = {} } = threadStreamOpts | ||
return build( | ||
async function (source) { | ||
for await (const obj of source) { | ||
port.postMessage({ | ||
data: obj, | ||
pinoConfig: { | ||
levels: source.levels, | ||
messageKey: source.messageKey, | ||
errorKey: source.errorKey | ||
} | ||
}) | ||
} | ||
}, | ||
opts | ||
) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
'use strict' | ||
|
||
const build = require('../..') | ||
|
||
module.exports = async function (threadStreamOpts) { | ||
const { port, opts = {} } = threadStreamOpts | ||
return build( | ||
function (source) { | ||
source.on('data', function (line) { | ||
port.postMessage({ | ||
data: line, | ||
pinoConfig: { | ||
levels: source.levels, | ||
messageKey: source.messageKey, | ||
errorKey: source.errorKey | ||
} | ||
}) | ||
}) | ||
}, | ||
opts | ||
) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
'use strict' | ||
|
||
const { Transform, pipeline } = require('stream') | ||
const build = require('../..') | ||
|
||
module.exports = function (threadStreamOpts) { | ||
const { opts = {} } = threadStreamOpts | ||
return build(function (source) { | ||
const transform = new Transform({ | ||
objectMode: true, | ||
autoDestroy: true, | ||
transform (chunk, enc, cb) { | ||
chunk.service = 'from transform' | ||
chunk.level = `${source.levels.labels[chunk.level]}(${chunk.level})` | ||
chunk[source.messageKey] = chunk[source.messageKey].toUpperCase() | ||
cb(null, JSON.stringify(chunk) + '\n') | ||
} | ||
}) | ||
|
||
pipeline(source, transform, () => {}) | ||
|
||
return transform | ||
}, { ...opts, enablePipelining: true }) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
'use strict' | ||
|
||
const { pipeline, PassThrough } = require('stream') | ||
|
||
module.exports = async function ({ targets }) { | ||
const streams = await Promise.all(targets.map(async (t) => { | ||
const fn = require(t.target) | ||
const stream = await fn(t.options) | ||
return stream | ||
})) | ||
|
||
const stream = new PassThrough() | ||
pipeline(stream, ...streams, () => {}) | ||
return stream | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.