diff --git a/demo_logger/README.md b/demo_logger/README.md new file mode 100644 index 0000000..e5b97f8 --- /dev/null +++ b/demo_logger/README.md @@ -0,0 +1,43 @@ +# Remer + +[ ![codeship status for seanedw1/remer](https://codeship.com/projects/92c3f5c0-76cf-0134-e5f4-66667cc72310/status?branch=master)](https://app.codeship.com/projects/179698) + + +# Getting started + +## Install package + +To install package + +``` +npm i remer +``` + +### Usage + +start your api in debug mode. + +``` +DEBUG=true node src/server +``` +### Logging + +remer will create and write to a log file on root level of application when enabled.Log will contain robust debugging information about your application. + +### Debugging + +write it in this format + +debug excepts two params one for title and one for status. + +status should be either succes or fail if undefined terminal will output magenta title + +``` +remer.debug('title goes here', 'status'); +``` + +###Style Guide reference +[Airbnb](https://github.com/airbnb/javascript) + +###Contributors +[View Contributors](https://github.com/seanedw1/remer/graphs/contributors) diff --git a/demo_logger/package.json b/demo_logger/package.json new file mode 100644 index 0000000..f48f54d --- /dev/null +++ b/demo_logger/package.json @@ -0,0 +1,34 @@ +{ + "name": "remer", + "version": "1.0.3", + "description": "debugging utility tool", + "main": "src/util", + "scripts": { + "test": "mocha" + }, + "repository": { + "type": "git", + "url": "git+https://github.com/seanedw1/remer.git" + }, + "keywords": [ + "debug" + ], + "author": "seanedw1", + "license": "ISC", + "bugs": { + "url": "https://github.com/seanedw1/remer/issues" + }, + "homepage": "https://github.com/seanedw1/remer#readme", + "dependencies": { + "colors": "^1.1.2" + }, + "devDependencies": { + "chai": "^3.5.0", + "mocha": "^3.1.2", + "eslint": "^3.3.1", + "eslint-config-airbnb": "^10.0.0", + "eslint-plugin-import": "^1.13.0", + "eslint-plugin-react": "^6.0.0", + "eslint-plugin-jsx-a11y": "2.1.0" + } +} diff --git a/demo_logger/src/util.js b/demo_logger/src/util.js new file mode 100644 index 0000000..c9cde0f --- /dev/null +++ b/demo_logger/src/util.js @@ -0,0 +1,30 @@ +// time stamp +const stamp = new Date(); + +const seperator = '======' + stamp + '======='; + +const colors = require('colors'); + +// utility method of debug +exports.debug = (data, status) => { + // debug env + let state; + if (process.env.DEBUG) { + if (status === 'fail') { + const out1 = seperator + '\n \n' + colors.red(data) + '\n \n'; + state = status; + console.error(out1); + } else if (status === 'sucess') { + const out2 = seperator + '\n \n' + colors.green(data) + '\n \n'; + state = status; + console.log(out2); + // if status is undefined + } else { + const out3 = seperator + '\n \n' + colors.magenta(data) + '\n \n'; + console.warn(out3); + state = 'warn'; + } // closes else + console.log('log updated sucessfully'); + return state; + } // closes if debug env +}; // closes util module diff --git a/demo_logger/test/__util.js b/demo_logger/test/__util.js new file mode 100644 index 0000000..91ea567 --- /dev/null +++ b/demo_logger/test/__util.js @@ -0,0 +1,32 @@ + +const expect = require('chai').expect; +const remer = require('../src/util'); + +// turn on debug mode for these tests +process.env.DEBUG = true; +describe('remer log tool tests', () => { + // Read url by id + it('remer should return "sucess" when using console.log()', (done) => { + // const test = remer.debug('this is a log', 'sucess'); + + const t = remer.debug('', 'sucess'); + expect(t).to.equal('sucess'); + done(); + }); + + it('remer should return "warn" when using console.warn()', (done) => { + // const test = remer.debug('this is a log', 'sucess'); + + const t = remer.debug('', 'warn'); + expect(t).to.equal('warn'); + done(); + }); + + it('remer should return "fail" when using console.error()', (done) => { + // const test = remer.debug('this is a log', 'sucess'); + + const t = remer.debug('', 'fail'); + expect(t).to.equal('fail'); + done(); + }); +}); diff --git a/error.log b/error.log new file mode 100644 index 0000000..157b8aa --- /dev/null +++ b/error.log @@ -0,0 +1,20 @@ +======Mon Oct 17 2016 22:41:20 GMT-0400 (EDT)======= + +sucess on get + +======Mon Oct 17 2016 22:41:57 GMT-0400 (EDT)======= + +sucess on get + +======Mon Oct 17 2016 22:42:02 GMT-0400 (EDT)======= + +sucess on get + +======Mon Oct 17 2016 22:42:11 GMT-0400 (EDT)======= + +sucess on get + +======Mon Oct 17 2016 22:42:38 GMT-0400 (EDT)======= + +sucess on get + diff --git a/src/models/gen.js b/src/models/gen.js index a9b672d..f554d7d 100644 --- a/src/models/gen.js +++ b/src/models/gen.js @@ -1,5 +1,6 @@ const bcrypt = require('bcrypt-nodejs'); -const remer = require('remer'); +// const remer = require('remer'); +const remer = require('../../demo_logger/src/util'); // sets generate module exports.genURL = () => { diff --git a/src/models/url.js b/src/models/url.js index 68c4218..ce1b51e 100644 --- a/src/models/url.js +++ b/src/models/url.js @@ -1,5 +1,6 @@ const db = require('./db'); -const remer = require('remer'); +// const remer = require('remer'); +const remer = require('../../demo_logger/src/util'); // create exports.create = (payload, err, success) => { diff --git a/src/models/user.js b/src/models/user.js index 266491c..e3674dd 100644 --- a/src/models/user.js +++ b/src/models/user.js @@ -1,5 +1,6 @@ const db = require('./db'); -const remer = require('remer'); +// const remer = require('remer'); +const remer = require('../../demo_logger/src/util'); // create exports.create = (payload, err, success) => { diff --git a/src/routes/api/url.js b/src/routes/api/url.js index 2fd051c..eb49fbc 100644 --- a/src/routes/api/url.js +++ b/src/routes/api/url.js @@ -1,7 +1,8 @@ // links to link generation model const gen = require('../../models/gen'); const url = require('../../models/url'); -const remer = require('remer'); +// const remer = require('remer'); +const remer = require('../../../demo_logger/src/util'); // accepts express as a parameter of express diff --git a/src/routes/api/user.js b/src/routes/api/user.js index ff8740d..a5bb493 100644 --- a/src/routes/api/user.js +++ b/src/routes/api/user.js @@ -1,6 +1,7 @@ const user = require('../../models/user'); const gen = require('../../models/gen'); -const remer = require('remer'); +// const remer = require('remer'); +const remer = require('../../../demo_logger/src/util'); module.exports = (express) => { diff --git a/src/routes/go/redirect.js b/src/routes/go/redirect.js index d1384dd..98ad5b0 100644 --- a/src/routes/go/redirect.js +++ b/src/routes/go/redirect.js @@ -1,5 +1,6 @@ const url = require('../../models/url'); -const remer = require('remer'); +// const remer = require('remer'); +const remer = require('../../../demo_logger/src/util'); module.exports = (express) => { diff --git a/src/routes/index.js b/src/routes/index.js index 5735751..7acf981 100644 --- a/src/routes/index.js +++ b/src/routes/index.js @@ -1,4 +1,5 @@ -const remer = require('remer'); +// const remer = require('remer'); +const remer = require('../../demo_logger/src/util'); module.exports = (express) => { const router = express.Router(); diff --git a/src/server.js b/src/server.js index e99807f..a6a6190 100644 --- a/src/server.js +++ b/src/server.js @@ -1,6 +1,7 @@ const express = require('express'); const bodyParser = require('body-parser'); -const remer = require('remer'); +// const remer = require('remer'); +const remer = require('../demo_logger/src/util'); // express functionality const app = express(); @@ -26,6 +27,5 @@ app.use('/', require('./routes')(express)); const server = app.listen(port, () => { remer.debug(' server active on ' + port); }); - // makes server modular module.exports = server; diff --git a/test/__logs.js b/test/__logs.js new file mode 100644 index 0000000..27c1c70 --- /dev/null +++ b/test/__logs.js @@ -0,0 +1,32 @@ +const expect = require('chai').expect; +const remer = require('../demo_logger/src/util'); + +// turn on debug mode for these tests +process.env.DEBUG = true; + +describe('remer log tool tests', () => { + // Read url by id + it('remer should return "sucess" when using console.log()', (done) => { + // const test = remer.debug('this is a log', 'sucess'); + + const t = remer.debug('', 'sucess'); + expect(t).to.equal('sucess'); + done(); + }); + + it('remer should return "warn" when using console.warn()', (done) => { + // const test = remer.debug('this is a log', 'sucess'); + + const t = remer.debug('', 'warn'); + expect(t).to.equal('warn'); + done(); + }); + + it('remer should return "fail" when using console.error()', (done) => { + // const test = remer.debug('this is a log', 'sucess'); + + const t = remer.debug('', 'fail'); + expect(t).to.equal('fail'); + done(); + }); +});