Skip to content

Anonymous Logs Use Field Default Instead of Org-Level Logger Settings for Retention Date #1002

Description

@jonoddkol

Package Edition of Nebula Logger

Unlocked Package

Package Version of Nebula Logger

4.18.2

New Bug Summary

Summary

When Log__c records are created without a LoggedBy__c value (anonymous/null context), the LogRetentionDate__c field defaults to the metadata field default value (14 days) instead of falling back to the org-level LoggerSettings__c.DefaultNumberOfDaysToRetainLogs__c setting.

We experience this issue as we generate logs by creating platform events (LogEntryEvent__e) from Mulesoft. In this scenario, the LoggedBy__c field ends up as null.

Impact

This causes anonymous logs to be purged prematurely based on the hard-coded field default rather than respecting the organization's configured retention policy.

Steps to Reproduce

  1. Configure org-level Logger Settings with DefaultNumberOfDaysToRetainLogs__c = 60
  2. Create a Log__c record through platform events (LogEntryEvent__e), or other method ensuring that LoggedBy__c on create is null
  3. Observe the resulting Log__c.LogRetentionDate__c value

Expected Behavior

Anonymous logs should respect the org-level Logger Settings hierarchy:

  • Expected: LogRetentionDate__c = CreatedDate + 60 days (org setting)
  • Settings hierarchy should be: User → Profile → Org → Field Default

Actual Behavior

Anonymous logs skip the entire Logger Settings hierarchy:

  • Actual: LogRetentionDate__c = CreatedDate + 14 days (field default)
  • Settings hierarchy becomes: Field Default only

Root Cause Analysis

Code Analysis

In LogHandler.cls (lines 159-207), the setLogRetentionDetails() method:

  1. Calls getLoggingUserSettings(log) to retrieve settings
  2. This method requires log.LoggedBy__c to traverse the hierarchy
  3. When LoggedBy__c is null, the method cannot access User, Profile, or Org settings
  4. Falls back to field default defined in metadata (14 days)

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type: BugSomething isn't working

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions