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

JSON logger without prcess context #3317

Open
derXear opened this issue Jan 15, 2025 · 0 comments
Open

JSON logger without prcess context #3317

derXear opened this issue Jan 15, 2025 · 0 comments

Comments

@derXear
Copy link

derXear commented Jan 15, 2025

I want to log in JSON format to make it machine readable and work with log shipper. When implementing a custom logger like this:

export class VendureLoggerImpl implements VendureLogger {
  private logger;

  constructor({ level }: { level: string }) {
    this.logger = pino({
      formatters: {
        level: (label) => {
          return { level: label.toUpperCase() };
        },
      },
      level: level ?? 'info',
      customLevels: {
        verbose: 10,
      },
      messageKey: 'message',
      timestamp: () => {
        return ', "@timestamp":"' + new Date(Date.now()).toISOString() + '"';
      },
    });
  }

  error(message: string, context?: string, trace?: string): void {
    this.logger.error({ message, context, trace });
  }

  warn(message: string, context?: string): void {
    this.logger.warn({ message, context });
  }

  info(message: string, context?: string): void {
    this.logger.info({ message, context });
  }

  verbose(message: string, context?: string): void {
    this.logger.verbose({ message, context });
  }

  debug(message: string, context?: string): void {
    this.logger.debug({ message, context });
  }

  setDefaultContext(defaultContext: string): void {
    this.logger = this.logger.child({ context: defaultContext });
  }
}

It will resolve to an output like this

[worker] {"level":"INFO", "@timestamp":"2025-01-15T06:26:31.874Z","pid":20142,"hostname":"local","context":"Vendure Worker","message":"Bootstrapping Vendure Worker (pid: 20142)..."}

Is there a way to get rid of the prefixed process context [worker] I don't see yet? It's crucial to have the final log entry as plain JSON for our log shipper to work with.

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