diff --git a/.eslintrc b/.eslintrc deleted file mode 100644 index 6b8cece..0000000 --- a/.eslintrc +++ /dev/null @@ -1,208 +0,0 @@ -{ - "env": { - "browser": true, - "es6": true, - "node": true - }, - "globals": { - "debug": false - }, - "parser": "babel-eslint", - "rules": { - "accessor-pairs": 0, - "array-bracket-spacing": [2, "never"], - "array-callback-return": 2, - "arrow-parens": ["error", "as-needed", { - "requireForBlockBody": true - }], - "block-scoped-var": 2, - "block-spacing": [2, "always"], - "brace-style": [2, "1tbs", { - "allowSingleLine": true - }], - "class-methods-use-this": [0, { - "exceptMethods": [] - }], - "comma-dangle": [2, "never"], - "comma-spacing": [2, { - "before": false, - "after": true - }], - "comma-style": [2, "first"], - "complexity": [0, 11], - "consistent-return": 0, - "consistent-this": [2, "that"], - "curly": [2, "multi-line"], - "default-case": 0, - "dot-location": [2, "property"], - "dot-notation": [1, { - "allowKeywords": true - }], - "eol-last": 2, - "eqeqeq": [2, "always", { - "null": "ignore" - }], - "guard-for-in": 2, - "indent": [1, 4, { - "FunctionDeclaration": { - "parameters": "first" - }, - "FunctionExpression": { - "parameters": "first" - }, - "SwitchCase": 1 - }], - "key-spacing": [0, { - "align": "colon", - "afterColon": true - }], - "keyword-spacing": [2, { - "overrides": { - "else": { - "before": true - }, - "while": { - "before": true - }, - "catch": { - "before": true - } - } - }], - "max-len": [1, 160, 2, { - "ignoreComments": true - }], - "no-alert": 1, - "no-caller": 2, - "no-case-declarations": 2, - "no-cond-assign": [2, "except-parens"], - "no-const-assign": "error", - "no-div-regex": 0, - "no-else-return": 0, - "no-empty-function": [2, { - "allow": ["arrowFunctions", "functions", "methods"] - }], - "no-empty-pattern": 2, - "no-eq-null": 0, - "no-eval": 2, - "no-extend-native": 2, - "no-extra-bind": 2, - "no-extra-label": 2, - "no-fallthrough": 1, - "no-floating-decimal": 2, - "no-global-assign": [2, { - "exceptions": [] - }], - "no-implicit-coercion": [0, { - "boolean": false, - "number": true, - "string": true, - "allow": [] - }], - "no-implicit-globals": 0, - "no-implied-eval": 2, - "no-invalid-this": 0, - "no-iterator": 2, - "no-labels": [2, { - "allowLoop": false, - "allowSwitch": false - }], - "no-lone-blocks": 2, - "no-loop-func": 1, - "no-magic-numbers": [1, { - "ignore": [0, 1, -1, 2, 3, 4, 5, 6, 7, 8, 9, - 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, - 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, - 32, 80, 443, 8080, 8090, - 1024, 2048, 4096, 8192, - 200, 201, 202, 204, 301, 302, 400, 401, 403, 404, 405, 409, 410, 415, 500, 505, - 30, 60, 120, 180, 240, 300, 900, 1800, 3600, 7200, 14400, 43200, 86400, 172800, - 1000, 2000, 2500, 3000, 5000, 10000, 60000, 120000, 180000, 240000, 300000, 900000, 1800000, 3600000, 7200000, 14400000, 43200000, 86400000, 172800000], - "ignoreArrayIndexes": true, - "enforceConst": false, - "detectObjects": false - }], - "no-mixed-spaces-and-tabs": 2, - "no-multi-spaces": 2, - "no-multi-str": 2, - "no-native-reassign": 0, - "no-new": 0, - "no-new-func": 2, - "no-new-wrappers": 2, - "no-octal": 2, - "no-octal-escape": 2, - "no-param-reassign": 0, - "no-proto": 2, - "no-redeclare": 2, - "no-restricted-properties": [2, { - "object": "arguments", - "property": "callee", - "message": "arguments.callee is deprecated," - }, { - "property": "__defineGetter__", - "message": "Please use Object.defineProperty instead." - }, { - "property": "__defineSetter__", - "message": "Please use Object.defineProperty instead." - }], - "no-return-assign": 2, - "no-script-url": 2, - "no-self-assign": 2, - "no-self-compare": 2, - "no-sequences": 2, - "no-spaced-func": 2, - "no-throw-literal": 2, - "no-trailing-spaces": 2, - "no-undef": 2, - "no-unmodified-loop-condition": 0, - "no-unused-expressions": [2, { - "allowShortCircuit": false, - "allowTernary": false - }], - "no-unused-labels": 2, - "no-unused-vars": [1, { - "vars": "local", - "args": "none" - }], - "no-use-before-define": [2, { - "functions": false - }], - "no-useless-call": 0, - "no-useless-concat": 2, - "no-useless-escape": 2, - "no-void": 2, - "no-warning-comments": [0, { - "terms": ["todo", "fixme", "xxx"], - "location": "start" - }], - "no-with": 2, - "one-var": [0, { - "uninitialized": "always", - "initialized": "never" - }], - "operator-linebreak": [2, "after"], - "padded-blocks": [0, "never"], - "quote-props": [1, "consistent-as-needed"], - "quotes": [1, "single"], - "radix": 0, - "semi": [2, "always"], - "semi-spacing": [2, { - "before": false, - "after": true - }], - "space-before-blocks": [2, "always"], - "space-before-function-paren": [2, "never"], - "space-in-parens": [2, "never"], - "space-infix-ops": 2, - "space-unary-ops": [2, { - "words": false, - "nonwords": false - }], - "spaced-comment": [2, "always"], - "vars-on-top": 0, - "wrap-iife": [2, "outside", { - "functionPrototypeMethods": false - }], - "yoda": 0 - } -} diff --git a/index.js b/index.js index 1a8abf9..cc1005f 100644 --- a/index.js +++ b/index.js @@ -1,46 +1,46 @@ -// External Libraries -const Transport = require('winston-transport'); -const Logger = require('logdna').Logger; -const stringify = require('json-stringify-safe'); +'use strict' -// Constants -const DEFAULT_LEVEL = 'debug'; -const DEFAULT_NAME = 'LogDNA'; +const pkg = require('./package.json') +const Transport = require('winston-transport') +const Logger = require('logdna').Logger + +const DEFAULT_LEVEL = 'debug' +const DEFAULT_NAME = 'LogDNA' /* * Support for Winston Transport */ module.exports = class LogDNATransport extends Transport { - constructor(options) { - const pkg = require('./package.json'); - super(options); - this.name = options.name || DEFAULT_NAME; - this.level = options.level || DEFAULT_LEVEL; - this.index_meta = options.index_meta || false; - this.logger = new Logger(options.key, Object.assign({}, options, { - UserAgent: `${pkg.name}/${pkg.version}` - })); - } - - log(info, callback) { - info = info || {}; + constructor(options) { + super(options) + this.name = options.name || DEFAULT_NAME + this.level = options.level || DEFAULT_LEVEL + this.index_meta = options.index_meta || false + this.logger = new Logger(options.key, { + ...options + , UserAgent: `${pkg.name}/${pkg.version}` + }) + } - if (info.error instanceof Error) { - info.error = info.error.stack || info.error.toString(); - } + log(info, callback) { + info = info || {} - if (!info.message) { - info.message = stringify(info, null, 2, function() { return undefined; }); - } + if (info.error instanceof Error) { + info.error = info.error.stack || info.error.toString() + } - const { level, message, index_meta, ...meta } = info; - const opts = { - level: level - , index_meta: typeof info.index_meta === 'boolean' ? index_meta : this.index_meta - , context: meta || {} - }; + if (!info.message) { + info.message = JSON.stringify(info, null, 2, function() { return undefined }) + } - this.logger.log(message, opts); - if (callback) { callback(null, true); } + const {level, message, index_meta, ...meta} = info + const opts = { + level: level + , index_meta: typeof info.index_meta === 'boolean' ? index_meta : this.index_meta + , context: meta || {} } -}; + + this.logger.log(message, opts) + if (callback) { callback(null, true) } + } +} diff --git a/package.json b/package.json index 7548c83..43ca7a7 100644 --- a/package.json +++ b/package.json @@ -4,7 +4,7 @@ "description": "LogDNA's Node.js logging module with support for Winston", "main": "index.js", "scripts": { - "lint": "./node_modules/.bin/eslint -c .eslintrc *.js" + "lint": "eslint ." }, "repository": { "type": "git", @@ -30,11 +30,24 @@ }, "homepage": "https://github.com/logdna/logdna-winston#readme", "dependencies": { - "logdna": "^3.5.0", - "winston": "^3.2.1" + "logdna": "^3.5.0" }, "devDependencies": { - "babel-eslint": "^10.0.3", - "eslint": "^6.8.0" + "eslint": "^7.10.0", + "eslint-config-logdna": "^2.0.0", + "winston-transport": "^4.4.0" + }, + "eslintConfig": { + "extends": [ + "logdna" + ], + "root": true, + "ignorePatterns": [ + "node_modules/", + "coverage/" + ], + "parserOptions": { + "ecmaVersion": 2019 + } } }