-
Notifications
You must be signed in to change notification settings - Fork 10.4k
Fix #8974 by supporting strings in configureLogging for SignalR JS client #9252
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
Conversation
src/SignalR/clients/ts/signalr/tests/HubConnectionBuilder.test.ts
Outdated
Show resolved
Hide resolved
🆙 📅 |
Update to fix build. |
@@ -13,6 +13,31 @@ import { JsonHubProtocol } from "./JsonHubProtocol"; | |||
import { NullLogger } from "./Loggers"; | |||
import { Arg, ConsoleLogger } from "./Utils"; | |||
|
|||
// tslint:disable:object-literal-sort-keys | |||
const LogLevelNameMapping = { |
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.
Does this need to be exported now that it's included in the public configureLogging type signature?
It might be better to change configureLogging to take a keyof typeof LogLevel
instead of keyof typeof LogLevelNameMapping
. You can still use the LogLevelNameMapping and call toLowerCase on the argument.
As an upside, hat would be make things more consistent with the capitalization of our HubConnectionStates.
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.
keyof typeof LogLevel
doesn't work since we want to allow "warn" and "info". I say don't export anything new, and change the configureLogging type signature to take a string.
We could link to the "Configure logging" section of docs from the configureLogging doc comment if the want to see what string are valid. If you want type safety, you can still use the Loglevel overload.
Co-Authored-By: anurse <[email protected]>
Feedback applied! |
@@ -146,27 +146,35 @@ export class SubjectSubscription<T> implements ISubscription<T> { | |||
/** @private */ | |||
export class ConsoleLogger implements ILogger { | |||
private readonly minimumLogLevel: LogLevel; | |||
// Public for testing purposes. |
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 comment was indented with a tab.
YARN : error : F:/workspace/_work/1/s/src/SignalR/clients/ts/signalr/src/Utils.ts[149, 1]: space indentation expected [F:\workspace\_work\1\s\src\SignalR\clients\ts\signalr\signalr.npmproj]
double nit: Add newline above.
@@ -44,15 +69,17 @@ export class HubConnectionBuilder { | |||
|
|||
/** Configures custom logging for the {@link @aspnet/signalr.HubConnection}. | |||
* | |||
* @param {LogLevel | ILogger} logging An object implementing the {@link @aspnet/signalr.ILogger} interface or {@link @aspnet/signalr.LogLevel}. | |||
* @param {LogLevel | string | ILogger} logging A {@link @aspnet/signalr.LogLevel}, a string representing a LogLevel, or an object implementing the {@link @aspnet/signalr.ILogger} interface. See {@link https://docs.microsoft.com/en-us/aspnet/core/signalr/configuration#configure-logging|the documentation for client logging configuration} for more details. |
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.
YARN : error : F:/workspace/_work/1/s/src/SignalR/clients/ts/signalr/src/HubConnectionBuilder.ts[72, 1]: Exceeds maximum line length of 300 [F:\workspace\_work\1\s\src\SignalR\clients\ts\signalr\signalr.npmproj]
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.
LGTM. Just some tslint cleanup left.
:'(. I'll look at that on Monday |
if (typeof mapping !== "undefined") { | ||
return mapping; | ||
} else { | ||
throw new Error(`Unknown log level: ${name}`); |
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.
Nit: Do we want to preserve the casing on the user input 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.
This does preserve that casing. I think that's the appropriate behavior here, since it's echoing what the user put in.
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.
Test Failure. It looks like configureLogging
is trying to define one of the string log level args as an ILogger which causes the test to fail.
FAIL signalr/tests/HubConnectionBuilder.test.ts
ΓùÅ Test suite failed to run
signalr\tests\HubConnectionBuilder.test.ts (203,39): Argument of type '"trace" | "debug" | "info" | "information" | "warn" | "warning" | "error" | "critical" | "none"' is not assignable to parameter of type 'ILogger'.
Type '"trace"' is not assignable to type 'ILogger'.
at Object.runTsDiagnostics (common/node_modules/ts-jest/src/utils.ts:227:11)
at process (common/node_modules/ts-jest/src/preprocessor.ts:47:5)
at Object.process (common/node_modules/ts-jest/index.js:8:51)
at ScriptTransformer.transformSource (common/node_modules/@jest/transform/build/ScriptTransformer.js:387:35)
at ScriptTransformer._transformAndBuildScript (common/node_modules/@jest/transform/build/ScriptTransformer.js:457:40)
at ScriptTransformer.transform (common/node_modules/@jest/transform/build/ScriptTransformer.js:513:25)
const mappedName = LogLevel[mapped]; | ||
it(`accepts "${str}" as an alias for LogLevel.${mappedName}`, async () => { | ||
const builder = new HubConnectionBuilder() | ||
.configureLogging(str); |
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's trying to assign str to an ILogger
instead of a string here
Blocked on @mikaelm12 's change request ;). |
Unblocked now :D |
This is why I don't like using the request changes feature lol |
I only use it when I specifically feel the need to see the result of my feedback before signing off. |
Fixes #8974
This allows users to pass in a string for the log level when calling
configureLogging
. This makes it much easier to configure logging in environments where you don't have access to the enum definition (such as in Blazor when you're just doing this in a script block in your page).Note: I also grouped all the
configureLogging
tests into their owndescribe
because there were now quite a few :).Test output for HubConnectionBuilder.test.ts:
cc @rynowak