2016-01-22 08:22:11 -06:00
|
|
|
import cluster from 'cluster'
|
|
|
|
import http from 'http'
|
|
|
|
import express from 'express'
|
2016-04-09 05:09:53 -05:00
|
|
|
import * as Scribe from '../index.js';
|
2016-01-22 19:16:53 -06:00
|
|
|
import * as JSON2 from '../src/libs/JSON2'
|
2016-01-22 08:22:11 -06:00
|
|
|
|
|
|
|
const port = 4005;
|
2016-01-22 10:42:13 -06:00
|
|
|
const socketPort = 50000;
|
2016-01-22 08:22:11 -06:00
|
|
|
const cpus = 4;
|
|
|
|
|
|
|
|
if (cluster.isMaster) {
|
|
|
|
for (var i = 0; i < cpus; i++) {
|
|
|
|
cluster.fork();
|
|
|
|
}
|
|
|
|
} else {
|
2016-04-09 05:09:53 -05:00
|
|
|
const options = {
|
|
|
|
"app": 'cluster-server',
|
|
|
|
"id": process.pid,
|
|
|
|
"module": {
|
|
|
|
"writer/SocketIO": {
|
|
|
|
"port": socketPort + cluster.worker.id - 1,
|
|
|
|
"options": {}
|
2016-01-22 08:22:11 -06:00
|
|
|
},
|
2016-04-09 05:09:53 -05:00
|
|
|
"router/Viewer/client": {
|
|
|
|
"background": "#131B21",
|
|
|
|
"socketPorts": [socketPort, socketPort + 1, socketPort + 2, socketPort + 3]
|
2016-01-22 08:22:11 -06:00
|
|
|
}
|
|
|
|
},
|
2016-04-09 05:09:53 -05:00
|
|
|
"debug": false
|
|
|
|
};
|
|
|
|
|
|
|
|
const console = Scribe.create(options);
|
2016-01-22 08:22:11 -06:00
|
|
|
|
|
|
|
// default tags
|
|
|
|
console.persistent('tags', ['mocha', 'scribe']);
|
|
|
|
|
|
|
|
// basic logging
|
|
|
|
function func(foo, bar) {
|
|
|
|
console.log('func')
|
|
|
|
}
|
|
|
|
|
|
|
|
console.log(JSON2.parse(JSON2.stringify([func, new Promise((req, res)=>0)])));
|
|
|
|
console.log({multi: "object"}, {test: 5}, {date: new Date()});
|
|
|
|
|
|
|
|
// express
|
|
|
|
const app = express();
|
2016-04-09 05:09:53 -05:00
|
|
|
const logger = new Scribe.Middleware.ExpressLogger(console);
|
|
|
|
const viewer = new Scribe.Router.Viewer(console);
|
2016-01-22 08:22:11 -06:00
|
|
|
|
|
|
|
// express logger
|
2016-04-09 05:09:53 -05:00
|
|
|
app.use(logger.getMiddleware());
|
|
|
|
|
|
|
|
// viewer
|
|
|
|
app.use('/scribe', viewer.getRouter());
|
2016-01-22 08:22:11 -06:00
|
|
|
|
|
|
|
// test harness
|
|
|
|
app.get('/test', (req, res) => {
|
|
|
|
console.log({multi: "object"}, {test: 5}, {date: new Date()}).then(()=> {
|
|
|
|
res.json({test: new Array(parseInt(Math.random() * 50)).join('.')})
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
app.listen(port, () => console.log(`Listening to ${port} - Cluster ${cluster.worker.id}`));
|
|
|
|
|
|
|
|
// override default console
|
|
|
|
console.override();
|
|
|
|
|
|
|
|
global.console.log('overriden!');
|
|
|
|
|
|
|
|
console.log(`Go to http://localhost:${port}/scribe`);
|
|
|
|
|
|
|
|
console.trace('This is a trace');
|
|
|
|
|
|
|
|
console.warn('Warning!!');
|
|
|
|
}
|