-
Notifications
You must be signed in to change notification settings - Fork 114
Logging
The logger class gives Zetta developer access to printing nicely formatted messages to STDOUT or STDERR. You can also replace Zetta logging with a custom logger such as bunyan or winston.
The logger itself is accessible anywhere you would write code in Zetta. Below are examples on how to access Zetta logging from different types of files.
Device
MyDevice.prototype.init = function(config) {
this.info('some info message', { hello: 'world'});
};
App
module.exports = function(server) {
server.info('some info message', { hello: 'world'});
};
Scout
MyScout.prototype.init = function(next) {
this.server.info('some info message', { hello: 'world'});
};
-
message
String -
data
Object
info
will print a standard blue log message to the console output. message
is the particular message to be printed, and data is any relevant accompanying data.
server.info('Hello world', { 'hello': 'world' });
-
message
String -
data
Object
warn
will print a standard yellow log message to the console output. message
is the particular message to be printed, and data is any relevant accompanying data.
server.warn('Hello world', { 'hello': 'world' });
-
message
String -
data
Object
error
will print a standard red log message to the console output. message
is the particular message to be printed, and data is any relevant accompanying data.
server.error('Hello world', { 'hello': 'world' });
-
message
String -
data
Object
log
will print a standard blue log message to the console output. message
is the particular message to be printed, and data is any relevant accompanying data. Is a copy of .info()
server.log('Hello world', { 'hello': 'world' });
Zetta allows to setup log message interception for using custom loggers.
On the Zetta server use the .logger()
function to set this up. An example is below.
zetta()
.logger(function(log) {
//log is an event emitter
log.on('message', function(level, event, msg, data) {
//Fires for any log message
});
log.on('info', function(event, msg, data) {
//info event
});
log.on('warn', function(event, msg, data) {
//warn event
});
log.on('error', function(event, msg, data) {
//error event
});
})
Zetta can also suppress logs using the .silent()
method.
//Logs no longer printed.
zetta()
.silent()
.listen(3000);
Need help? Visit the Zetta Discuss List !
Need help? Visit the Zetta Discuss List ! |
---|
About Zetta
Videos and webcasts
- NEW! Building with Zetta
Tutorials
- NEW! Zetta tutorial series
- Quick start
- Configure a simple device
- Build a mock LED device
- Use the browser client
- Deploy a Zetta server to Heroku
Understanding Zetta
Writing Zetta drivers
- Finding Zetta device drivers
- Create a device driver from starter code
- More coming soon...
Using streams
Reference