question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

How to update default config in production environment at run time

See original GitHub issue

Related issue #7 answers how to change the logging config at compile-time (using environment), but I wish to know how to change the global config at run-time.

The logger.updateConfig(config) method only changes them for the current instance.

I am trying to perform this update in an APP_INITIALIZER of the Angular bootstrap, but it grabs a new copy of the config provided in forRoot(config). I wondering if the service could have another way to update the default config which is always provided to the service when initialized:

    // each instance of the logger should have their own config engine
    this.configService = new NgxLoggerConfigEngine(loggerConfig);

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Reactions:3
  • Comments:9 (5 by maintainers)

github_iconTop GitHub Comments

1reaction
bmtheocommented, Jan 24, 2020

@dbfannin this would also be useful in our app

The user story is a bit different : We need to change the logLevel at runtime (by default in PROD mode it’s set to ERROR) but if we need to investigate on an issue, we’d like to modify that logLevel to DEBUG or TRACE for example.

So the updateConfig should update all “living” instances of NGXLogger AND the future instances.

Are you open to PR for this ? and if so I was thinking of doing something like this :

export class NGXLogger implements OnDestroy {
  private static readonly _sharedConfig: Subject<LoggerConfig> = new Subject<LoggerConfig>();
  /** Returns an observable when the sharedConfig is changed */
  public sharedConfigChanged(): Observable<LoggerConfig> {
    return NGXLogger._sharedConfig.asObservable();
  }

  /** Updates the config for all the instances of NGXLogger */
  public updateSharedConfig(config: LoggerConfig) {
    NGXLogger._sharedConfig.next(config);
  }

...

  // each instance of the logger should have their own config engine
  this.config = new NGXLoggerConfigEngine(loggerConfig, this.sharedConfigChanged());
1reaction
bradoylercommented, May 10, 2019

So one workaround might be to read the logLevel from localStorage and then you can update the value in the browser console at runtime. This is how the nodejs debug module works.

example app.module.ts

....
const localLogLevel = localStorage.getItem('logLevel');
const defaultLogLevel = NgxLoggerLevel.INFO;
const logLevel = localLogLevel ? NgxLoggerLevel[localLogLevel] || defaultLogLevel : defaultLogLevel;
....
imports: [
  LoggerModule.forRoot({ level: logLevel })
]
Read more comments on GitHub >

github_iconTop Results From Across the Web

Production Configuration - 2.8.x - Play Framework
conf overrides the default settings in the various reference.conf files. You can override runtime configuration in several ways. This can be handy when...
Read more >
Use multiple environments in ASP.NET Core | Microsoft Learn
Select the app from the App Services page. · In the Settings group, select Configuration. · In the Application settings tab, select New ......
Read more >
Should default configuration for deployed services be set as ...
For those options, your default should be to set the production settings. These options are things like sidestepping caches, or enabling debug ...
Read more >
changing or updating app.config at runtime in wpf projects
I have four config files for DEV, TEST, UAT, PROD. Based on user selection I need to overwrite the default config file completely...
Read more >
How to Configure .Net Core, ASP.NET Environments With ...
Therefore, it is crucial to check and update your environment configuration ... Now, how can we retrieve the configuration value at runtime?
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found