mirror of
https://github.com/mathew-kurian/Scribe.js
synced 2025-04-24 22:34:58 +00:00
Add expressLogger example
This commit is contained in:
parent
4d1f4e6ac6
commit
f8a4b4b1ec
3 changed files with 75 additions and 20 deletions
13
examples/expressLogger.js
Normal file
13
examples/expressLogger.js
Normal file
|
@ -0,0 +1,13 @@
|
||||||
|
/* jshint -W098 */
|
||||||
|
(function () {
|
||||||
|
var scribe = require('../scribe')(),
|
||||||
|
express = require('express'),
|
||||||
|
app = express(),
|
||||||
|
console = process.console;
|
||||||
|
|
||||||
|
app.use(scribe.express.logger()); //Log each request
|
||||||
|
|
||||||
|
app.listen(8080, function () {
|
||||||
|
console.time().log('Server listening at port 8080');
|
||||||
|
});
|
||||||
|
}());
|
40
examples/expressLogger_custom.js
Normal file
40
examples/expressLogger_custom.js
Normal file
|
@ -0,0 +1,40 @@
|
||||||
|
/* jshint -W098 */
|
||||||
|
(function () {
|
||||||
|
var scribe = require('../scribe')(),
|
||||||
|
express = require('express'),
|
||||||
|
app = express(),
|
||||||
|
console = process.console;
|
||||||
|
|
||||||
|
//Create a Console2 for express
|
||||||
|
//with logs saved in /expressLogger
|
||||||
|
var expressConsole = scribe.console({
|
||||||
|
console : {
|
||||||
|
colors : 'white',
|
||||||
|
timeColors : ['grey', 'underline'],
|
||||||
|
},
|
||||||
|
createBasic : false,
|
||||||
|
logWriter : {
|
||||||
|
rootPath : 'expressLogger'
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
expressConsole.addLogger('info'); //create a 'info' logger
|
||||||
|
|
||||||
|
//A filter function
|
||||||
|
var validate = function (req, res) {
|
||||||
|
|
||||||
|
//if (something) {
|
||||||
|
// return false //ie. don't log this request
|
||||||
|
//else
|
||||||
|
//{
|
||||||
|
|
||||||
|
return true;
|
||||||
|
};
|
||||||
|
|
||||||
|
//Pass the console and the filter
|
||||||
|
app.use(scribe.express.logger(expressConsole, validate));
|
||||||
|
|
||||||
|
app.listen(8080, function () {
|
||||||
|
console.time().log('Server listening at port 8080');
|
||||||
|
});
|
||||||
|
}());
|
|
@ -1,28 +1,30 @@
|
||||||
/* jshint -W079 */
|
/* jshint -W079 */
|
||||||
var scribe = require('../scribe')(),
|
(function () {
|
||||||
console = process.console,
|
var scribe = require('../scribe')(),
|
||||||
express = require('express'),
|
console = process.console,
|
||||||
app = express();
|
express = require('express'),
|
||||||
|
app = express();
|
||||||
|
|
||||||
|
|
||||||
app.get('/', function (req, res) {
|
app.get('/', function (req, res) {
|
||||||
res.send('Hello world, see you at /logs');
|
res.send('Hello world, see you at /logs');
|
||||||
});
|
});
|
||||||
|
|
||||||
app.use('/logs', scribe.webPanel());
|
app.use('/logs', scribe.webPanel());
|
||||||
|
|
||||||
|
|
||||||
//Make some logs
|
//Make some logs
|
||||||
console.addLogger('debug', 'inverse');
|
console.addLogger('debug', 'inverse');
|
||||||
console.addLogger('fun', 'rainbow');
|
console.addLogger('fun', 'rainbow');
|
||||||
|
|
||||||
console.time().fun('hello world');
|
console.time().fun('hello world');
|
||||||
console.tag('This is a test').debug('A test');
|
console.tag('This is a test').debug('A test');
|
||||||
console.tag('An object').log({
|
console.tag('An object').log({
|
||||||
a: 'b',
|
a: 'b',
|
||||||
c : [1, 2, 3]
|
c : [1, 2, 3]
|
||||||
});
|
});
|
||||||
|
|
||||||
app.listen(8080, function () {
|
app.listen(8080, function () {
|
||||||
console.time().log('Server listening at port 8080');
|
console.time().log('Server listening at port 8080');
|
||||||
});
|
});
|
||||||
|
}());
|
||||||
|
|
Loading…
Add table
Reference in a new issue