-
Notifications
You must be signed in to change notification settings - Fork 215
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
d432dea
commit d10fccd
Showing
2 changed files
with
43 additions
and
9 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
/* eslint-env node */ | ||
|
||
import { makeFsStreamWriter } from '@agoric/internal/src/node/fs-stream.js'; | ||
import { makeContextualSlogProcessor } from './context-aware-slog.js'; | ||
import { serializeSlogObj } from './serialize-slog-obj.js'; | ||
|
||
/** | ||
* @param {import('./index.js').MakeSlogSenderOptions} options | ||
*/ | ||
export const makeSlogSender = async options => { | ||
const { CHAIN_ID, CONTEXTUAL_SLOGFILE } = options.env || {}; | ||
if (!CONTEXTUAL_SLOGFILE) | ||
return console.warn( | ||
'Ignoring invocation of slogger "context-aware-slog-file" without the presence of "CONTEXTUAL_SLOGFILE"', | ||
); | ||
|
||
const stream = await makeFsStreamWriter(CONTEXTUAL_SLOGFILE); | ||
|
||
if (!stream) | ||
return console.error( | ||
`Couldn't create a write stream on file "${CONTEXTUAL_SLOGFILE}"`, | ||
); | ||
|
||
const contextualSlogProcessor = makeContextualSlogProcessor({ | ||
'chain-id': CHAIN_ID, | ||
}); | ||
|
||
/** | ||
* @param {import('./context-aware-slog.js').Slog} slog | ||
*/ | ||
const slogSender = slog => | ||
stream.write(`${serializeSlogObj(contextualSlogProcessor(slog))}\n`); | ||
|
||
return Object.assign(slogSender, { | ||
forceFlush: () => stream.flush(), | ||
shutdown: () => stream.close(), | ||
}); | ||
}; |
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