-
Notifications
You must be signed in to change notification settings - Fork 250
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat(logging): Allow log to a file #954
Changes from 28 commits
01a9b36
187855e
a6feb8c
8e50b4f
09eb2f2
c50d69d
98c2bfb
c002d5c
7d2f3df
6590624
691e3a7
042117e
188bada
d5d483e
4fdc250
1729794
c14a520
0a30c08
5a92cc3
be5477f
3339086
10bed57
a820577
ee1efda
33aa4d9
c2882b9
f59d0c2
9d6a4f6
82db388
145e583
d10b523
cbe94cc
18859d6
0761b79
07cc2b1
bafa8e8
256f8ab
6f64f1d
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
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 | ||
|
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'; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Do we really need getLogger in a separate file or can we also just place the content here? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It is how our entire API is build up right now. Everything in separate files. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Let's leave it like this for now. |
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; |
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; | ||
} |
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); | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
import Logger from './Logger'; | ||
|
||
/** | ||
* Get a logger instance. Instance is cached on categoryName level. | ||
* | ||
* @param {String} [categoryName] name of category to log to. | ||
* @returns {Logger} instance of logger for the category | ||
* @static | ||
*/ | ||
export default interface LoggerFactoryMethod { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I don't understand why this exists and what it does There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I changed the description to:
Is this better? |
||
(categoryName?: string): Logger; | ||
} |
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; |
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'); | ||
}); |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
import * as log4js from 'log4js'; | ||
import * as logging from 'stryker-api/logging'; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. what else do we use from the logging here? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Nope, changing it to a named import. |
||
import fileUrl = require('file-url'); | ||
import * as path from 'path'; | ||
import { Config } from 'stryker-api/config'; | ||
|
@@ -7,7 +7,7 @@ import * as util from './util'; | |
import * as templates from './templates'; | ||
import Breadcrumb from './Breadcrumb'; | ||
|
||
const log = log4js.getLogger('HtmlReporter'); | ||
const log = logging.getLogger('HtmlReporter'); | ||
const DEFAULT_BASE_FOLDER = path.normalize('reports/mutation/html'); | ||
export const RESOURCES_DIR_NAME = 'strykerResources'; | ||
|
||
|
@@ -20,7 +20,6 @@ export default class HtmlReporter implements Reporter { | |
private scoreResult: ScoreResult; | ||
|
||
constructor(private options: Config) { | ||
log4js.setGlobalLogLevel(options.logLevel || 'info'); | ||
} | ||
|
||
onAllSourceFilesRead(files: SourceFile[]) { | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
import * as log4js from 'log4js'; | ||
import * as log4js from 'stryker-api/logging'; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is a log4jsMock file There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Good point. I'll change it. |
||
import * as sinon from 'sinon'; | ||
|
||
let logger = { | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -36,5 +36,6 @@ | |
"devDependencies": { | ||
"stryker-api": "^0.17.3" | ||
}, | ||
"contributors": [] | ||
"contributors": [], | ||
"dependencies": {} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why is this in a todo?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We get an error after 10 test runs because of this issue: jasmine/jasmine-npm#134. I'll add it as a comment.