Skip to content

Custom logger #121

Open
Open
@melvynhills

Description

@melvynhills

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}"}`
        );
    }
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions