@kofile/log
Advanced tools
Comparing version 1.3.0 to 1.4.0
24
Log.js
@@ -0,7 +1,11 @@ | ||
const chalk = require('chalk') | ||
const Timer = require('@kofile/timer') | ||
const Adapters = require('./adapters') | ||
const Timer = require('./Timer') | ||
const formatMessageFor = (level, meta) => message => { | ||
const makeFormatMessageFor = color => (level, meta) => message => { | ||
const time = new Date().toISOString() | ||
const baseMessage = `${time} [${level}] ${message || ''}` | ||
const levelColor = Log.LEVEL_COLORS[level] | ||
const timestamp = color.gray(time) | ||
const levelLabel = color[levelColor](`[${level}]`) | ||
const baseMessage = `${timestamp} ${levelLabel} ${message || ''}` | ||
@@ -49,2 +53,9 @@ if (meta) { | ||
this._colorer = | ||
(params || {}).colors === false | ||
? new chalk.constructor({ enabled: false }) | ||
: chalk | ||
const formatMessageFor = makeFormatMessageFor(this._colorer) | ||
this._adapter = (params || {}).adapter || new Adapters.Console(console) | ||
@@ -134,2 +145,9 @@ this._formatError = formatMessageFor(klass.LEVELS.ERROR, this._meta) | ||
Log.LEVEL_COLORS = { | ||
ERROR: 'red', | ||
WARN: 'yellow', | ||
INFO: 'green', | ||
DEBUG: 'cyan' | ||
} | ||
module.exports = Log |
@@ -1,1 +0,1 @@ | ||
{"name":"@kofile/log","version":"1.3.0","description":"Node log wrapper","author":"Evan Sherwood <evan@sherwood.io>","license":"MIT","main":"index.js","files":["index.js","Timer.js","Log.js","adapters/Console/index.js","adapters/Adapter.js","adapters/index.js"],"devDependencies":{"ava":"^0.22.0","commitizen":"^2.9.6","coveralls":"^2.13.1","cz-cli":"^1.0.0","cz-conventional-changelog":"^2.0.0","husky":"^0.13.4","lint-staged":"^3.6.0","nyc":"^11.1.0","prettier-standard":"^6.0.0","semantic-release":"^8.2.0","sinon":"^4.0.1","snazzy":"^7.0.0","standard":"^10.0.3"},"lint-staged":{"*.js":["prettier-standard","git add"]},"scripts":{"precommit":"lint-staged","commit":"git-cz","lint":"standard | snazzy","test":"nyc ava","semantic-release":"semantic-release pre && npm publish && semantic-release post"},"config":{"commitizen":{"path":"node_modules/cz-conventional-changelog"}},"nyc":{"include":["index.js","Timer.js","Log.js","adapters/Console/index.js","adapters/Adapter.js","adapters/index.js"]},"repository":{"type":"git","url":"https://github.com/kofile/log.git"}} | ||
{"name":"@kofile/log","version":"1.4.0","description":"Node log wrapper","author":"Evan Sherwood <evan@sherwood.io>","license":"MIT","main":"index.js","files":["index.js","Log.js","adapters/Console/index.js","adapters/Adapter.js","adapters/index.js"],"devDependencies":{"ava":"^0.22.0","commitizen":"^2.9.6","coveralls":"^2.13.1","cz-cli":"^1.0.0","cz-conventional-changelog":"^2.0.0","husky":"^0.13.4","lint-staged":"^3.6.0","nyc":"^11.1.0","prettier-standard":"^6.0.0","semantic-release":"^8.2.0","sinon":"^4.0.1","snazzy":"^7.0.0","standard":"^10.0.3"},"lint-staged":{"*.js":["prettier-standard","git add"]},"scripts":{"precommit":"lint-staged","commit":"git-cz","lint":"standard | snazzy","test":"nyc ava","semantic-release":"semantic-release pre && npm publish && semantic-release post"},"config":{"commitizen":{"path":"node_modules/cz-conventional-changelog"}},"nyc":{"include":["index.js","Log.js","adapters/Console/index.js","adapters/Adapter.js","adapters/index.js"]},"repository":{"type":"git","url":"https://github.com/kofile/log.git"},"dependencies":{"@kofile/timer":"^1.0.1","chalk":"^2.3.0"}} |
@@ -69,4 +69,6 @@ # Log | ||
If you want access to export the `LEVELS`, you can do so: | ||
```js | ||
const { LEVELS } = require('@kofile/log') | ||
LEVELS.DEBUG //=> 'DEBUG' | ||
@@ -85,2 +87,8 @@ ``` | ||
You can disable coloring by passing in `colors: false`: | ||
```js | ||
const log = makeLog({ colors: false }) | ||
``` | ||
Meta must be an object. | ||
@@ -107,3 +115,3 @@ | ||
Set the given level as the new log level for this instance. | ||
Set the given level as the new log level for this instance. | ||
@@ -172,2 +180,4 @@ Log level must be one of `Log.LEVELS`. | ||
Please see the [Timer](https://github.com/kofile/timer) documentation. | ||
<a name="why"></a> | ||
@@ -174,0 +184,0 @@ ## Why? |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
200
10756
2
7
162
+ Added@kofile/timer@^1.0.1
+ Addedchalk@^2.3.0
+ Added@kofile/timer@1.0.1(transitive)
+ Addedansi-styles@3.2.1(transitive)
+ Addedchalk@2.4.2(transitive)
+ Addedcolor-convert@1.9.3(transitive)
+ Addedcolor-name@1.1.3(transitive)
+ Addedescape-string-regexp@1.0.5(transitive)
+ Addedhas-flag@3.0.0(transitive)
+ Addedsupports-color@5.5.0(transitive)