-
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
Conversation
Finally got a green build! I even ran into a race condition with the log4js logging service. I still want to make the code in the |
…was not working, instead hope for the best
I've removed the retrying mechanism for getting a free port to log to as it was not working properly. Instead, removed the preference for port 5000 to decrease the likelihood of hitting an |
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.
Could you take a look at my comments? We need to make sure that we update the peer dependencies of packages ourselves to we drop support for older api versions with this change.
const strykerLog = await fs.readFile('./stryker.log', 'utf8'); | ||
expect(strykerLog).contains('INFO InputFileResolver Found 2 of 10 file(s) to be mutated'); | ||
expect(strykerLog).matches(/Stryker Done in \d+ seconds/); | ||
// expect(strykerLog).not.contains('ERROR'); 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.
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.
* @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 comment
The 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 comment
The reason will be displayed to describe this comment to others. Learn more.
I changed the description to:
* Represents a factory to get loggers by category name.
* This interface is used to describe the shape of a logger factory method.
Is this better?
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 comment
The 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 comment
The 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. getLogger
is also used from LoggerFactoryMethod
and others. You want me to move the entire logging API to this file?
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.
Let's leave it like this for now.
@@ -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 comment
The 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 comment
The reason will be displayed to describe this comment to others. Learn more.
Nope, changing it to a named import.
@@ -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 comment
The 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 comment
The reason will be displayed to describe this comment to others. Learn more.
Good point. I'll change it.
/** | ||
* Configure the logging for the server. Includes the master configuration. | ||
* This method can only be called ONCE, as it starts the log4js server to listen for log events. | ||
* It returns the logging client context that should be used to doe the `forWorker` calls. |
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.
What do you mean? There seem to be some errors in the last part of this sentence.
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.
Rephrased it as: It returns the logging client context that should be used to configure the child processes.
. I've also renamed the forWorker
method to configureChildProcess
. Is it clearer now?
|
||
/** | ||
* Configure the logging for the server. Includes the master configuration. | ||
* This method can only be called ONCE, as it starts the log4js server to listen for log events. |
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.
Can it only be called once or should it only be called once?
} | ||
|
||
function getLevel(level: LogLevel): log4js.Level { | ||
// Needs an any cast here, wrongly typed, see https://github.com/log4js-node/log4js-node/pull/745 |
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.
Isn't this fixed now?
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.
Awesome! My PR got merged. I've removed this entire method 👍
|
||
private static createMasterAppenders(consoleLogLevel: LogLevel, fileLogLevel: LogLevel): AppendersConfiguration { | ||
|
||
const multiAppender = { type: require.resolve('./MultiAppender'), appenders: ['filteredConsole'] }; |
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 require the type like this? What are you trying to do?
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.
That's the log4js way of loading custom appenders. See https://log4js-node.github.io/log4js-node/appenders.html#other-appenders. I'll add the link to the code as well so it's less magical.
} | ||
} | ||
|
||
export function configure(config: { appenders: string[] }, _: any, findAppender: (name: string) => RuntimeAppender ): RuntimeAppender { |
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.
Where is this used?
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.
It is used by log4js. See https://log4js-node.github.io/log4js-node/writing-appenders.html. I'll add a jsdoc explaining it.
* Add js docs * Add references to log4js documentation * Rename all wrong `log4js` references in plugins to `logging`
Thanks for the great review @simondel . I've implemented the changes, could you take a look? |
Just one question left @simondel. I'll try to update the peer dependency version later today as well. (But might be tomorrow) |
Looks good to me! Just one question, do we want to upgrade to log4js 3.0 in this PR or separately? |
Refactor code so additional arguments are passed as constructor parameters. Also refactor the integration tests to be more flat and consice.
@simondel I've refactored the code to remove the |
Merged 🎉 |
This feature adds the ability to log to a "stryker.log" file using a separate log level.
You can configure it like this:
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:
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