Skip to content

Commit

Permalink
feat(core): print log type in debug
Browse files Browse the repository at this point in the history
  • Loading branch information
wdavidw committed Mar 19, 2024
1 parent 091b713 commit 588fb9c
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 13 deletions.
3 changes: 2 additions & 1 deletion packages/core/lib/plugins/metadata/debug.js
Original file line number Diff line number Diff line change
Expand Up @@ -70,9 +70,10 @@ export default {
: log.message?.toString != null
? log.message.toString().trim()
: JSON.stringify(log.message);
const type = log.type.split('_')[0];
const position = log.position.map((i) => i + 1).join('.');
const name = log.namespace?.join('.') || log.module;
msg = ['[', position + '.' + log.level, name ? ' ' + name : void 0, '] ', msg].join('');
msg = ['[', type, ' ', position + ' ' + log.level, name ? ' ' + name : void 0, '] ', msg].join('');
msg = (function() {
switch (log.type) {
case 'stdin':
Expand Down
24 changes: 12 additions & 12 deletions packages/core/test/plugins/metadata/debug.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ describe 'metadata "debug"', ->
ws.write = (chunk) -> data.push chunk
await nikita.call $debug: ws, ({tools: {log}}) ->
log 'Some message'
data.join().should.eql '\u001b[32m[1.1.INFO call] Some message\u001b[39m\n'
data.join().should.eql '\u001b[32m[text 1.1 INFO call] Some message\u001b[39m\n'

it 'stdin, stdout, stderr', ->
data = []
Expand All @@ -59,10 +59,10 @@ describe 'metadata "debug"', ->
"""
$debug: ws
data.join().should.eql [
'\u001b[33m[1.1.INFO execute] echo to_stdout; echo to_stderr 1>&2\u001b[39m\n'
'\u001b[36m[1.1.INFO execute] to_stdout\u001b[39m\n'
'\u001b[35m[1.1.INFO execute] to_stderr\u001b[39m\n'
'\u001b[32m[1.1.DEBUG execute] Command exit with status: 0\u001b[39m\n'
'\u001b[33m[stdin 1.1 INFO execute] echo to_stdout; echo to_stderr 1>&2\u001b[39m\n'
'\u001b[36m[stdout 1.1 INFO execute] to_stdout\u001b[39m\n'
'\u001b[35m[stderr 1.1 INFO execute] to_stderr\u001b[39m\n'
'\u001b[32m[text 1.1 DEBUG execute] Command exit with status: 0\u001b[39m\n'
].join()

describe 'print', ->
Expand All @@ -75,7 +75,7 @@ describe 'metadata "debug"', ->
$debug: true
$handler: ({tools: {log}}) -> log 'Some message'
process.stderr.write = write
data.join().should.eql '\u001b[32m[1.1.INFO call] Some message\u001b[39m\n'
data.join().should.eql '\u001b[32m[text 1.1 INFO call] Some message\u001b[39m\n'

it 'stdout', ->
data = []
Expand All @@ -85,7 +85,7 @@ describe 'metadata "debug"', ->
$debug: 'stdout'
$handler: ({tools: {log}}) -> log 'Some message'
process.stdout.write = write
data.join().should.eql '\u001b[32m[1.1.INFO call] Some message\u001b[39m\n'
data.join().should.eql '\u001b[32m[text 1.1 INFO call] Some message\u001b[39m\n'

it 'stream writer', ->
data = []
Expand All @@ -94,7 +94,7 @@ describe 'metadata "debug"', ->
await nikita.call
$debug: ws
$handler: ({tools: {log}}) -> log 'Some message'
data.join().should.eql '\u001b[32m[1.1.INFO call] Some message\u001b[39m\n'
data.join().should.eql '\u001b[32m[text 1.1 INFO call] Some message\u001b[39m\n'

describe 'cascade', ->

Expand All @@ -108,8 +108,8 @@ describe 'metadata "debug"', ->
await @call ({tools: {log}}) ->
log 'Child message'
data.join().should.eql [
'\u001b[32m[1.1.INFO call] Parent message\u001b[39m\n'
'\u001b[32m[1.1.2.INFO call] Child message\u001b[39m\n'
'\u001b[32m[text 1.1 INFO call] Parent message\u001b[39m\n'
'\u001b[32m[text 1.1.2 INFO call] Child message\u001b[39m\n'
].join ','

it 'not available in parent', ->
Expand All @@ -120,7 +120,7 @@ describe 'metadata "debug"', ->
log 'Parent message'
@call $debug: ws, ({tools: {log}}) ->
log 'Child message'
data.join().should.eql '\u001b[32m[1.1.1.INFO call] Child message\u001b[39m\n'
data.join().should.eql '\u001b[32m[text 1.1.1 INFO call] Child message\u001b[39m\n'

it 'not available in parent sibling', ->
data = []
Expand All @@ -133,6 +133,6 @@ describe 'metadata "debug"', ->
log 'Child message'
.call ({tools: {log}}) ->
log 'Sibling message'
data.join().should.eql '\u001b[32m[1.1.2.INFO call] Child message\u001b[39m\n'
data.join().should.eql '\u001b[32m[text 1.1.2 INFO call] Child message\u001b[39m\n'


0 comments on commit 588fb9c

Please sign in to comment.