tfg-logging
v1.1.4
Published
Wrapper for the Google Cloud logging winston package. Perfect for use in express applications for logging.
Downloads
4
Readme
TFG Logger
Wrapper for the Google Cloud logging winston package. Perfect for use in express applications for logging.
Quickstart
- Wrap app.js in an async
- Create server in server.js
- Create logger with settings in app.js
- Wrap logger in middleware object
- Mount the middleware object, you now have the two logging objects for use throughout your application
// app.js
async function createServer(){
const TfgLogging = require("../../../_npm/tfg-logging/index");
// Create the winston logger for use throughout the application,
// Logs to console in a correctly formatted way
const tfg_logger = TfgLogging.makeLogger("webber-aio" + '-service',{
environment: env
});
// Make middleware for use in routing,
var mw_logger = await TfgLogging.makeMiddleware(tfg_logger,{
gcp_key_file: path.join(__dirname,"..", ".credentials", "/gcloud_auth_" + env + ".json"),
serviceContext: {
service: "Global"
}
});
return app;
}
// server.js
#!/usr/bin/nodejs
var debug = require('debug')('my-application');
async function main(){
var app = await require('./src/app');
app.set('port', process.env.PORT || 3000);
var server = app.listen(app.get('port'), function() {
debug('Express server listening on port ' + server.address().port);
});
}
main();
Features
- Includes all logging levels 1 - 7
- Includes the service name in the console log - great to filter between multiple services in a single log file
- Prints the stacktrace to the console (bugfix!)
- Sends the logs to GCP
- Nicely formats requests in Stackdriver, includes all logs within a request and the response code
Coming Soon
- Create error reports