-
Notifications
You must be signed in to change notification settings - Fork 250
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(logging): Allow log to a file (#954)
This feature adds the ability to log to a "stryker.log" file using a separate log level. You can configure it like this: ```js // stryker.conf.js module.exports = function(config) { config.set({ fileLogLevel: 'trace' // defaults to 'off' }); } ``` **Note:** The console logger can still be configured as expected using `logLevel: 'info'`. This also adds logging to the stryker api. Plugin creators can now opt into stryker logging using the new logging api: ```ts import { getLogger, Logger } from 'stryker-api/logging'; const logger: Logger = getLogger('myLoggerCategory'); ``` They no longer have to 'role their own config'. Stryker will take care of the logging appearing in the expected places (console and file). Fixes #748
- Loading branch information
Showing
149 changed files
with
1,269 additions
and
708 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,7 @@ | ||
node_modules | ||
lerna-debug.log | ||
npm-debug.log | ||
stryker.log | ||
|
||
coverage | ||
reports | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
export { default as LoggerFactory } from './src/logging/LoggerFactory'; | ||
export { default as Logger } from './src/logging/Logger'; | ||
export { default as LoggerFactoryMethod } from './src/logging/LoggerFactoryMethod'; | ||
export { default as getLogger } from './src/logging/getLogger'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
|
||
enum LogLevel { | ||
Off = 'off', | ||
Fatal = 'fatal', | ||
Error = 'error', | ||
Warning = 'warn', | ||
Information = 'info', | ||
Debug = 'debug', | ||
Trace = 'trace' | ||
} | ||
|
||
export default LogLevel; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
export default interface Logger { | ||
isTraceEnabled(): boolean; | ||
isDebugEnabled(): boolean; | ||
isInfoEnabled(): boolean; | ||
isWarnEnabled(): boolean; | ||
isErrorEnabled(): boolean; | ||
isFatalEnabled(): boolean; | ||
|
||
trace(message: string, ...args: any[]): void; | ||
debug(message: string, ...args: any[]): void; | ||
info(message: string, ...args: any[]): void; | ||
warn(message: string, ...args: any[]): void; | ||
error(message: string, ...args: any[]): void; | ||
fatal(message: string, ...args: any[]): void; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
import LoggerFactoryMethod from './LoggerFactoryMethod'; | ||
import Logger from './Logger'; | ||
|
||
const noopLogger: Logger = { | ||
isTraceEnabled(): boolean { return false; }, | ||
isDebugEnabled(): boolean { return false; }, | ||
isInfoEnabled(): boolean { return false; }, | ||
isWarnEnabled(): boolean { return false; }, | ||
isErrorEnabled(): boolean { return false; }, | ||
isFatalEnabled(): boolean { return false; }, | ||
trace(): void { }, | ||
debug(): void { }, | ||
info(): void { }, | ||
warn(): void { }, | ||
error(): void { }, | ||
fatal(): void { } | ||
}; | ||
|
||
let logImplementation: LoggerFactoryMethod = () => noopLogger; | ||
|
||
export default class LoggerFactory { | ||
|
||
static setLogImplementation(implementation: LoggerFactoryMethod) { | ||
logImplementation = implementation; | ||
} | ||
|
||
static getLogger: LoggerFactoryMethod = (categoryName?: string) => { | ||
return logImplementation(categoryName); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
import Logger from './Logger'; | ||
|
||
/** | ||
* Represents a factory to get loggers by category name. | ||
* This interface is used to describe the shape of a logger factory method. | ||
* | ||
* @param {String} [categoryName] name of category to log to. | ||
* @returns {Logger} instance of logger for the category | ||
*/ | ||
export default interface LoggerFactoryMethod { | ||
(categoryName?: string): Logger; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
import LoggerFactory from './LoggerFactory'; | ||
import LoggerFactoryMethod from './LoggerFactoryMethod'; | ||
|
||
const getLogger: LoggerFactoryMethod = LoggerFactory.getLogger; | ||
|
||
export default getLogger; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
import { expect } from 'chai'; | ||
import LogLevel from '../../../src/core/LogLevel'; | ||
|
||
describe('LogLevel', () => { | ||
|
||
function arrangeActAssertLogLevel(actual: LogLevel, expected: string) { | ||
it(`should provide "${expected}" for log level "${actual}"`, () => { | ||
expect(actual).eq(expected); | ||
}); | ||
} | ||
|
||
arrangeActAssertLogLevel(LogLevel.Off, 'off'); | ||
arrangeActAssertLogLevel(LogLevel.Fatal, 'fatal'); | ||
arrangeActAssertLogLevel(LogLevel.Error, 'error'); | ||
arrangeActAssertLogLevel(LogLevel.Warning, 'warn'); | ||
arrangeActAssertLogLevel(LogLevel.Information, 'info'); | ||
arrangeActAssertLogLevel(LogLevel.Debug, 'debug'); | ||
arrangeActAssertLogLevel(LogLevel.Trace, 'trace'); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.