caesarjs-console-logger-plugin
v0.0.2
Published
A simple Caesar.js server plugin which prints logs over data sent to and received from client.
Downloads
19
Maintainers
Readme
Caesar.js console logger plugin is a very simple serever plugin which allows printing to the console all the data sent to the server and back to the client.
Caesar.js Project's homepage
Install caesajs & the plugin in your Project
npm instal caesarjs caesarjs-console-logger-plugin --save
Usage example
const caesarConsoleLoggerPlugin = require('caesarjs-console-logger-plugin');
const encryptorKey = '33a24560-a43b-44cc-b2bc-9cc0de14a093';
const Server = require('caesarjs').server;
const Client = require('caesarjs').client;
new Server(3000, {encryptorKey})
.installPlugin(caesarConsoleLoggerPlugin())
.add( {role: 'test', cmd: 'testLogger'}, (req, res) => {
const name = req.data.name;
res.caesarJson({ msg: 'Hello Mr Client!' });
})
.listen();
const clientId = 'client-1';
let cclient;
new Client('localhost', 3000, {encryptorKey, clientId})
.init()
.then( (client) => {
cclient = client;
return cclient.call({role: 'test', cmd: 'testLogger'}, {name: 'Caesar!'});
});
This should print something like the following in the console:
{"pid":9520,"hostname":"cgc-Skylake-Platform","level":30,"time":1499130163367,"msg":"Data sent back to client {\"routes\":[{\"urlId\":\"96cbf292-7e20-40d8-ac90-cb4d14fb0ba8\",\"patternObject\":{\"role\":\"stats\",\"cmd\":\"getServerStats\"},\"inputObject\":{}},{\"urlId\":\"b9d9abc2-7a08-463a-86e7-ce3e093f8966\",\"patternObject\":{\"role\":\"test\",\"cmd\":\"testLogger\"},\"inputObject\":{}}]}","v":1}
{"pid":9520,"hostname":"cgc-Skylake-Platform","level":30,"time":1499130163390,"msg":"Data received from clientID: client-1 DATA: {\"name\":\"Caesar!\"}","v":1}
{"pid":9520,"hostname":"cgc-Skylake-Platform","level":30,"time":1499130163391,"msg":"Data sent back to client {\"msg\":\"Hello Mr Client!\"}","v":1}