NebulaLogger icon indicating copy to clipboard operation
NebulaLogger copied to clipboard

Disabling system messages in LWC component

Open dominykasvitkus opened this issue 8 months ago • 3 comments

Hello, I want to use NebulaLogger for errors in public site, but I don't want initialization and error messages in browser's console.

On c/logger/loggerService.js file I can see functions to disable messages:

let areSystemMessagesEnabled = true;

export function enableSystemMessages() {
  areSystemMessagesEnabled = true;
}

export function disableSystemMessages() {
  areSystemMessagesEnabled = false;
}

But i'm not sure how to use these as I can only import c/logger and not c/logger/loggerService.js. Is it possible to provide it as a setting when initializing logger in LWC?

dominykasvitkus avatar May 20 '25 10:05 dominykasvitkus

Hi @dominykasvitkus - if you want to prevent the logs from showing up in the browser's console, there's a settings field you can use to control that (LoggerSettings__c.IsJavaScriptConsoleLoggingEnabled__c). For production orgs, I recommend that this is disabled org-wide, but you can also configure at the profile or user levels.

Image

jongpie avatar May 23 '25 15:05 jongpie

Hey, I've already disabled this setting, but looking at the code it doesn't apply to initial message which I refer.

c/logger/loggerService.js:58-66

  constructor() {
    this._loadSettingsFromServer();

    if (areSystemMessagesEnabled && !LoggerService.hasInitialized) {
      this._logToConsole('INFO', 'logger component initialized\n' + JSON.stringify(new BrowserContext(), null, 2));

      LoggerService.hasInitialized = true;
    }
  }

areSystemMessagesEnabled doesn't read settings from what I see (loggerService.js:29-37):

let areSystemMessagesEnabled = true;

export function enableSystemMessages() {
  areSystemMessagesEnabled = true;
}

export function disableSystemMessages() {
  areSystemMessagesEnabled = false;
}

dominykasvitkus avatar May 26 '25 09:05 dominykasvitkus

@dominykasvitkus thanks for the clarification! I see what you're saying about the initial message not checking the settings first. I'm not planning to expose the functions enableSystemMessages() and disableSystemMessages() (I think those were added primarily to help with testing in Jest tests), but I'll see if I can change the behavior so the settings are checked first before printing the initial message.

jongpie avatar May 27 '25 18:05 jongpie

@dominykasvitkus I've just published release v4.16.4 to address this. It will now check LoggerSettings__c.IsJavaScriptConsoleLoggingEnabled__c first, before deciding if it should print the initialization and error messages in the browser's console. You won't have to add anything to your code for this (e.g., you won't need to call disableSystemMessages(), etc.), just upgrading your version of Nebula Logger should fix this in your orgs.

Whenever you have a chance to upgrade & try it, let me know if you come across any more issues with this - or have any other suggestions/feedback!

jongpie avatar Jul 23 '25 23:07 jongpie

Hey, @jongpie. Seems to work as expected now, thank you!

dominykasvitkus avatar Aug 01 '25 10:08 dominykasvitkus

@dominykasvitkus that's great to hear, thanks for the update!

jongpie avatar Aug 01 '25 10:08 jongpie