Skip to content
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

Custom logger #121

Open
melvynhills opened this issue Apr 8, 2024 · 0 comments
Open

Custom logger #121

melvynhills opened this issue Apr 8, 2024 · 0 comments

Comments

@melvynhills
Copy link
Contributor

It would be useful to expose the logger functionality instead of the default console.

Something like:

types.ts

export type InputType = {
  // ...
  enableDebugLogs?: boolean;
  logger?: (message: string) => void;
}

fetch.ts

static init(options: InputType) {
  let config = validateAndNormaliseInputOrThrowError(options);
  
  if (options.enableDebugLogs !== undefined && options.enableDebugLogs) {
      enableLogging(options.logger);
  }

logger.ts

let _logger = console.log;

export function enableLogging(logger?: (message:string) => void) {
    __supertokensWebsiteLogging = true;
  if (logger) {
    _logger = logger
  }
}

export function logDebugMessage(message: string) {
    if (__supertokensWebsiteLogging) {
        _logger(
            `${SUPERTOKENS_DEBUG_NAMESPACE} {t: "${new Date().toISOString()}", message: \"${message}\", supertokens-react-native: "${version}"}`
        );
    }
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant