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

feat: add cmd line option to toggle log levels, get version, get help #557

Open
varunsrin opened this issue Feb 11, 2023 · 3 comments
Open
Labels
t-devex Simplify the developer experience
Milestone

Comments

@varunsrin
Copy link
Member

What is the feature you would like to implement?
A command line option should be added to allow users to toggle between different logging levels, check the version of the app, and print out all available commands.

Why is this feature important?
Will make it easier for users to manage the app in production

Will the protocol spec need to be updated??
No

@varunsrin varunsrin added the t-feat Add a new feature or protocol improvement label Feb 11, 2023
@varunsrin varunsrin added this to the v2.0.0 p3 milestone Feb 11, 2023
@vinliao
Copy link
Contributor

vinliao commented Mar 17, 2023

I've tried doing this by making a log level setting on CLI, tried setting the logger.level inside commander.action(), doesn't work. Tried making a singleton instance like this:

export class Logger {
  private static instance: Pino.Logger;

  private constructor() {}

  public static getInstance(): Pino.Logger {
    if (!Logger.instance) {
      const logLevel = process.env['NODE_ENV'] === 'test' || process.env['CI'] ? 'silent' : 'info';
      Logger.instance = Pino({ level: logLevel });
    }
    return Logger.instance;
  }

  public static setLogLevel(newLogLevel: string): void {
    Logger.instance = Pino({ level: newLogLevel });
  }
}

Doesn't work too. When I console.log() out the level of each logger, seems like they each have their own log level, and setting the level in one place doesn't change loggers in other modules, even though they're imported from the same place. The easiest solution for this issue seems to be setting the log level from the environment variable, then instantiating a logger instance with the wanted log level.

@varunsrin
Copy link
Member Author

@jcliff already had a pr for this here i think, and ran into the same issue: https://github.com/farcasterxyz/hubble/pull/607/files

this is fine for now, and we can merge this pr in, but id like to keep the issue open so that we can investigate if there's a way to do a flag, since setting flags in cloud environments is usually easier than having to set environment variables.

@jcliff
Copy link

jcliff commented Mar 22, 2023

@varunsrin I just rebased the change. Let me know if there's any tweaks needed to pass tests and get merged.

@varunsrin varunsrin modified the milestones: v1.0.20, vNext Apr 3, 2023
@varunsrin varunsrin added t-devex Simplify the developer experience and removed t-feat Add a new feature or protocol improvement labels Apr 10, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
t-devex Simplify the developer experience
Projects
Status: No status
Development

No branches or pull requests

3 participants