fix: replace direct console.* calls with authLogger in auth package#1593
fix: replace direct console.* calls with authLogger in auth package#1593devin-ai-integration[bot] wants to merge 3 commits intomainfrom
Conversation
Original prompt from Guillecan you determine the issue and propose a PR in case it's feasible to maintain the silent logs flag in every part of our sdks? |
🤖 Devin AI EngineerI'll be helping with this pull request! Here's what you should know: ✅ I will automatically:
Note: I can only respond to comments from users who have write access to this repository. ⚙️ Control Options:
|
🦋 Changeset detectedLatest commit: dee1ea4 The changes in this PR will be included in the next version bump. This PR includes changesets to release 8 packages
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
| export function initAuthLogger(apiKey: string): void { | ||
| const validationResult = validateAPIKey(apiKey); | ||
| if (!validationResult.isValid) { | ||
| return; | ||
| } | ||
| const { environment, projectId } = validationResult; | ||
| authLogger.init({ | ||
| packageName: "@crossmint/client-sdk-auth", | ||
| environment, | ||
| projectId, | ||
| }); |
There was a problem hiding this comment.
Consider accepting consoleLogLevel parameter to enable users to suppress console output (similar to initReactLogger). Currently, users cannot configure silent mode for auth logs even though the underlying SdkLogger supports it.
| export function initAuthLogger(apiKey: string): void { | |
| const validationResult = validateAPIKey(apiKey); | |
| if (!validationResult.isValid) { | |
| return; | |
| } | |
| const { environment, projectId } = validationResult; | |
| authLogger.init({ | |
| packageName: "@crossmint/client-sdk-auth", | |
| environment, | |
| projectId, | |
| }); | |
| export function initAuthLogger(apiKey: string, consoleLogLevel?: ConsoleLogLevel): void { | |
| const validationResult = validateAPIKey(apiKey); | |
| if (!validationResult.isValid) { | |
| return; | |
| } | |
| const { environment, projectId } = validationResult; | |
| authLogger.init({ | |
| packageName: "@crossmint/client-sdk-auth", | |
| environment, | |
| projectId, | |
| consoleLogLevel, | |
| }); |
Note: If this suggestion doesn't match your team's coding style, reply to this and let me know. I'll remember it for next time!
Prompt To Fix With AI
This is a comment left during a code review.
Path: packages/client/auth/src/logger.ts
Line: 11-21
Comment:
Consider accepting `consoleLogLevel` parameter to enable users to suppress console output (similar to `initReactLogger`). Currently, users cannot configure silent mode for auth logs even though the underlying `SdkLogger` supports it.
```suggestion
export function initAuthLogger(apiKey: string, consoleLogLevel?: ConsoleLogLevel): void {
const validationResult = validateAPIKey(apiKey);
if (!validationResult.isValid) {
return;
}
const { environment, projectId } = validationResult;
authLogger.init({
packageName: "@crossmint/client-sdk-auth",
environment,
projectId,
consoleLogLevel,
});
```
<sub>Note: If this suggestion doesn't match your team's coding style, reply to this and let me know. I'll remember it for next time!</sub>
How can I resolve this? If you propose a fix, please make it concise.| authLogger.init({ | ||
| packageName: "@crossmint/client-sdk-auth", | ||
| environment, | ||
| projectId, | ||
| }); |
There was a problem hiding this comment.
consoleLogLevel is not being passed to authLogger.init(), which means users cannot suppress auth logs even when setting consoleLogLevel="silent". The logger will always use the default "debug" level for console output.
| authLogger.init({ | |
| packageName: "@crossmint/client-sdk-auth", | |
| environment, | |
| projectId, | |
| }); | |
| authLogger.init({ | |
| packageName: "@crossmint/client-sdk-auth", | |
| environment, | |
| projectId, | |
| consoleLogLevel, | |
| }); |
Prompt To Fix With AI
This is a comment left during a code review.
Path: packages/client/auth/src/logger.ts
Line: 17-21
Comment:
`consoleLogLevel` is not being passed to `authLogger.init()`, which means users cannot suppress auth logs even when setting `consoleLogLevel="silent"`. The logger will always use the default "debug" level for console output.
```suggestion
authLogger.init({
packageName: "@crossmint/client-sdk-auth",
environment,
projectId,
consoleLogLevel,
});
```
How can I resolve this? If you propose a fix, please make it concise.|
|
||
| export const authLogger = new SdkLogger(); | ||
|
|
||
| export function initAuthLogger(apiKey: string): void { |
There was a problem hiding this comment.
initAuthLogger() needs to accept a consoleLogLevel parameter (similar to initReactLogger() in packages/client/react-base/src/logger/init.ts:19) so users can control console output verbosity.
| export function initAuthLogger(apiKey: string): void { | |
| export function initAuthLogger(apiKey: string, consoleLogLevel?: ConsoleLogLevel): void { |
Prompt To Fix With AI
This is a comment left during a code review.
Path: packages/client/auth/src/logger.ts
Line: 11
Comment:
`initAuthLogger()` needs to accept a `consoleLogLevel` parameter (similar to `initReactLogger()` in packages/client/react-base/src/logger/init.ts:19) so users can control console output verbosity.
```suggestion
export function initAuthLogger(apiKey: string, consoleLogLevel?: ConsoleLogLevel): void {
```
How can I resolve this? If you propose a fix, please make it concise.| } | ||
|
|
||
| public static from(crossmint: Crossmint, config: CrossmintAuthClientConfig = {}): CrossmintAuthClient { | ||
| initAuthLogger(crossmint.apiKey); |
There was a problem hiding this comment.
consoleLogLevel needs to be passed to initAuthLogger(). First, add consoleLogLevel to CrossmintAuthClientConfig type (similar to how CrossmintProviderProps extends CrossmintConfig in packages/client/ui/react-ui/src/providers/CrossmintProvider.tsx:12), then pass it here.
| initAuthLogger(crossmint.apiKey); | |
| initAuthLogger(crossmint.apiKey, config.consoleLogLevel); |
Prompt To Fix With AI
This is a comment left during a code review.
Path: packages/client/auth/src/CrossmintAuthClient.ts
Line: 43
Comment:
`consoleLogLevel` needs to be passed to `initAuthLogger()`. First, add `consoleLogLevel` to `CrossmintAuthClientConfig` type (similar to how `CrossmintProviderProps` extends `CrossmintConfig` in packages/client/ui/react-ui/src/providers/CrossmintProvider.tsx:12), then pass it here.
```suggestion
initAuthLogger(crossmint.apiKey, config.consoleLogLevel);
```
How can I resolve this? If you propose a fix, please make it concise.| import { | ||
| SdkLogger, | ||
| validateAPIKey, | ||
| detectPlatform, | ||
| BrowserDatadogSink, | ||
| ServerDatadogSink, | ||
| } from "@crossmint/common-sdk-base"; |
There was a problem hiding this comment.
Missing ConsoleLogLevel import needed for the function signature.
| import { | |
| SdkLogger, | |
| validateAPIKey, | |
| detectPlatform, | |
| BrowserDatadogSink, | |
| ServerDatadogSink, | |
| } from "@crossmint/common-sdk-base"; | |
| import { | |
| SdkLogger, | |
| validateAPIKey, | |
| detectPlatform, | |
| BrowserDatadogSink, | |
| ServerDatadogSink, | |
| type ConsoleLogLevel, | |
| } from "@crossmint/common-sdk-base"; |
Prompt To Fix With AI
This is a comment left during a code review.
Path: packages/client/auth/src/logger.ts
Line: 1-7
Comment:
Missing `ConsoleLogLevel` import needed for the function signature.
```suggestion
import {
SdkLogger,
validateAPIKey,
detectPlatform,
BrowserDatadogSink,
ServerDatadogSink,
type ConsoleLogLevel,
} from "@crossmint/common-sdk-base";
```
How can I resolve this? If you propose a fix, please make it concise.
Description
Part of the effort to make
consoleLogLevel="silent"suppress logs across all SDK packages. Replaces 4 directconsole.*calls inCrossmintAuthClientwith a new package-levelauthLoggerinstance, properly initialized viainitAuthLogger(apiKey).Changes:
src/logger.ts— createsauthLoggersingleton andinitAuthLogger(apiKey)initializer (validates API key, inits logger with package name/environment/projectId, adds platform-appropriate Datadog sink)CrossmintAuthClient.from()— callsinitAuthLogger(crossmint.apiKey)before constructing the clientCrossmintAuthClient.ts— 4 directconsole.*calls →authLogger.debug/authLogger.errorCrossmintAuthClient.test.ts— updated to spy onauthLogger.errorinstead ofconsole.errorNote:
initAuthLoggeruses optional chaining (validationResult?.isValid) as a defensive guard — when tests mock@crossmint/common-sdk-base,validateAPIKeyreturnsundefined, so this preventsTypeErrorwithout requiring test changes.Requested by: @xmint-guille
Link to Devin run
Items for reviewer attention
consoleLogLevelparameter oninitAuthLogger— unlikeinitReactLogger, this init function doesn't accept aconsoleLogLevelparam. TheSdkLoggersharedsinkManagershould propagate the level set byCrossmintProvider, but worth verifying.initAuthLoggeris called on everyCrossmintAuthClient.from()invocation. VerifySdkLogger.init()handles repeated calls gracefully.Test plan
authLogger.errorinstead ofconsole.errorCrossmintAuthClient.test.tspass locally after the defensive optional chaining fixpnpm lint)Package updates
@crossmint/client-sdk-auth: patch (changeset added)