pm2-js-logger
v1.0.4
Published
A simple service to store pm2 logs in mongodb.
Downloads
1
Maintainers
Readme
pm2-js-logger
A simple service to store pm2 logs in mongodb.
Installation
Using git:
git clone https://gitlab.com/sexycoders/pm2-js-logger.git
cd ./pm2-js-logger
npm install
using npm directly:
npm install pm2-js-logger
Configuration
All the configuration is done inside the config file that should look something like this:
{
"__system__":
{
"mongo_location":"localhost",
"mongo_port":27017
},
"ExampleService":
{
"path":"some-path",
"name":"service-config.js",
"home":"your_home_directory"
}
}
The configuration as you can see is very simple.
The system object (HAS to be named "__system__")is used to locate the mongo database on your setup.
You can then specify any amount of other configuration objects pointing to services.
Those objects have three values you have to fill in:
- the path to the service (please use full path because we do no link resolving)
- the config file that pm2 is using ("ecosystem" file)
- your home directory (to get default files under $HOME/.pm2)
:warning: The "log_type":"json" parameter is ABSOLUTELY REQUIRED otherwise the logger cannot parse the data.
Regarding the config file the service will look for it in:
- the "node_modules/pm2-js-logger"
- the root directory of your project (the forder in which node_moduls dir is located)
If you wish to place the config file elsewhere please provide a link to one of the aforementioned locations.
Everything else is read from whithin the pm2 files!
Running the service
The servide can be easilly initiated using
node --experimental-worker main.js
:information_source: Please note that the "experimental worker" option is only required for older versions of node.
If you wish to run the service using pm2 please add the following to your ecosystem file:
{
name: 'MongoLogger',
script:'./node_modules/pm2-js-logger/main.js',
interpreter_args:"--experimental-worker",
log_type:'json',
log_date_format:'DD-MM-YYYY hh:mm'
}
:information_source: Of course the logger will also log itself!
Mongo
:warning: Please keep in mind that mongo server HAS TO BE RUNNING!!!
If you would like to automatically resolve the home directory or start the mongo server you will have to provide your own implementation.
We dont want this service to get involved with your system at all (let alone ask for root privilages to start mongo server !)
Licence and contribution
This service is available under the General Public Licence as described in the LICENCE file and by using any part of it you are subject to said licence.
To contibute to our project please raise a merge request and it will be reviewed swiftly!
Have fun coding
Shane from Greece