Skip to content

Commit

Permalink
Add initial implementation
Browse files Browse the repository at this point in the history
  • Loading branch information
Rui Marinho committed Jul 13, 2015
0 parents commit 3449d05
Show file tree
Hide file tree
Showing 9 changed files with 561 additions and 0 deletions.
163 changes: 163 additions & 0 deletions .eslintrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,163 @@
{
"ecmaFeatures": {
"modules": true
},
"env": {
"es6": true,
"node": true
},
"parser": "babel-eslint",
"plugins": [
"babel"
],
"rules": {
"accessor-pairs": [2, true],
"array-bracket-spacing": 2,
"babel/block-scoped-var": 2,
"babel/generator-star-spacing": 2,
"babel/new-cap": 2,
"babel/object-shorthand": [2, "always"],
"brace-style": 2,
"camelcase": 2,
"comma-dangle": [2, "never"],
"comma-spacing": 2,
"comma-style": 2,
"computed-property-spacing": 2,
"consistent-return": 2,
"consistent-this": 2,
"constructor-super": 2,
"curly": [2, "all"],
"default-case": 2,
"dot-location": [2, "property"],
"dot-notation": [2, {"allowKeywords": true, "allowPattern": ""}],
"eol-last": 2,
"eqeqeq": [2, "smart"],
"func-names": 2,
"func-style": 2,
"guard-for-in": 2,
"indent": [2, 2],
"key-spacing": 2,
"linebreak-style": [2, "unix"],
"lines-around-comment": 2,
"max-nested-callbacks": 2,
"new-parens": 2,
"newline-after-var": 2,
"no-alert": 2,
"no-caller": 2,
"no-catch-shadow": 2,
"no-cond-assign": [2, "always"],
"no-console": 2,
"no-constant-condition": 2,
"no-control-regex": 2,
"no-debugger": 2,
"no-delete-var": 2,
"no-div-regex": 2,
"no-dupe-args": 2,
"no-dupe-keys": 2,
"no-duplicate-case": 2,
"no-else-return": 2,
"no-empty": 2,
"no-empty-character-class": 2,
"no-empty-label": 2,
"no-eq-null": 2,
"no-eval": 2,
"no-ex-assign": 2,
"no-extend-native": 2,
"no-extra-bind": 2,
"no-extra-boolean-cast": 2,
"no-extra-parens": 2,
"no-extra-semi": 2,
"no-fallthrough": 2,
"no-floating-decimal": 2,
"no-func-assign": 2,
"no-implied-eval": 2,
"no-inline-comments": 2,
"no-inner-declarations": 2,
"no-invalid-regexp": 2,
"no-irregular-whitespace": 2,
"no-iterator": 2,
"no-label-var": 2,
"no-labels": 2,
"no-lone-blocks": 2,
"no-lonely-if": 2,
"no-loop-func": 2,
"no-mixed-spaces-and-tabs": 2,
"no-multi-spaces": 2,
"no-multi-str": 2,
"no-multiple-empty-lines": 2,
"no-native-reassign": 2,
"no-negated-in-lhs": 2,
"no-nested-ternary": 2,
"no-new": 2,
"no-new-func": 2,
"no-new-object": 2,
"no-new-require": 2,
"no-new-wrappers": 2,
"no-obj-calls": 2,
"no-octal": 2,
"no-octal-escape": 2,
"no-path-concat": 2,
"no-process-env": 2,
"no-process-exit": 2,
"no-proto": 2,
"no-redeclare": 2,
"no-regex-spaces": 2,
"no-reserved-keys": 2,
"no-restricted-modules": 2,
"no-return-assign": 2,
"no-script-url": 2,
"no-self-compare": 2,
"no-sequences": 2,
"no-shadow": 2,
"no-shadow-restricted-names": 2,
"no-spaced-func": 2,
"no-sparse-arrays": 2,
"no-sync": 2,
"no-ternary": 2,
"no-this-before-super": 2,
"no-throw-literal": 2,
"no-trailing-spaces": 2,
"no-undef": 2,
"no-undef-init": 2,
"no-undefined": 2,
"no-underscore-dangle": 2,
"no-unexpected-multiline": 2,
"no-unneeded-ternary": 2,
"no-unreachable": 2,
"no-unused-expressions": 2,
"no-unused-vars": 2,
"no-use-before-define": 2,
"no-var": 2,
"no-void": 2,
"no-warning-comments": 2,
"no-with": 2,
"object-curly-spacing": [2, "always"],
"one-var": 2,
"operator-assignment": 2,
"operator-linebreak": 2,
"padded-blocks": [2, "never"],
"prefer-const": 2,
"quote-props": [2, "as-needed"],
"quotes": [2, "single"],
"radix": 2,
"semi": [2, "always"],
"semi-spacing": 2,
"sort-vars": 2,
"space-after-keywords": 2,
"space-before-blocks": 2,
"space-before-function-paren": [2, "never"],
"space-in-parens": 2,
"space-infix-ops": 2,
"space-return-throw-case": 2,
"space-unary-ops": 2,
"spaced-comment": [2, "always"],
"strict": [2, "global"],
"use-isnan": 2,
"valid-jsdoc": 2,
"valid-typeof": 2,
"vars-on-top": 2,
"wrap-iife": 2,
"wrap-regex": 2,
"yoda": [2, "never"]
}
}
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
coverage
examples
node_modules
3 changes: 3 additions & 0 deletions .jscsrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"esnext": true
}
9 changes: 9 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
language: node_js

node_js:
- iojs
- "0.12"
- "0.10"

after_success:
- npm run coveralls
74 changes: 74 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
# debugnyan

A logging library that combines the simplicity and convenience of [debug](https://github.com/visionmedia/debug) with the power of [bunyan](https://github.com/trentm/node-bunyan).

## Status

[![npm version][npm-image]][npm-url]
[![build status][travis-image]][travis-url]

## Installation

Install the package via `npm`:

```bash
$ npm install debugnyan --save
```

## Usage

Create a logger by giving it a namespace and then call [bunyan's log methods](https://github.com/trentm/node-bunyan#log-method-api) on the returned instance.

By default, similarly to `debug`'s behaviour, loggers do not output any content. Each logger output can be selectively activated by using the `DEBUG` environment variable.
Pattern matching is based on the logger's name and it can optionally contain colons (`:`) to create (sub)-components properties on the logger instance.

Consider a logger named `foo:bar:biz`:

- this creates a `bunyan` logger with name `foo`
- and a `bunyan` (simple) child logger with property `component` equal to `bar`.

```js
var logger1 = require('debugnyan')('foo');
var logger2 = require('debugnyan')('foo:bar');

logger1.debug('net');
logger2.debug('qux');
```

*Example output with `DEBUG=foo`*:

```bash
DEBUG=foo node example.js

{"name":"foo","hostname":"ruimarinho","pid":1,"level":20,"msg":"net","time":"2016-10-04T18:54:14.530Z","v":0}
{"name":"foo","hostname":"ruimarinho","pid":1,"component":"bar","level":20,"msg":"qux","time":"2016-10-04T18:54:14.531Z","v":0}
```

*Example output with `DEBUG=foo:bar`*:

```bash
DEBUG=foo:bar node example.js

{"name":"foo","hostname":"ruimarinho","pid":2,"component":"bar","level":20,"msg":"qux","time":"2016-10-04T18:55:08.217Z","v":0}
```

The `prefix` and `suffix` for each component is also customizable:

```js
var logger = require('debugnyan')('foo', {}, { suffix: 'module' });
```

## Tests

```
$ npm test
```

## License

MIT

[npm-image]: https://img.shields.io/npm/v/debugnyan.svg
[npm-url]: https://www.npmjs.com/package/debugnyan
[travis-image]: https://travis-ci.org/seegno/debugnyan.svg
[travis-url]: https://travis-ci.org/seegno/debugnyan
82 changes: 82 additions & 0 deletions dist/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@

/**
* Module dependencies.
*/

'use strict';

exports.__esModule = true;

var _extends = Object.assign || function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; };

exports['default'] = debugnyan;

function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { 'default': obj }; }

var _bunyan = require('bunyan');

var _bunyan2 = _interopRequireDefault(_bunyan);

var _debug = require('debug');

var _debug2 = _interopRequireDefault(_debug);

/**
* Loggers.
*/

var loggers = Object.create(null);

/**
* Default level.
*/

var level = _bunyan2['default'].FATAL + 1;

/**
* Export `debugnyan`.
*/

function debugnyan(name, options, config) {
var components = name.split(':');
var root = components[0];

config = _extends({
prefix: 'sub',
suffix: 'component'
}, config);

if (!loggers[root]) {
loggers[root] = _bunyan2['default'].createLogger(_extends({}, options, { name: root, level: level }));
}

var child = loggers[root];

for (var i = 1; i < components.length; i++) {
var _extends2;

var current = components[i];
var next = loggers[components.slice(0, i).join(':')];
var childName = components.slice(0, i + 1).join(':');

if (loggers[childName]) {
child = loggers[childName];

continue;
}

options = _extends({}, options, (_extends2 = {}, _extends2['' + config.prefix.repeat(i - 1) + config.suffix] = current, _extends2.level = level, _extends2));

child = next.child(options, true);

loggers[childName] = child;
}

if (_debug2['default'].enabled(name)) {
child.level(_bunyan2['default'].DEBUG);
}

return loggers[name];
}

module.exports = exports['default'];
57 changes: 57 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
{
"name": "debugnyan",
"version": "0.0.1",
"description": "A logging library that combines the simplicity and convenience of debug with the power of bunyan",
"author": {
"email": "rui.marinho@seegno.com",
"name": "Rui Marinho",
"url": "http://seegno.com"
},
"license": "MIT",
"homepage": "https://github.com/seegno/debugnyan/",
"bugs": "https://github.com/seegno/debugnyan/issues",
"repository": {
"type": "git",
"url": "https://github.com/seegno/debugnyan.git"
},
"main": "./dist/index.js",
"keywords": [
"bridge",
"bunyan",
"debug",
"debugging",
"json",
"log",
"logging"
],
"options": {
"mocha": "--compilers js:babel/register --require should test"
},
"scripts": {
"build": "rm -rf dist/* && ./node_modules/.bin/babel src/ --loose --plugins object-assign --out-dir dist/",
"changelog": "github_changelog_generator",
"cover": "./node_modules/.bin/babel-node node_modules/.bin/isparta cover --report html node_modules/.bin/_mocha -- $npm_package_options_mocha",
"coveralls": "./node_modules/.bin/babel-node node_modules/.bin/isparta cover --report html node_modules/.bin/_mocha --report lcovonly -- $npm_package_options_mocha && cat ./coverage/lcov.info | ./node_modules/coveralls/bin/coveralls.js",
"lint": "eslint src",
"prepublish": "npm test && npm run build",
"test": "./node_modules/.bin/mocha $npm_package_options_mocha"
},
"dependencies": {
"bunyan": "^1.4.0",
"debug": "^2.2.0"
},
"devDependencies": {
"babel": "^5.6.14",
"babel-eslint": "^3.1.23",
"babel-plugin-object-assign": "^1.2.0",
"coveralls": "^2.11.2",
"eslint": "^0.24.1",
"eslint-plugin-babel": "^1.1.0",
"isparta": "^3.0.3",
"mocha": "^2.0.1",
"should": "^7.0.1"
},
"engines": {
"node": ">= 0.10"
}
}
Loading

0 comments on commit 3449d05

Please sign in to comment.