Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

added local log tool to to simulate tests. logs should now only pint … #1

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
43 changes: 43 additions & 0 deletions demo_logger/README.md
Original file line number Diff line number Diff line change
@@ -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)
34 changes: 34 additions & 0 deletions demo_logger/package.json
Original file line number Diff line number Diff line change
@@ -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"
}
}
30 changes: 30 additions & 0 deletions demo_logger/src/util.js
Original file line number Diff line number Diff line change
@@ -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
32 changes: 32 additions & 0 deletions demo_logger/test/__util.js
Original file line number Diff line number Diff line change
@@ -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();
});
});
20 changes: 20 additions & 0 deletions error.log
Original file line number Diff line number Diff line change
@@ -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

3 changes: 2 additions & 1 deletion src/models/gen.js
Original file line number Diff line number Diff line change
@@ -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 = () => {
Expand Down
3 changes: 2 additions & 1 deletion src/models/url.js
Original file line number Diff line number Diff line change
@@ -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) => {
Expand Down
3 changes: 2 additions & 1 deletion src/models/user.js
Original file line number Diff line number Diff line change
@@ -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) => {
Expand Down
3 changes: 2 additions & 1 deletion src/routes/api/url.js
Original file line number Diff line number Diff line change
@@ -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
Expand Down
3 changes: 2 additions & 1 deletion src/routes/api/user.js
Original file line number Diff line number Diff line change
@@ -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) => {
Expand Down
3 changes: 2 additions & 1 deletion src/routes/go/redirect.js
Original file line number Diff line number Diff line change
@@ -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) => {
Expand Down
3 changes: 2 additions & 1 deletion src/routes/index.js
Original file line number Diff line number Diff line change
@@ -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();
Expand Down
4 changes: 2 additions & 2 deletions src/server.js
Original file line number Diff line number Diff line change
@@ -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();
Expand All @@ -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;
32 changes: 32 additions & 0 deletions test/__logs.js
Original file line number Diff line number Diff line change
@@ -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();
});
});