Comparing version 0.0.1 to 1.0.0
@@ -32,3 +32,3 @@ "use strict"; | ||
const setLogdaLevel = level => { | ||
const setLogdaLevel = (level = 'error') => { | ||
defaultLevel = (0, _Level.resolveLevel)(level); | ||
@@ -40,3 +40,3 @@ updateLogdaLevel(); | ||
const logdaFactory = () => tag => { | ||
const logdaFactory = () => (tag = '') => { | ||
return new _LogdaLogger.LogdaLogger({ | ||
@@ -43,0 +43,0 @@ tags: [tag], |
@@ -7,3 +7,3 @@ "use strict"; | ||
exports.SEPARATOR = exports.EMPTY = exports.DEFAULT_LEVEL = exports.LOCAL_STORAGE_LEVEL = exports.GLOBAL_ITEM = void 0; | ||
const GLOBAL_ITEM = '_LOGDA'; | ||
const GLOBAL_ITEM = 'logda'; | ||
exports.GLOBAL_ITEM = GLOBAL_ITEM; | ||
@@ -10,0 +10,0 @@ const LOCAL_STORAGE_LEVEL = GLOBAL_ITEM + '.level'; |
@@ -16,3 +16,3 @@ "use strict"; | ||
level | ||
} = {}) { | ||
}) { | ||
this._children = new Map(); | ||
@@ -26,3 +26,3 @@ this._tags = tags; | ||
_createLabel() { | ||
const tagsLabel = this._tags.join(_constants.SEPARATOR); | ||
const tagsLabel = this._tags.filter(tag => tag && tag.length > 0).join(_constants.SEPARATOR); | ||
@@ -69,3 +69,3 @@ return tagsLabel.length > 0 ? `${tagsLabel}>` : _constants.EMPTY; | ||
try { | ||
const label = `[${level}]>${this._label}`; | ||
const label = `[${level}] ${this._label}`; | ||
const args = provider(); | ||
@@ -72,0 +72,0 @@ if (Array.isArray(args)) writter(label, ...args);else writter(label, args); |
{ | ||
"name": "logda", | ||
"version": "0.0.1", | ||
"version": "1.0.0", | ||
"description": "Efficient lightweight logger", | ||
@@ -9,2 +9,4 @@ "main": "dist", | ||
"logger", | ||
"stacktrace", | ||
"debug", | ||
"browser" | ||
@@ -14,2 +16,5 @@ ], | ||
"license": "MIT", | ||
"repository": "github:alextremp/logda", | ||
"bugs": "https://github.com/alextremp/logda/issues", | ||
"runkitExampleFile": "runkitExample.js", | ||
"scripts": { | ||
@@ -20,8 +25,9 @@ "clean": "rm -Rf dist", | ||
"test": "mocha --recursive --require @babel/register \"src/test/**/*Test.js\"", | ||
"coverage": "istanbul cover --report html _mocha -- ./src/test* --recursive --compilers js:@babel/register", | ||
"coverage:ci": "istanbul cover _mocha -- ./src/test* --recursive --compilers js:@babel/register && codecov", | ||
"coverage": "nyc --reporter=html --exclude=\"src/test\" npm run test", | ||
"coverage:ci": "nyc --reporter=cobertura --exclude=\"src/test\" npm run test && codecov", | ||
"local": "webpack-dev-server --config local/webpack.config.babel.js", | ||
"lint": "sui-lint js", | ||
"check": "npm run lint && npm run test", | ||
"build": "babel src/main --out-dir dist" | ||
"build": "babel src/main --out-dir dist", | ||
"versiona": "node versiona.js" | ||
}, | ||
@@ -40,3 +46,2 @@ "devDependencies": { | ||
"html-webpack-plugin": "^3.2.0", | ||
"istanbul": "1.1.0-alpha.1", | ||
"jsdom": "15.2.1", | ||
@@ -46,4 +51,6 @@ "jsdom-global": "3.0.2", | ||
"mocha": "5.2.0", | ||
"nyc": "^15.0.0", | ||
"querystring": "^0.2.0", | ||
"sinon": "^7.5.0", | ||
"versiona": "^3.0.0", | ||
"webpack": "^4.41.2", | ||
@@ -67,2 +74,2 @@ "webpack-cli": "^3.3.10", | ||
} | ||
} | ||
} |
151
README.md
@@ -1,5 +0,154 @@ | ||
# logda | ||
# logda [![NPM Module](https://img.shields.io/npm/v/logda.svg)](https://www.npmjs.com/package/logda) | ||
[![Build Status](https://travis-ci.org/alextremp/logda.svg?branch=master)](https://travis-ci.org/alextremp/logda) | ||
[![codecov](https://codecov.io/gh/alextremp/logda/branch/master/graph/badge.svg)](https://codecov.io/gh/alextremp/logda) | ||
[![Maintainability](https://api.codeclimate.com/v1/badges/53000060cbda73bad602/maintainability)](https://codeclimate.com/github/alextremp/logda/maintainability) | ||
**logda** is a lightweight efficient logger thought for developers who use to debug their libraries running in production when something goes wrong, without worrying about global objects or reconfigurations. | ||
* It works as a _console_ wrapper but with **level** capabilites, so no logs will be written down the desired level. | ||
* It receives arrow functions instead of built messages, so when running under the configured level, no heavy log operations will be executed. Also, these operations will never break your app as they run into a catcheable block. | ||
## Features | ||
* :rocket: **Efficient logger**: Will not run unnecessary operations, as all logger operations are delegated with an arrow function | ||
* :sparkles: **Pretty printer**: When enabled, distinguish different modules or files using tags | ||
* :bulb: **Developer ready**: Set the _logda.level_ into your _window.localStorage_ to enable logda loggers for the apps you're reviewing (if you don't remove it from the local storage, you'll be able to review logs the next time you visit the page!) | ||
## Usage | ||
Install | ||
``` | ||
npm install logda --save | ||
``` | ||
Create a root logger for your module: (optional but recommended for better log messages) | ||
`logger.js` | ||
``` ecmascript 6 | ||
import {logda} from 'logda' | ||
const LOG = logda('my-app') | ||
LOG.info(() => 'Logda log initialized') | ||
export default LOG | ||
``` | ||
* The exported LOG is a logda logger already, you can call all level methods on it, but also allows creating sub-loggers by calling the _logger_ method. In this case, the _.info_ call (if info is enabled) will print: | ||
``` | ||
[INFO] my-app> Logda log initialized | ||
``` | ||
Import this root logger to all files requiring a logger: (for example, MyService.js) | ||
`MyService.js` | ||
``` ecmascript 6 | ||
import LOG from './logger.js | ||
const log = LOG.logger('MyService') | ||
class MyService { | ||
// ... | ||
aMethod(params) { | ||
log.debug(() => ['aMethod', {params}]) | ||
} | ||
} | ||
``` | ||
* The created _log_ is a LOG sub-logger that when debug is enabled will print a message like: | ||
``` | ||
[DEBUG] my-app|MyService> aMethod {...} | ||
``` | ||
### Write logs | ||
Logda is intended to be used with arrow functions, so to log messages, call the level method with an arrow function: | ||
```ecmascript 6 | ||
log.debug(() => 'log messages as simple strings') | ||
log.debug(() => ['log complex data inside an array', { | ||
aKey: 'aValue', | ||
another: calculatedData() | ||
}]) | ||
``` | ||
>Encapsulating data into an object {} will help you to review it correlating key-valued data in message logs | ||
### Change the log level | ||
Logda accepts 'trace', 'debug', 'info', 'warn', 'error', 'off' levels. | ||
Console correspondency: | ||
* log.trace => console.trace | ||
* log.debug => console.log | ||
* log.info => console.info | ||
* log.error => console.error | ||
'off' is intended to disable all logs including 'error' logs. | ||
* Developer-only level: | ||
In your browser's console, write: | ||
``` | ||
window.localStorage.setItem('logda.level', 'debug') | ||
``` | ||
* Application level: | ||
In case that you want a lower level to log messages (Node environments, loc/dev builds, ...), you can enable a specific logda level programmatically: | ||
`logger.js` | ||
``` ecmascript 6 | ||
import {logda, setLogdaLevel} from 'logda' | ||
setLogdaLevel('info') | ||
const LOG = logda('my-app') | ||
LOG.info(() => 'Logda log initialized') | ||
export default LOG | ||
``` | ||
>In this case, 'Logda log initialized' will be printed directly | ||
>In browser environments, the localStorage 'logda.level' (if set) will override the application level | ||
## Contributing | ||
:wrench: Maintenance info | ||
### Available Scripts | ||
_npm run_... | ||
* **phoenix** to reset the project reinstalling its dependencies | ||
* **lint** to check the code format | ||
* **test** to run the project tests | ||
* **check** to run both lint&test | ||
* **coverage** to get an html test coverage report | ||
* **build** to build the project | ||
* **versiona** to publish a new version of the library (in Travis CI) | ||
### Create a PR | ||
Use the PR template to explain the better possible: | ||
* Why the PR should be merged | ||
* How can be checked | ||
### Deploying | ||
This project uses Travis CI for: | ||
* PR validation | ||
* Merge to master validation | ||
* NPM publications on Release tag creation | ||
To create a new Release, take in mind: | ||
* The Release Tag must be named *vX.Y.Z* where X.Y.Z are the _semver_ numbers that will correspond to the published package's version. | ||
* Travis CI will launch the versiona.js script which will: | ||
* Update the package.json to the X.Y.Z version set in the Release Tag | ||
* Publish the NPM package with the X.Y.Z version |
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
No bug tracker
MaintenancePackage does not have a linked bug tracker in package.json.
Found 1 instance in 1 package
No repository
Supply chain riskPackage does not have a linked source code repository. Without this field, a package will have no reference to the location of the source code use to generate the package.
Found 1 instance in 1 package
No v1
QualityPackage is not semver >=1. This means it is not stable and does not support ^ ranges.
Found 1 instance in 1 package
16581
9
147
1
155
22