Comparing version 1.4.2 to 1.5.0
{ | ||
"name": "debugutil", | ||
"version": "1.4.2", | ||
"version": "1.5.0", | ||
"description": "Debug Utility Tool with Logging", | ||
"gitrepo": "https://github.com/melonysmith/debugutil", | ||
"main": "src/debug.js", | ||
"scripts": { | ||
"test": "mocha" | ||
"test": "DEBUG=true mocha" | ||
}, | ||
@@ -29,5 +28,4 @@ "keywords": [ | ||
"istanbul": "^0.4.5", | ||
"mocha": "^3.2.0", | ||
"supertest": "^2.0.1" | ||
"mocha": "^3.2.0" | ||
} | ||
} |
## debugutil | ||
A [NodeJS](https://nodejs.org/en/) API debug utility tool with logging developed for my Deployment of Web Applications class at Full Sail University. This package will allow you to debug your API with success and error messages displayed in your CLI (Command Line Interface) as well as saving timestamped messages to a .log file. | ||
A [NodeJS](https://nodejs.org/en/) API debug utility tool with logging developed for my Deployment of Web Applications class at Full Sail University. This package will allow you to debug your API with success, warn and error messages displayed in your CLI (Command Line Interface) as well as saving timestamped messages to a .log file. | ||
Note: Logging is not working. I will have this fixed soon. | ||
## Required | ||
@@ -12,3 +14,3 @@ This Debug Utility Tool will run on an API created with [NodeJS](https://nodejs.org/en/) | ||
```javascript | ||
npm install --save debugutil | ||
npm install debugutil | ||
``` | ||
@@ -26,6 +28,6 @@ | ||
javascript | ||
const debug = require('utildebug') | ||
require('utildebug'); | ||
``` | ||
To enable logging, add the following environmental variable to your server start command: | ||
To enable logging, use the following environmental variable: | ||
```javascript | ||
@@ -37,3 +39,3 @@ DEBUG=true | ||
To disable logging, add the following environmental variable to your server start command: | ||
To disable logging, use the following environmental variable: | ||
```javascript | ||
@@ -44,13 +46,21 @@ DEBUG=false | ||
## Unit Testing | ||
This package has been Unit Tested using [chai](https://www.npmjs.com/package/chai), [supertest](https://www.npmjs.com/package/supertest) and [mocha](https://www.npmjs.com/package/mocha). | ||
This package has been Unit Tested using [chai](https://www.npmjs.com/package/chai) and [mocha](https://www.npmjs.com/package/mocha). You will need to install these packages to your devDependencies to run tests. | ||
To run tests, execute the following command in your CLI: | ||
```javascript | ||
DEBUG=true mocha | ||
``` | ||
## Code Coverage | ||
Check out [istanbul](https://www.npmjs.com/package/istanbul) for more on code coverage. | ||
To run tests with code coverage, execute the following command in your CLI: | ||
```javascript | ||
istanbul cover src/debug.js | ||
``` | ||
## Other | ||
Please note, the package will create the .log file for you, but not the folder to which the .log file is saved. In your root directory, you will need to manually create a folder called log in which the .log file is saved. | ||
You can change the name and/or path of the folder and the .log file, in src/debug.js. Just edit the following lines: | ||
```javascript | ||
fs.appendFile('./logs/log.log', '\n' + info + '\n', (debugSuccess) => { | ||
fs.appendFile('./logs/logFile.log', '\n' + info + '\n', (debugSuccess) => { | ||
}); | ||
@@ -60,3 +70,3 @@ ``` | ||
```javascript | ||
fs.appendFile('./logs/log.log', '\n' + info + '\n', (debugError) => { | ||
fs.appendFile('./logs/logFile.log', '\n' + info + '\n', (debugError) => { | ||
}); | ||
@@ -67,4 +77,5 @@ ``` | ||
```javascript | ||
const debugSuccess = chalk.green; | ||
const debugError = chalk.red; | ||
const success = chalk.green; | ||
const warn = chalk.yellow; | ||
const error = chalk.red; | ||
``` |
// Debug Utility with Logging by Melony Smith | ||
// dependencies | ||
const timestamp = require('log-timestamp'); | ||
const chalk = require('chalk'); | ||
require('log-timestamp'); | ||
const fs = require('fs'); | ||
// chalk rule | ||
const debugSuccess = chalk.green; | ||
const debugError = chalk.red; | ||
// for success... | ||
debugSuccess => { | ||
exports.debug = (title, type) => { | ||
if (process.env.DEBUG) { | ||
console.log(debugSuccess(info)); | ||
fs.appendFile('./logs/log.log', '\n' + info + '\n', (debugSuccess) => { | ||
}); | ||
if(type == 'warn'){ | ||
console.warn(warn(title, type)) | ||
} else if (type == 'error'){ | ||
console.error(error(title, type)) | ||
} else { | ||
console.log(success(title, type)) | ||
} | ||
}; | ||
} | ||
// for error... | ||
debugError => { | ||
if (process.env.DEBUG) { | ||
console.log(debugError(info)); | ||
fs.appendFile('./logs/log.log', '\n' + info + '\n', (debugError) => { | ||
}); | ||
}; | ||
} | ||
// export | ||
exports.debugSuccess = debugSuccess; | ||
exports.debugError = debugError; |
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
4809
8
8
41
76