├── .editorconfig ├── .gitignore ├── .jshintrc ├── .npmignore ├── .travis.yml ├── LICENSE ├── README.md ├── index.js ├── package.json └── test └── index.js /.editorconfig: -------------------------------------------------------------------------------- 1 | # editorconfig.org 2 | root = true 3 | 4 | [*] 5 | indent_style = space 6 | indent_size = 2 7 | end_of_line = lf 8 | charset = utf-8 9 | trim_trailing_whitespace = true 10 | insert_final_newline = true -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | .DS_Store 2 | build 3 | lib-cov 4 | *.seed 5 | *.log 6 | *.csv 7 | *.dat 8 | *.out 9 | *.pid 10 | *.gz 11 | 12 | pids 13 | logs 14 | results 15 | 16 | npm-debug.log 17 | node_modules 18 | *.sublime* 19 | *.node 20 | coverage 21 | *.orig 22 | .idea 23 | sandbox 24 | -------------------------------------------------------------------------------- /.jshintrc: -------------------------------------------------------------------------------- 1 | { 2 | "camelcase": true, 3 | "curly": true, 4 | "eqeqeq": true, 5 | "freeze": true, 6 | "indent": 2, 7 | "newcap": false, 8 | "quotmark": "single", 9 | "maxdepth": 3, 10 | "maxstatements": 50, 11 | "maxlen": 80, 12 | "eqnull": true, 13 | "funcscope": true, 14 | "strict": true, 15 | "undef": true, 16 | "unused": true, 17 | "node": true, 18 | "mocha": true 19 | } 20 | -------------------------------------------------------------------------------- /.npmignore: -------------------------------------------------------------------------------- 1 | .DS_Store 2 | build 3 | lib-cov 4 | *.seed 5 | *.log 6 | *.csv 7 | *.dat 8 | *.out 9 | *.pid 10 | *.gz 11 | 12 | pids 13 | logs 14 | results 15 | 16 | npm-debug.log 17 | node_modules 18 | *.sublime* 19 | *.node 20 | coverage 21 | *.orig 22 | .idea 23 | sandbox 24 | -------------------------------------------------------------------------------- /.travis.yml: -------------------------------------------------------------------------------- 1 | sudo: false 2 | language: node_js 3 | node_js: 4 | - 'iojs' 5 | - '0.12' 6 | - '0.10' 7 | - '4.0.0' 8 | after_script: 9 | - npm run coveralls 10 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | Copyright (c) 2015 Contra 2 | 3 | Permission is hereby granted, free of charge, to any person obtaining 4 | a copy of this software and associated documentation files (the 5 | "Software"), to deal in the Software without restriction, including 6 | without limitation the rights to use, copy, modify, merge, publish, 7 | distribute, sublicense, and/or sell copies of the Software, and to 8 | permit persons to whom the Software is furnished to do so, subject to 9 | the following conditions: 10 | 11 | The above copyright notice and this permission notice shall be 12 | included in all copies or substantial portions of the Software. 13 | 14 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 15 | EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 16 | MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 17 | NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE 18 | LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION 19 | OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION 20 | WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 21 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # react-logger [![NPM version][npm-image]][npm-url] [![Downloads][downloads-image]][npm-url] 2 | 3 | ## Install 4 | 5 | ``` 6 | npm install react-logger --save 7 | ``` 8 | ## Usage 9 | 10 | This module exposes `console.log` `console.error` and `console.dir` on the component. Everything is what you would normally expect, but log messages are prefixed with the displayName of the component so you know where things are coming from. This also works cross-browser, so on browsers without the console object it won't blow up. 11 | 12 | ```js 13 | var React = require('react'); 14 | var LoggerMixin = require('react-logger'); 15 | 16 | React.createClass({ 17 | displayName: 'TestComponent', 18 | // Add mixin 19 | mixins: [LoggerMixin], 20 | componentDidMount: function() { 21 | // Log: [TestComponent] something insightful 22 | this.log('something insightful'); 23 | }, 24 | render: function() { 25 | // do stuff here 26 | } 27 | }); 28 | ``` 29 | 30 | ## LICENSE 31 | 32 | (MIT License) 33 | 34 | Copyright (c) 2016 Contra 35 | 36 | Permission is hereby granted, free of charge, to any person obtaining 37 | a copy of this software and associated documentation files (the 38 | "Software"), to deal in the Software without restriction, including 39 | without limitation the rights to use, copy, modify, merge, publish, 40 | distribute, sublicense, and/or sell copies of the Software, and to 41 | permit persons to whom the Software is furnished to do so, subject to 42 | the following conditions: 43 | 44 | The above copyright notice and this permission notice shall be 45 | included in all copies or substantial portions of the Software. 46 | 47 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 48 | EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 49 | MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 50 | NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE 51 | LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION 52 | OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION 53 | WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 54 | 55 | [gittip-url]: https://www.gittip.com/contra/ 56 | [gittip-image]: http://img.shields.io/gittip/contra.svg 57 | 58 | [downloads-image]: http://img.shields.io/npm/dm/react-logger.svg 59 | [npm-url]: https://npmjs.org/package/react-logger 60 | [npm-image]: http://img.shields.io/npm/v/react-logger.svg 61 | 62 | [travis-url]: https://travis-ci.org/contra/react-logger 63 | [travis-image]: https://travis-ci.org/contra/react-logger.png?branch=master 64 | 65 | [coveralls-url]: https://coveralls.io/r/contra/react-logger 66 | [coveralls-image]: https://coveralls.io/repos/contra/react-logger/badge.png 67 | 68 | [depstat-url]: https://david-dm.org/contra/react-logger 69 | [depstat-image]: https://david-dm.org/contra/react-logger.png 70 | 71 | [david-url]: https://david-dm.org/contra/react-logger 72 | [david-image]: https://david-dm.org/contra/react-logger.png?theme=shields.io 73 | -------------------------------------------------------------------------------- /index.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | 3 | var slice = require('array-slice'); 4 | var console = require('console'); 5 | 6 | var levels = ['log', 'dir', 'error', 'count', 'info']; 7 | 8 | var logger = {}; 9 | 10 | levels.forEach(function (level) { 11 | logger[level] = function() { 12 | var args = slice(arguments); 13 | args.unshift('[' + this.constructor.displayName + ']'); 14 | console[level].apply(console, args); 15 | }; 16 | }); 17 | 18 | module.exports = logger; 19 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "react-logger", 3 | "description": "Dead simple logging mixin for react", 4 | "version": "1.1.0", 5 | "homepage": "http://github.com/contra/react-logger", 6 | "repository": "git://github.com/contra/react-logger.git", 7 | "author": "Contra (http://contra.io)", 8 | "dependencies": { 9 | "array-slice": "^0.2.3", 10 | "console": "^0.5.2" 11 | }, 12 | "devDependencies": { 13 | "istanbul-coveralls": "^1.0.3", 14 | "jshint": "^2.5.11", 15 | "jshint-stylish": "^2.1.0", 16 | "mochify": "dylanfm/mochify.js", 17 | "mochify-istanbul": "^2.3.0", 18 | "should": "^8.0.0" 19 | }, 20 | "main": "./index.js", 21 | "scripts": { 22 | "lint": "jshint index.js --exclude node_modules --config .jshintrc --reporter node_modules/jshint-stylish/index.js", 23 | "test": "npm run-script lint && mochify --recursive --reporter spec", 24 | "coveralls": "mochify --recursive --plugin [ mochify-istanbul --exclude '**/+(test|node_modules)/**/*' --report lcov --dir ./coverage ] && istanbul-coveralls" 25 | }, 26 | "engines": { 27 | "node": ">= 0.10" 28 | }, 29 | "license": "MIT" 30 | } 31 | -------------------------------------------------------------------------------- /test/index.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | 3 | var should = require('should'); 4 | var logger = require('../'); 5 | 6 | var dummy = { 7 | constructor: { 8 | displayName: 'test' 9 | } 10 | }; 11 | 12 | describe('logger', function() { 13 | it('should be able to call log', function(done) { 14 | logger.log.call(dummy, 'test', 123); 15 | done(); 16 | }); 17 | it('should be able to call dir', function(done) { 18 | logger.dir.call(dummy); 19 | done(); 20 | }); 21 | it('should be able to call error', function(done) { 22 | // logger.error.call(dummy, 'test', 123); 23 | done(); 24 | }); 25 | it('should be able to call count', function(done) { 26 | logger.count.call(dummy); 27 | done(); 28 | }); 29 | it('should be able to call info', function(done) { 30 | logger.info.call(dummy, 'test', 123); 31 | done(); 32 | }); 33 | }); 34 | --------------------------------------------------------------------------------