Skip to content

Commit

Permalink
Removed jmespath (#227)
Browse files Browse the repository at this point in the history
* Removed jmespath

* removed search from README
  • Loading branch information
mcollina committed Sep 7, 2021
1 parent cf9c502 commit 0881f18
Show file tree
Hide file tree
Showing 7 changed files with 2 additions and 82 deletions.
7 changes: 2 additions & 5 deletions Readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -81,10 +81,8 @@ node app.js | pino-pretty
- Require a `SYS:` prefix to translate time to the local system's time zone. A
shortcut `SYS:standard` to translate time to `yyyy-mm-dd HH:MM:ss.l o` in
system time zone.
- `--search` (`-s`): Specify a search pattern according to
[jmespath](http://jmespath.org/).
- `--ignore` (`-i`): Ignore one or several keys, nested keys are supported with each property delimited by a dot character (`.`),
keys may be escaped to target property names that contains the delimiter itself:
- `--ignore` (`-i`): Ignore one or several keys, nested keys are supported with each property delimited by a dot character (`.`),
keys may be escaped to target property names that contains the delimiter itself:
(`-i time,hostname,req.headers,log\\.domain\\.corp/foo`)
- `--hideObject` (`-H`): Hide objects from output (but not error object)
- `--singleLine` (`-S`): Print each log message on a single line (errors will still be multi-line)
Expand Down Expand Up @@ -144,7 +142,6 @@ with keys corresponding to the options described in [CLI Arguments](#cliargs):
messageFormat: false, // --messageFormat
timestampKey: 'time', // --timestampKey
translateTime: false, // --translateTime
search: 'foo == `bar`', // --search
ignore: 'pid,hostname', // --ignore
hideObject: false, // --hideObject
singleLine: false, // --singleLine
Expand Down
4 changes: 0 additions & 4 deletions index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -90,10 +90,6 @@ interface PrettyOptions_ {
* @default ""
*/
errorProps?: string;
/**
* Specify a search pattern according to {@link http://jmespath.org|jmespath}
*/
search?: string;
/**
* Ignore one or several keys.
* @example "time,hostname"
Expand Down
12 changes: 0 additions & 12 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ const { options: coloretteOptions } = require('colorette')
const pump = require('pump')
const { Transform } = require('readable-stream')
const abstractTransport = require('pino-abstract-transport')
const jmespath = require('jmespath')
const sonic = require('sonic-boom')
const sjs = require('secure-json-parse')

Expand Down Expand Up @@ -61,9 +60,7 @@ function prettyFactory (options) {
const ignoreKeys = opts.ignore ? new Set(opts.ignore.split(',')) : undefined
const hideObject = opts.hideObject
const singleLine = opts.singleLine

const colorizer = colors(opts.colorize)
const search = opts.search

return pretty

Expand All @@ -80,10 +77,6 @@ function prettyFactory (options) {
log = inputData
}

if (search && !jmespath.search(log, search)) {
return
}

const prettifiedMessage = prettifyMessage({ log, messageKey, colorizer, messageFormat, levelLabel })

if (ignoreKeys) {
Expand Down Expand Up @@ -178,11 +171,6 @@ function build (opts = {}) {
autoDestroy: true,
transform (chunk, enc, cb) {
const line = pretty(chunk)
if (line === undefined) {
cb()
return
}

cb(null, line)
}
})
Expand Down
1 change: 0 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@
"colorette": "^1.3.0",
"dateformat": "^4.5.1",
"fast-safe-stringify": "^2.0.7",
"jmespath": "^0.15.0",
"joycon": "^3.0.0",
"pino-abstract-transport": "^0.2.0",
"pump": "^3.0.0",
Expand Down
33 changes: 0 additions & 33 deletions test/basic.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -443,39 +443,6 @@ test('basic prettifier tests', (t) => {
log.info('foo')
})

t.test('filter some lines based on jmespath', (t) => {
t.plan(3)
const pretty = prettyFactory({ search: 'foo.bar' })
const expected = [
undefined,
undefined,
`[${epoch}] INFO (${pid} on ${hostname}): foo\n foo: {\n "bar": true\n }\n`
]
const log = pino({}, new Writable({
write (chunk, enc, cb) {
const formatted = pretty(chunk.toString())
t.equal(
formatted,
expected.shift()
)
cb()
}
}))
log.info('foo')
log.info({ something: 'else' }, 'foo')
// only this line will be formatted
log.info({ foo: { bar: true } }, 'foo')
})

t.test('handles `undefined` return values', (t) => {
t.plan(2)
const pretty = prettyFactory({ search: 'msg == \'hello world\'' })
let formatted = pretty(`{"msg":"nope", "time":${epoch}, "level":30}`)
t.equal(formatted, undefined)
formatted = pretty(`{"msg":"hello world", "time":${epoch}, "level":30}`)
t.equal(formatted, `[${epoch}] INFO: hello world\n`)
})

t.test('formats a line with an undefined field', (t) => {
t.plan(1)
const pretty = prettyFactory()
Expand Down
25 changes: 0 additions & 25 deletions test/cli.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,31 +47,6 @@ test('cli', (t) => {
})
})

;['--search', '-s'].forEach((optionName) => {
t.test(`does search via ${optionName}`, (t) => {
t.plan(1)
const child = spawn(process.argv[0], [bin, optionName, 'msg == `hello world`'], { env })
child.on('error', t.threw)
child.stdout.on('data', (data) => {
t.equal(data.toString(), `[${epoch}] INFO (42 on foo): hello world\n`)
})
child.stdin.write(logLine)
t.teardown(() => child.kill())
})
})

t.test('does search but finds only 1 out of 2', (t) => {
t.plan(1)
const child = spawn(process.argv[0], [bin, '-s', 'msg == `hello world`'], { env })
child.on('error', t.threw)
child.stdout.on('data', (data) => {
t.equal(data.toString(), `[${epoch}] INFO (42 on foo): hello world\n`)
})
child.stdin.write(logLine.replace('hello world', 'hello universe'))
child.stdin.write(logLine)
t.teardown(() => child.kill())
})

;['--ignore', '-i'].forEach((optionName) => {
t.test('does ignore multiple keys', (t) => {
t.plan(1)
Expand Down
2 changes: 0 additions & 2 deletions test/types/pino-pretty.test-d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ const options: PinoPretty.PrettyOptions = {
messageKey: "msg",
timestampKey: "timestamp",
translateTime: "UTC:h:MM:ss TT Z",
search: "foo == `bar`",
singleLine: false,
customPrettifiers: {
key: (value) => {
Expand All @@ -45,7 +44,6 @@ const options2: PrettyOptions = {
messageKey: "msg",
timestampKey: "timestamp",
translateTime: "UTC:h:MM:ss TT Z",
search: "foo == `bar`",
singleLine: false,
customPrettifiers: {
key: (value) => {
Expand Down

0 comments on commit 0881f18

Please sign in to comment.