Skip to content

Commit 6e58ce0

Browse files
committed
seneca.quiet
1 parent e3564ed commit 6e58ce0

File tree

4 files changed

+93
-65
lines changed

4 files changed

+93
-65
lines changed

lib/api.js

Lines changed: 36 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,42 @@ var errlog = Common.make_standard_err_log_entry
1212

1313
var intern = {}
1414

15+
16+
// TODO: logging needs to be able to support this withtou awkwardness!
17+
exports.quiet = function() {
18+
this.options({log:{level:'warn'}})
19+
this.private$.logger = Logging.preload.call(this).extend.logger
20+
return this
21+
}
22+
23+
24+
exports.test = function(errhandler, logspec) {
25+
var opts = this.options()
26+
27+
if ('-' != opts.tag) {
28+
this.root.id =
29+
null == opts.id$
30+
? this.private$.actnid().substring(0, 4) + '/' + opts.tag
31+
: '' + opts.id$
32+
}
33+
34+
if ('function' !== typeof errhandler && null !== errhandler) {
35+
logspec = errhandler
36+
errhandler = null
37+
}
38+
39+
this.options({
40+
errhandler: null == errhandler ? null : errhandler,
41+
test: true,
42+
log: logspec || 'test'
43+
})
44+
45+
this.private$.logger = Logging.preload.call(this).extend.logger
46+
47+
return this
48+
}
49+
50+
1551
// use('pluginname') - built-in, or provide calling code 'require' as seneca opt
1652
// use(require('pluginname')) - plugin object, init will be called
1753
// if first arg has property senecaplugin
@@ -62,31 +98,6 @@ exports.translate = function(from_in, to_in) {
6298
return this
6399
}
64100

65-
exports.test = function(errhandler, logspec) {
66-
var opts = this.options()
67-
68-
if ('-' != opts.tag) {
69-
this.root.id =
70-
null == opts.id$
71-
? this.private$.actnid().substring(0, 4) + '/' + opts.tag
72-
: '' + opts.id$
73-
}
74-
75-
if ('function' !== typeof errhandler && null !== errhandler) {
76-
logspec = errhandler
77-
errhandler = null
78-
}
79-
80-
this.options({
81-
errhandler: null == errhandler ? null : errhandler,
82-
test: true,
83-
log: logspec || 'test'
84-
})
85-
86-
this.private$.logger = Logging.preload.call(this).extend.logger
87-
88-
return this
89-
}
90101

91102
exports.gate = function() {
92103
return this.delegate({ gate$: true })

package-lock.json

Lines changed: 46 additions & 39 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

seneca.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -372,10 +372,11 @@ function make_seneca(initial_options) {
372372
root$.client = API.client(callpoint) // Send outbound messages.
373373
root$.gate = API.gate // Create a delegate that executes actions in sequence.
374374
root$.ungate = API.ungate // Execute actions in parallel.
375-
root$.test = API.test // Set test mode.
376375
root$.translate = API.translate // Translate message to new pattern.
377376
root$.ping = API.ping // Generate ping response.
378377
root$.use = API.use // Define and load a plugin.
378+
root$.test = API.test // Set test mode.
379+
root$.quiet = API.quiet // Convenience method to set logging level to `warn+`.
379380

380381
root$.add = api_add // Add a pattern an associated action.
381382
root$.act = api_act // Submit a message and trigger the associated action.
@@ -1045,6 +1046,7 @@ function make_seneca(initial_options) {
10451046
}
10461047
}
10471048

1049+
// TODO: in 4.x, when given options, it should chain
10481050
// Allow chaining with seneca.options({...}, true)
10491051
// see https://github.com/rjrodger/seneca/issues/80
10501052
return chain ? self : opts.$

test/logging.test.js

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,14 @@ describe('logging', function() {
3232
})
3333
})
3434

35+
it('quiet', function(fin) {
36+
Seneca()
37+
.quiet()
38+
.error(fin)
39+
.ready(fin)
40+
})
41+
42+
3543
it('basic', function(fin) {
3644
var capture = make_log_capture()
3745

0 commit comments

Comments
 (0)