Skip to content

Commit

Permalink
Add color highlighting for log levels in outputFns.js and fix order o…
Browse files Browse the repository at this point in the history
…f execution in utilFns.js
  • Loading branch information
nmaguiar committed Feb 24, 2024
1 parent 0ab0168 commit c68dd46
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 5 deletions.
7 changes: 6 additions & 1 deletion src/include/outputFns.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,13 @@ var _outputFns = new Map([
let d = (isDef(_r["@timestamp"]) ? _r["@timestamp"] : __)
let l = (isDef(_r.level) ? _r.level : __)
let m = (isDef(_r.message) ? _r.message : __)
let lineC
if (isDef(l)) {
if (l.toLowerCase().indexOf("err") >= 0) lineC = "RED,BOLD"
if (l.toLowerCase().indexOf("warn") >= 0) lineC = "YELLOW"
}
if (isDef(d) && d.length > 24) d = d.substring(0, 23) + "Z"
if (isDef(m) || isDef(d)) print(ansiColor("BOLD", d) + (isDef(l) ? " | " + l : "") + " | " + m)
if (isDef(m) || isDef(d)) print(ansiColor("BOLD", d) + (isDef(l) ? " | " + ansiColor(lineC, l) : "") + " | " + ansiColor(lineC, m))
}
})
}
Expand Down
5 changes: 3 additions & 2 deletions src/include/utilFns.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,13 @@ const _transform = r => {
return r
}
const _$f = (r, options) => {
if (isString(r)) return _transform(r)

if (options.__path) {
r = $path(r, options.__path.trim())
delete options.__path
}

if (isString(r)) return _transform(r)

if (options.__from) {
r = $from(r).query(af.fromNLinq(options.__from.trim()))
delete options.__from
Expand Down
4 changes: 2 additions & 2 deletions src/oafp.source.js.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -368,10 +368,10 @@ if (!noFurtherOutput) {
}

// Determine input type and execute
if (isDef(_inputFns.has(params.type))) {
if (isDef(params.type) && _inputFns.has(params.type)) {
_inputFns.get(params.type)(_res, options)
} else {
printErr("WARN: " + params.type + " input type not supported. Using json.")
if (isString(params.type)) printErr("WARN: " + params.type + " input type not supported. Using json.")
_inputFns.get("json")(_res, options)
}
}
Expand Down

0 comments on commit c68dd46

Please sign in to comment.