Skip to content

Commit

Permalink
feat(core): let #perform to process log entry instead of input
Browse files Browse the repository at this point in the history
  • Loading branch information
pismenskiy authored Mar 6, 2020
1 parent 3816a62 commit 317927d
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 15 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
"coveralls:push": "cat ./coverage/lcov.info | coveralls",
"jest": "BABEL_ENV=test NODE_ENV=test jest --no-cache -w 1 --detectOpenHandles --config jest.config.json",
"flow": "flow",
"flow:coverage": "flow-coverage-report -i 'packages/**/src/main/**/*.js' -t html -t json -t text --threshold 90",
"flow:coverage": "flow-coverage-report -i 'packages/**/src/main/**/*.js' -t html -t json -t text --threshold 85",
"flow:fetch": "flow-typed install [email protected]",
"lint": "standard packages/**/src/**/*.js packages/**/test/**/*.js",
"lint:fix": "yarn lint --fix",
Expand Down
11 changes: 6 additions & 5 deletions packages/logwrap-core/src/main/js/logwrap.js
Original file line number Diff line number Diff line change
Expand Up @@ -56,16 +56,17 @@ export default class Logwrap implements ILogwrap {
}

static initLogMethod (method: ILogLevel, level: ILogLevel, pipeline: INormalizedPipeline): ILogMethod {
return (...args: IAny): void => this.perform(level, method, pipeline, args)
return (...args: IAny): void => {
const entry = this.normalizeEntry(method, args, {})
return this.perform(level, pipeline, entry)
}
}

static perform (treshold: ILogLevel, level: ILogLevel, pipeline: INormalizedPipeline, input: IAny[]): IAny {
if (!this.validateLevel(treshold, level)) {
static perform (treshold: ILogLevel, pipeline: INormalizedPipeline, entry: ILogEntry): IAny {
if (!this.validateLevel(treshold, entry.level)) {
return
}

const entry = this.normalizeEntry(level, input, {})

return reduce(
pipeline,
(memo, pipe) => pipe(memo) || memo,
Expand Down
8 changes: 6 additions & 2 deletions packages/logwrap-core/src/test/js/logwrap.js
Original file line number Diff line number Diff line change
Expand Up @@ -128,11 +128,15 @@ describe('logwrap-core/logwrap', () => {
const input = ['foo', 'bar']

it('does nothing on log level mismatch', () => {
expect(perform('error', 'warn')).toBeUndefined()
const entry = normalizeEntry('warn', input, {})

expect(perform('error', pipeline, entry)).toBeUndefined()
})

it('processes data though the pipeline', () => {
expect(perform('debug', 'warn', pipeline, input)).toEqual({
const entry = normalizeEntry('warn', input, {})

expect(perform('debug', pipeline, entry)).toEqual({
level: 'warn',
input,
meta: {}
Expand Down
7 changes: 0 additions & 7 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -1814,13 +1814,6 @@
once "^1.4.0"
universal-user-agent "^4.0.0"

"@qiwi/logwrap-core@^1.4.2":
version "1.4.2"
resolved "https://registry.yarnpkg.com/@qiwi/logwrap-core/-/logwrap-core-1.4.2.tgz#90d819bbb98758687ce2771da9440c032a2b0964"
integrity sha512-ZLThJ4VKacxUlitxF6+Ic0fDKj3mlX6P8uOknaIzhy4vccBzbkl9/hq71dMR6wd+36DDMYWbT8TKxVDlVKlZug==
dependencies:
lodash-es "^4.17.15"

"@qiwi/substrate-types@^1.0.0":
version "1.16.0"
resolved "https://registry.yarnpkg.com/@qiwi/substrate-types/-/substrate-types-1.16.0.tgz#3f7e54a8e12bd4f8a7aefd9b563842f38adf0ad1"
Expand Down

0 comments on commit 317927d

Please sign in to comment.