Comparing version 2.0.2 to 2.0.3
@@ -13,3 +13,3 @@ import { Logger } from './Logger'; | ||
name: string; | ||
level: string; | ||
level: Lowercase<keyof typeof Level>; | ||
} | ||
@@ -16,0 +16,0 @@ export interface Factory { |
@@ -62,2 +62,21 @@ "use strict"; | ||
}; | ||
var checkIfLevelBelow = function(event) { | ||
var level = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : Level.Debug; | ||
var levelKey = (0, _utils.capitalize)(event.level); | ||
return level > Level[levelKey]; | ||
}; | ||
var provideToFactory = function(events) { | ||
var level = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : Level.Debug; | ||
var filteredEvents = events.filter(function(e) { | ||
return !checkIfLevelBelow(e, level); | ||
}); | ||
// events is empty if all are below set level | ||
if (filteredEvents.length > 0) { | ||
var _ref; | ||
var ref; | ||
(ref = __slf._factory) === null || ref === void 0 ? void 0 : (_ref = ref).call.apply(_ref, [ | ||
__slf | ||
].concat(_toConsumableArray(filteredEvents))); | ||
} | ||
}; | ||
var __slf = global.__slf ? global.__slf : global.__slf = { | ||
@@ -89,4 +108,3 @@ _chain: [], | ||
if (__slf._factory) { | ||
var ___slf; | ||
(___slf = __slf)._factory.apply(___slf, _toConsumableArray(args)); | ||
provideToFactory(args, LoggerFactory.getLogLevel()); | ||
} else { | ||
@@ -110,7 +128,3 @@ __slf._queued[__slf._queued.length % 100] = args; | ||
__slf._queued.forEach(function(evt) { | ||
var _ref; | ||
var ref; | ||
(ref = __slf._factory) === null || ref === void 0 ? void 0 : (_ref = ref).call.apply(_ref, [ | ||
__slf | ||
].concat(_toConsumableArray(evt))); | ||
return provideToFactory(evt, level); | ||
}); | ||
@@ -117,0 +131,0 @@ __slf._queued.length = 0; |
{ | ||
"name": "slf", | ||
"version": "2.0.2", | ||
"version": "2.0.3", | ||
"description": "Simple Logging Facade", | ||
@@ -5,0 +5,0 @@ "main": "lib/index.js", |
# slf | ||
Surikat Log Facade | ||
## Install | ||
```bash | ||
@@ -10,5 +12,7 @@ npm install --save slf | ||
## API | ||
Get a logger | ||
```javascript | ||
import {LoggerFactory} from 'slf'; | ||
import { LoggerFactory } from 'slf'; | ||
@@ -18,10 +22,10 @@ const log = LoggerFactory.getLogger('name'); | ||
const log = LoggerFactory.getLogger('name:subname:subsubname'); | ||
``` | ||
### Logging | ||
```javascript | ||
log('Hello!') // As level info | ||
log('Hello!'); // As level info | ||
log.log('info', 'Hello!'); // as level info | ||
log.log('Hello!') // as level info (implicit) | ||
log.log('Hello!'); // as level info (implicit) | ||
@@ -35,5 +39,7 @@ log.trace('My Trace'); | ||
``` | ||
### Formatting | ||
Using util.format(...) | ||
- %s - String. | ||
@@ -43,2 +49,3 @@ - %d - Number (both integer and float). | ||
- %% - single percent sign ('%'). This does not consume an argument. | ||
```javascript | ||
@@ -54,5 +61,6 @@ log.info('My Formatted %s', 'Message') | ||
Json Formatting | ||
```javascript | ||
log.info({a: 'aloha'}) | ||
>> {a: 'aloha'} | ||
log.info({ a: 'aloha' }) | ||
>> { a: 'aloha' } | ||
log.info('My Formatted %d', 123) | ||
@@ -65,2 +73,3 @@ >> 'My Formatted 123' | ||
## Configuring a Provider | ||
```javascript | ||
@@ -71,3 +80,21 @@ LoggerFactory.setFactory(<factory-function>); | ||
### Log Levels | ||
When setting a factory provider, you can also set a level to ensure not to send logs if the level is too low. | ||
#### Set Level | ||
```javascript | ||
LoggerFacotry.setFactory(ConsoleLogger, Level.Info); | ||
``` | ||
#### Hierarchy | ||
- Critical | ||
- Error | ||
- Warn | ||
- Info | ||
- Debug | ||
## Writing a Provider | ||
SLF is nothing without a backing logging implementation. | ||
@@ -79,2 +106,3 @@ The most tiny implementation of a console.log based implementation is shipped with SLF | ||
factory-function has the following signature: | ||
```javascript | ||
@@ -93,3 +121,1 @@ function(loggerName) { | ||
``` | ||
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
20807
453
113