-
Notifications
You must be signed in to change notification settings - Fork 8.3k
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
Introduce LegacyAppender
that forwards log records to the legacy platform.
#14354
Introduce LegacyAppender
that forwards log records to the legacy platform.
#14354
Conversation
Hey @kjbekkelund, Here is implementation of the 2nd option I mentioned in the #13412. You can also take a look at the first commit that is what I meant by option 1 :) |
append(record: LogRecord) { | ||
this.kbnServer.server.log( | ||
[record.level.id.toLowerCase(), ...record.context.split('.')], | ||
record.error || record.message, |
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.
note: it seems in the legacy platform we can't provide both message and error :/
@@ -24,6 +25,8 @@ export class MutableLoggerFactory implements LoggerFactory { | |||
private readonly bufferAppender = new BufferAppender(); | |||
private readonly loggers: Map<string, LoggerAdapter> = new Map(); | |||
|
|||
constructor(private readonly env: Env) {} |
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.
Env
is now everywhere :)
7c73347
to
6342f69
Compare
We now |
(I know this isn't too far away from what we're doing, as we're specifying the interface, I'm just trying to make it even stricter — just not sure if it makes sense 🙈) |
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.
Looks like it works as expected. LGTM.
Just that one question re legacyKbnServer
. If you want to we could also do that in a follow-up PR, so I'm good with merging this as-is.
appender.append(record); | ||
} | ||
|
||
expect(legacyLogStub.mock.calls).toMatchSnapshot(); |
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.
Great use of snapshots imo 🎉
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.
Yeah, it works pretty well for cases when arguments are predictable, borrowed the approach from your logger mock's _collect
method :)
Do you mean something like this? export class LegacyKbnServer {
constructor(private readonly rawKbnServer: any) {
}
get newPlatformProxyListener() {
return this.rawKbnServer.newPlatformProxyListener;
}
log(...args: any[]) {
this.rawKbnServer.server.log(...args);
}
}
---------------
export const injectIntoKbnServer = (rawKbnServer: any) => {
const legacyConfig$ = new BehaviorSubject(rawKbnServer.config);
const config$ = legacyConfig$.map(
legacyConfig => new LegacyConfigToRawConfigAdapter(legacyConfig)
);
rawKbnServer.updateNewPlatformConfig = (legacyConfig: LegacyConfig) => {
legacyConfig$.next(legacyConfig);
};
//const LegacyPlatformProxifier =
rawKbnServer.newPlatformProxyListener = new LegacyPlatformProxifier(
new Root(config$, Env.createDefault({ kbnServer: new LegacyKbnServer(rawKbnServer) }))
);
}; |
Yep |
…r` methods under `newPlatform` "namespace".
@kjbekkelund Thanks for review. Would you mind taking a look at the 4th commit with |
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 like it. LGTM.
@@ -0,0 +1,28 @@ | |||
import { LegacyKbnServer } from '..'; | |||
|
|||
it('correctly returns `newPlatformProxyListener`.', () => { |
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.
nitpick: it
-> test
?
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'm not sure here, as I don't know if we are consistent either way, so feel free to skip)
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.
ha-ha, right, it should definitely be test
- I believe we are pretty consistent on this in the new platform code (I see only 3 more tests that use it
and that was me who did that :), so I'll change them to test
too).
LegacyAppender
just forwards all log records it receives to thekbnServer.server.log
so that legacy platform can decide how to format that records and where it should be written to.From the new-platform perspective
LegacyAppender
is set asdefault
appender used by theroot
logger.Fixes #13412.