Skip to content

Conversation

hitarth-gg
Copy link
Collaborator

@hitarth-gg hitarth-gg commented Aug 25, 2025

Description of Change

  • Added Logger class with logLevel option.
  • Updated devtron.install(options) to configure the logger automatically, allowing users to set a minimum log level. Only logs at the selected level and above will be shown, preventing unwanted Devtron logs from cluttering the terminal.
  • Updated docs with usage example and options table.

Usage:

await devtron.install({ logLevel: 'warn' }); // only logs 'warn' and 'error'

@hitarth-gg hitarth-gg marked this pull request as ready for review August 25, 2025 18:57
Copy link
Member

@erickzhao erickzhao left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

API-wise, I think a logLevel option would make more sense and cover all our bases.

Options would be debug, info, warn, error, or none, where enabling a less important log level would make all higher-priority ones.

It feels more ergonomic that way since you don't usually want to ignore non-contiguous log levels.


```js
await devtron.install({ ignoreLogs: ['debug', 'info'] });
```
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Agreed with @erickzhao about a logLevel option. Then these two examples could be

devtron.install({ logLevel: [] })
devtron.install({ logLevel: ['info', 'warn'] })

I'm partial to the idea of the quiet option as a shorthand though. Open to either keeping it or removing it.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In my head it'd look more like a sliding scale:

devtron.install({ logLevel: 'quiet' }) // or `'none'`
devtron.install({ logLevel: 'error' }) // only shows `error`
devtron.install({ logLevel: 'warn' }) // shows `warn`, or `error`, but not `debug` or `info`
devtron.install({ logLevel: 'info' }) // shows `info`, `warn`, or `error`, but not `debug`

since it'd be unlikely that you would want to specifically ignore non-contiguous log levels (e.g. ignoring error and debug but not info and warn).

@hitarth-gg
Copy link
Collaborator Author

hitarth-gg commented Aug 29, 2025

@erickzhao I made the requested changes and also updated the NPM Package to 0.0.0-development.15 to reflect the commits above.

@dsanders11 dsanders11 changed the title feat: add configurable logger with quiet mode and ignoreLogs support feat: add configurable logLevel to install options Aug 29, 2025
Comment on lines 4 to 10
private readonly logLevelMap: Record<LogLevel, number> = {
debug: 1,
info: 2,
warn: 3,
error: 4,
none: 5,
};
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we could combine this and the LogLevel type in src/types/shared.ts if we just make LogLevel into a numeric enum:

enum LogLevel {
  none,
  debug,
  info,
  warn,
  error
}

Enums without assigned values in TS auto-assign to incrementing number values so you can get > comparisons out of the box without defining a separate map.

See:

Copy link
Collaborator Author

@hitarth-gg hitarth-gg Aug 30, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since we want users to be able to pass log level as a string, like devtron.install({ logLevel: 'warn' }), I'll need to create another type with log level strings as well, right ?

@erickzhao erickzhao self-requested a review August 29, 2025 23:12
@hitarth-gg
Copy link
Collaborator Author

I've added the LogLevel enum. Let me know if it still doesn’t look right!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants