Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to support logging (console.log) statement in microcule example java script index.js file? #3

Closed
rishabh1952 opened this issue Jul 5, 2018 · 3 comments

Comments

@rishabh1952
Copy link

rishabh1952 commented Jul 5, 2018

I am not able to find the log statement added with console.log() in microcule java script example index,js.In Microcule any Js example index.js file am adding console.log() ,but that log statement is not displaying in my command prompt.If i use res.write('') that logs displaying in browser,any possibilities to support logging statement using console.log that will display in console not browser?

Index.js

module['exports'] = function helloWorld (req,res) {
//req is a Node.js http.IncomingMessage
var host = req.host;
console.log("host is",host); //Not working
res.end('hello world');
};

@Marak
Copy link
Contributor

Marak commented Jul 5, 2018

What operating system on you on? Is it Windows? Also, what is your node -v and npm -v and microcule -v values returning on console?

The default behavior for console.log in microcule services should be to write directly to your console. This is the default logger that should being run: https://github.com/Stackvana/microcule/blob/master/lib/plugins/logger.js

It's also possible to easily override this logging behavior with your own custom logging middleware.

How are you starting the microcule server?

@rishabh1952
Copy link
Author

rishabh1952 commented Jul 6, 2018

Hi, Yes i am using windows 10 OS with npm-5.6.0, microcule-6.0.0,node-v8.11.1. I tried both way to start microcule first npm start and second direct index file run like microcule ./index.js
Default logging(https://github.com/Stackvana/microcule/blob/master/lib/plugins/logger.js) is displaying my console .
For custom looging in index.js am using console.log() that is not working is it possible to support
logging in console for index.js using console.log()?
I also tried for custom logging using witson library that also not printing logs in console.its printing in output please check below refrence and attached screenshots
Example:

index.js

module['exports'] = function calculateSal(req, res) {
var flow = require('../setup.js');
var logger = require('../logger.js'); //custom logger class using witson
//console.log("input salary is:", req.params.salary); //Not working
//console.log("input pf is:", req.params.pf); //Not working
logger.info('input salary is:%s', req.params.salary);
logger.info('input pf is:%s', req.params.pf);
flow.totalSal(req.params.salary, req.params.pf).then(totalsal => {
res.json({
message: "Salray calculated successfully",
salary: req.params.salary,
PF: req.params.pf,
totalSal: totalsal
});
}).catch(err => {
res.json({
errorMessage: "salary is not proper."
});
});
};

Here just one sample am trying with calculate total salary with post json request using postman
In this total sal function it just adding both salary+pf and return response.

Request: POST- content-type:(application/json)
{
"salary": 25000,
"pf":1800
}

Response in postman in Text format
2018-07-06T06:12:10.191Z info: input salary is:25000
2018-07-06T06:12:10.199Z info: input pf is:1800
{
"message": "Salray calculated successfully",
"salary": "25000",
"PF": "1800",
"totalSal": "26800"
}
Note:
2018-07-06T06:12:10.191Z info: input salary is:25000
2018-07-06T06:12:10.199Z info: input pf is:1800

1.These first two logger i want to print in console.we can print this in console?
2.Second thing am returning response as json(res.json()) why its not return me as json format.its giving me as text format.It is possible to get stdout response as json?
Postman Screenshots attached Please clarify me.
capture

@rishabh1952
Copy link
Author

rishabh1952 commented Jul 8, 2018

Same task am discussing in microcule so closing this task.stackvana/microcule#46

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants