CaramelPuppy is an intelligent log manager, it allows to save the logs in a caramelPuppy.json file in the project root. Integration with express and credential protected web interface for log viewing.
First install the caramelPuppy package
- Via Node Package Manager (NPM):
npm install caramel-puppy
- Via yarn:
yarn add caramel-puppy
Then import caramelPuppy into your project:
const caramelPuppy = require("caramel-puppy")({
__filename
})
The code above is enough for caramelPuppy to work. The __filename
parameter is Node's own variable, which tells which file that code is being run.
After the setup is a success. The caramelPuppy will return some functions.
Similar to the console.log()
function it takes a number of parameters. And save it to the caramelPuppy.json log array like this:
{
date:"2019-12-11 10:12:12",
type:"log",
filename:"index.js",
log:["Hello","World"] //array of arguments
}
And will display on the console:
LOG Hello World
Useful to know when your app started. In caramelPuppy.json:
{
filename:"index.js",
type:"appStart",
date:"2019-12-11 10:12:12"
}
And will not display anything on the console.
CaramelPuppy uses express middleware to intercept requests and save the http method, status code, and URL. By default the information will only be saved at the end of the request.
Not required to use Express.
const express = require("express")
const app = express()
const caramelPuppy = require("caramel-puppy")({
__filename,
express:app
})
Messages will be displayed on the console:
Express Start GET /hi
Express End GET /hi 200
Start means the request has been received. End means the request has been terminated.
In the future with the implementation of trace it will be easier to monitor the logs that happened in a request.
CaramelPuppy provides a web interface to view logs simply and securely.
Setting this interface requires setting an environment variable, so you can create the .env
file in the root:
CARAMELPUPPY_KEY=exemple
When creating this file, caramelPuppy uses dotenv to read it. So just go to url: http://mydomin.com/caramelPuppy?credential=example
caramelPuppy.request(req)
receives the request req and error as a parameter:
request("google.com",{
time:true //Passing time: true will save elapsedTime
},(err,req,body)=>{
caramelPuppy.request(req,err)
})
And will display on the console:
Request GET 200 google.com
- 1.0.0: Initial release
- 1.0.1: Fixed error looking for href from url in request
- Patrícia Garbe Carvalho: Helped you choose the name caramelPuppy
My sincere and thank you to all who contributed.
Please read CONTRIBUTING.md for details on our code of conduct and the process for submitting pull requests to us.
This project is licensed under the MIT license - see the LICENSE file for details.