Logging¶
The Service class provides a logging facility that can be
used to log application messages at various logging levels.
Logging messages¶
To support logging the Service class exposes the following
methods:
To log a message you simply use these methods on your
Service object:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 | var carbon = require('carbon-io')
var o = carbon.atom.o(module)
var __ = carbon.fibers.__(module)
__(function() {
module.exports = o.main({
_type: carbon.carbond.Service,
port: 8888,
endpoints: {
hello: o({
_type: carbon.carbond.Endpoint,
get: function(req) {
this.getService().logInfo("GET on /hello called")
try {
// Do stuff
} catch (e) {
this.getService().logError("Error while doing stuff")
}
return {msg: "Hello World!"}
}
})
}
})
})
|
Controling verbosity¶
The verbosity level of your Service at runtime (i.e. which
log levels are logged) can controlled by the
verbosity property of you
Service object.
The verbosity property is a string and can have the following values:
'trace''debug''info''warn''error''fatal'
These values have an ordering, and by setting the
verbosity property to one of these values you are
directing the Service to log all messages with that log
level and any “higher” log level.
For example, setting the verbosity to 'info'
will result in all messages of log level 'info', 'warn', 'error',
and 'fatal' to be logged.
There are two ways to control the verbosity level of a
Service:
- Setting the
verbosityproperty of theServiceas part of its configuration:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 | var carbon = require('carbon-io')
var o = carbon.atom.o(module)
var __ = carbon.fibers.__(module)
__(function() {
module.exports = o.main({
_type: carbon.carbond.Service,
port: 8888,
verbosity: 'info',
/*
* endpoint definitions...
*/
})
})
|
- Using the
-v, --verbosityflag at the commandline to specifity the verbosity level, which will set the value of theverbosityproperty on yourServiceobject.
% node <path-to-your-app>/MyService -v info
Logging output¶
All output of the logging facility is directed to stderr. This can
then be piped manually or via a process manager into log files or to
implement more elaborate logging strategies.