Consistent logging and formatting for all intribe applications
This library provides common logging methods e.g. trace, debug, info, error etc and enables a basic template/log format to be specified. So that all intribe applications can be configured to produce the same log output for a collective logging service - such as stackdriver or splunk.
import {Logger} from './Logger';
let logger = new Logger({});
logger.trace('trace message');
logger.debug('debug message');
logger.info('info message');
logger.warning('warning message');
logger.error('error message');
logger.fatal('fatal message');
There are some minimal configuration options (see /src/ILoggerOptions.ts) which have some sane defaults set (see src/Defaults.ts)
import {Logger} from './Logger';
import {LogLevels} from './LogLevels';
let options = {
appName: 'intribe-api',
logFormat: '%appName% %logLevelEmoji% %logLevel% %message%',
outputLogLevels: [
LogLevels.INFO,
LogLevels.WARNING,
LogLevels.ERROR,
LogLevels.FATAL,
],
outputFunction: (message: string, logLevel: LogLevels) => {
switch (logLevel) {
case LogLevels.INFO:
case LogLevels.DEBUG:
case LogLevels.TRACE:
console.log(message);
break;
case LogLevels.WARNING:
console.warn(message);
break;
case LogLevels.ERROR:
case LogLevels.FATAL:
console.error(message);
break;
default:
console.log(message);
break;
}
}
};
let logger = new Logger(options);
Builds compile in to the dist dir, the entry point being dist/index.js. Builds should automatically occur during a git commit.
You can run tests against the typescript code when developing with:
npm test
You can build the distribution code with:
npm run build
Note that build will also run mocha (tests) over the built files
You can run just the tests after building the dist code by running
npm run build:test