Mock logger for testing logging behavior in Pelias projects
npm install pelias-mock-logger
This module is used for testing logging events in Pelias projects. proxyquire
is the supported module for overriding dependencies in which this module is used.
``bash`
$ npm install pelias-mock-logger --save-dev

The pelias-mock-logger npm module can be found here:
https://npmjs.org/package/pelias-mock-logger
Traditionally, testing logging events required quite a bit of setup with proxyquire:
`javascript
const errorMessages = [];
var service = proxyquire('../../../service/interpolation', {
'pelias-logger': {
get: () => {
return {
error: (msg) => { errorMessages.push(msg); },
info: (msg) => {}
};
}
}
}).search();
t.deepEquals(errorMessages, ['RequireTransport: failed to connect to interpolation service']);
`
Using the pelias-mock-logger module, this code can be shortened to:
`javascript
const logger = require('pelias-mock-logger')();
var adapter = proxyquire('../../../service/interpolation', {
'pelias-logger': logger
}).search();
t.deepEquals(logger.getErrorMessages(), ['RequireTransport: failed to connect to interpolation service']);
`
* logging events
* error(msg)warn(msg)
* info(msg)
* verbose(msg)
* debug(msg)
* silly(msg)
* getLayer()
* : returns the value passed to .get() in require( 'pelias-logger' ).get( 'api' )getLevels()
* : returns the supported logging levels: error, warn, info, verbose, debug, and sillygetMessages(level, pattern)
* : returns all messages logged at a level, optionally matching a patterngetMessages('error')
* Examples:
* getMessages('error', /backend error occurred/)
* hasMessages(level, pattern)
* : returns whether messages were logged at a level, optionally matching a patternhasMessages('error')
* Examples:
* hasMessages('error', /backend error occurred/)
* isMessage(level, pattern)
* : returns whether the supplied pattern matches or is equal to any messages logged at the specified levelisMessage('error', /backend error occurred)
* Examples
* isMessage('error', 'a backend error occurred, contact the Pelias team for assistance')
* getErrorMessages(pattern)
* level-specific functions
* getMessages: returns all messages logged at the level specified in function name, optionally matching a pattern
* getWarnMessages(pattern)
* getInfoMessages(pattern)
* getVerboseMessages(pattern)
* getDebugMessages(pattern)
* getSillyMessages(pattern)
* hasErrorMessages(pattern)
* hasMessages: returns whether messages were logged at the level specified in function name, optionally matching a pattern
* hasWarnMessages(pattern)
* hasInfoMessages(pattern)
* hasVerboseMessages(pattern)
* hasDebugMessages(pattern)
* hasSillyMessages(pattern)
* isErrorMessages(pattern)
* isMessage: returns whether the supplied pattern matches or is equal to any messages logged at the level specified in the function name
* isWarnMessages(pattern)
* isInfoMessages(pattern)
* isVerboseMessages(pattern)
* isDebugMessages(pattern)
* isSillyMessages(pattern)
*
Please fork and pull request against upstream master on a feature branch.
Provide unit tests in the test directory.
`bash``
$ npm test