I searched the docs, but found no answer. What is the preferred way of turning on access logging?
I expect HTTP verb, requested path, source IP address,... printed to either standard output or a log file.
All I got so far is:
Browse your REST API at http://0.0.0.0:3000/explorer
Web server listening at: http://0.0.0.0:3000/
The server responds to requests but I cannot see any logs.
I currently need to run the app using slc run (no process manager).
You can achieve the logs in a separate file by just passing the log file name.
for example:-
slc run -d -l /tmp/file.log -p /tmp/file.pid -d
-d will detach the process from your current screen, and will run it in the background
Go through the below links, for further clarifications:-
http://docs.strongloop.com/display/NODE/slc+run
http://docs.strongloop.com/display/SLC/Logging
And for choosing the correct logger:-
http://docs.strongloop.com/display/SLC/Using+logging+libraries
Winston and bunyan are 2 well suited loggers, we are using bunyan and it is working really good for us.
If you want to RUN the slc in the DEBUG mode, to check all the logs, you can run using
DEBUG=* slc run
Since loopback is based on express, you could start with something like morgan:
var morgan = require('morgan');
app.use(morgan('combined'))
Related
I was wondering, is there any way I can check out the logs of the my nodejs server when I've forever'd it using forever start server.js to look at what's being logged, check any live errors and such.
I looked at their documentation but couldn't find anything related to this. I want to be able to look at the console.
As forever start an application on background it gets hard to access old logs.
If you can use a library for maintaining logs, I will suggest simple-node-logger . Using this library you can save all your logs on a file and can access that file any time using:
tail -f logsFile.txt
Using this command this will keep printing new changes over logsFile.txt as logger keep updating logs.
This will help you to maintain all the logs for you.
First find out where your logs are stored using:
sudo forever list
for each process you can see something like this as logfile:
/root/.forever/_Jht.log
use 'tail -f' to monitor its changes:
sudo tail -f /root/.forever/_Jht.log
You can also set your desired path for log files, see this:
https://stackoverflow.com/a/21021251/1119611
So I am putting my app on a server and I want to see some console logs generated from my nodejs app. Before putting it on the server I saw the output of my console log on my terminal, but where do I find the output for these on Ubuntu? I'm running version 16.04 on Ubuntu
Lifted straight from #SlovyanskiyYehor comment two years ago, but I missed his answer as a comment. Also answered here: Make pm2 log to console.
If you are using pm2 to start your node.js application, you can use:
pm2 logs
or for just a single app running in pm2:
pm2 logs yourAppNameHere
If you are using some bash script which is runed by cron for example,
you can specify file where you need to output all logs of your app
It will looks like that:
myApp > /path/to/logs/myAppLogs.txt
This command will run application myApp and put all logs into
"/path/to/logs/myAppLogs.txt"
Also you can put this string into cron directly without some bash scripts
Of course you can see all console logs by user here ~/.bash_history
but it`s not always useful
If you used pm2, you can check log in this folder:
/root/.pm2/log
We are using Diego version 2.80 and I'm trying to debug node.js application...in this URL there is place which you should install node inspector and expose debug port , my question is there a shorter way to do it ? maybe without having the need to download the node inspector ...
Bluemix provides documentation that will show you the options of how to manage and debug Liberty and Node.js apps:
Managing Liberty and Node.js apps
I would recommend reading this documentation to see what options you want to utilize. Please note some of the options work for both Liberty and Node.js, but others are specific to each runtime.
There is even detailed information regarding the inspector you mention above, but the steps you need to take are dependent on your Node version:
Node.js inspector
Assuming you are using the latest Node.js v6:
in your package.json change your app's start command from something like node app.js to node --inspect app.js
push your app
create a SSH tunnel so you can remotely access the debug port which by default is 9229: cf ssh -N -T -L 9229:127.0.0.1:9229 <appName>
get your chrome-devtools URL from cf logs <appName> --recent and browse to it (it will take a few seconds to load)
I found this guide which solved the issue
https://codeburst.io/an-easy-way-to-debug-node-js-apps-in-cloud-foundry-22f559d44516
I have a sailsjs app on AWS EC2, which I have been running till now using forever. I have two adantages using forever:
1) Perpetuality: I can use the CLI forever start app.js or forever restart app.js and then app starts running and keeps on running till I stop it with the command forever stop app.js. So, the app does not stop even when I close my terminal. The process keeps on running.
2) Runtime Log: I have a .forever directory that has a log file, while on real time records the server logs, and when I check the log using tail -f file_name.log, I get to see run time logs.
However there is a disadvantage: Every time I upload a new/modified server file, I have to restart the app manually. To get rid of this, I am switching from forever to nodemon.
From the documentation provided by Nodemon, I cant figure out how can I replicate the two advantages, as mentioned above, from Nodemon too. Will be a great help if anyone can guide me on how to start my nodejs app using nodemon so that it can keep running even after closing the terminal on my side, and how to watch runtime log of server.
Just my two cents.
I use nodemon daily while developing and I dont think its something you want to use in place of something like forever. Nodemon is used when developing, the software will detect when there has been a file change and restart the server but for deployment it should not be considered.
There is no need to change either because forever has this use case handled with the --w or --watchDirectory comand that will watch for file changes(It can be found here on their readme).
I'm deploying a node web application as an upstart service using grunt and monitoring it using monit. However:
My upstart and monit configuration duplicate each other a little bit
Upstart doesn't do variable expansion inside env stanzas
I can't find a way to configure monit dynamically (ala upstart .override files)
My question
This means I'm looking for a grunt plugin or other tool that I can use to generate the uptstart .conf and monit conf.d/ files. Can you please help me find one (or suggest a better way of robustly running my node web app)?
A rather crude solution?
To be honest an underscore template of the upstart and monit files would probably be sufficient, and that's what I'll wrap up into a grunt plugin if there isn't a ready-made solution, but this feels like a problem that other people must have run into as well so I imagine there's a solution out there, I just can't find it.
Detail
A bit more detail to illustrate the three problems. My upstart conf file looks like this:
setuid node
setgid node
# ...
script
mkdir -p /home/node/.my-app
echo $$ > /home/node/.my-app/upstart.pid
/usr/local/bin/node /var/node/my-app/server.js >> /var/node/my-app/logs/console.log 2>&1
end script
# ...
And my monit configuration looks like this:
check process node with pidfile /home/node/.my-app/upstart.pid
start program = "/sbin/start my-app" with timeout 60 seconds
stop program = "/sbin/stop my-app"
if failed host localhost port 17394 protocol http
and request "/monit.html"
then restart
if 3 restarts within 5 cycles then timeout
As you can see, the PID file path and config directory is duplicated across the two (problem 1) and I'd love to parameterise the host, port and request URL in the monit file (problem 3).
For problem 2 (no variable expansion in upstart's env stanza, bug report here) there are a couple of workarounds that work for variables used inside *script blocks, which are interpreted as bash scripts, but they don't seem to work in the conf file itself. I think this makes it impossible to specify the user id the app should run as in a configuration file?
Those techniques I just mentioned:
Method 1: Don't use env - echo the variables in the pre-script to a file and then source it later
Method 2: Duplicate the variable expansion in all the script bodies where it is needed
Method 3: Store the variables in a file and cat them in using command substitution
...or suggest a better way of robustly running my node web app
Use PM2 by Unitech instead.
I run all my node apps using PM2. It works perfectly and is easy to configure. It has built-in functionality for autogenerating of startup script. It gives you logging, monitoring and easy maintenance.
Here is a good article showing off the highlights.
Install
npm install -g pm2
Start app
pm2 start app.js
Show running apps
pm2 list
Make a startup script
pm2 startup [ubuntu|centos|systemd]
More details in the readme on their github page