nebula-logger-testing-your-code

Installation
SKILL.md

Testing Code That Uses Nebula Logger

This skill is for developers whose own Apex or LWC code calls Logger.info(...), Logger.error(...), etc. and who want to prove in tests that the right things get logged. It only uses global Nebula Logger APIs, so the same techniques work whether the org has the unlocked or the managed package installed.

The Buffer Model

Nebula Logger buffers log entries in memory during a transaction. Logger.saveLog() moves the buffered entries onto the save path (platform event, queueable, REST, or synchronous DML) - see nebula-logger-instrumentation for the save method choice.

For tests, the buffer is the observation point: you can add entries, inspect the buffer size before saveLog(), then either call saveLog() and query the resulting records, or flushBuffer() to drop them without persisting. All three APIs are global.

Assert on the Buffer Before Save

Logger.getBufferSize() returns the number of entries currently buffered. Use it to prove your code added the entries you expected without needing to persist them.

@IsTest
static void it_should_log_a_warning_when_credit_check_fails() {
  Account account = new Account(Name = 'Test Account');
  insert account;
Installs
4
GitHub Stars
953
First Seen
Today
nebula-logger-testing-your-code — jongpie/nebulalogger