How to Test a Web Product When Logging Fails
Successfully saving a note does not mean the corresponding event reached the log. And an error in the logging handler should not automatically turn a successful operation into a failed one. Testing both sides requires a specific contract: what happens to the data, what result the user receives and how the team detects the failure. We will use an entirely fictional web product with synthetic notes we own and a controllable test handler.
Define the contract for one operation
In our fictional product, a user saves a note. For this example, we adopt a design requirement: logging is a supporting dependency, so failure to record an event does not undo the save. The expected outcome is that the note is saved, the user receives a consistent confirmation and no unhandled handler exception escapes the operation boundary. The logging problem must also be detectable separately.
This follows OWASP's recommendation that logging failures should not disrupt the rest of the application or disclose information. However, this contract cannot automatically be applied to mandatory business auditing. If recording an event is a condition for completing the operation, a separate design decision is required. OWASP notes that audit, transaction and security event logs may serve different purposes.
Identify the boundary to test
The test boundary lies between saving the note and calling the event logging handler. OWASP recommends implementing the logging handler as a standard module where possible so it can be thoroughly tested. In our example, we use a test implementation with two modes: normal recording to a test sink and a controlled exception before recording.
All subsequent steps are defensive tests devised for this article, not an official OWASP procedure. Run them in your own test environment using synthetic data you own. This scenario does not require filling a disk or taking shared infrastructure offline: the controllable handler lets you test a specific dependency failure without those actions.
Confirm normal behavior first
Create a synthetic note with a unique identifier and enable the handler's working mode. Save the note, then read it separately from storage using your test environment's tools. Compare its identifier and content with the submitted data. Check the result shown to the user and find the corresponding event in the test sink.
The positive control requires three observations: the data is actually saved, the result reports success and the expected event is recorded. A successful HTTP response alone is insufficient. If this control fails, fix the normal path first; otherwise, the subsequent comparison with the failure scenario will be ambiguous.
Reproduce the recording failure
Switch the handler to the mode that throws an exception before recording and save a different synthetic note. The test must confirm that the handler was actually called and that the configured failure occurred. Then repeat the checks of the stored data and the result shown to the user. The event for this operation must be absent from the test sink, and no unhandled exception should escape the operation boundary.
For our contract, the test passes only when all conditions hold: the new note is saved with the expected content, the user sees success, the event is not recorded because of the configured failure and the exception is handled. If the response indicates success but the note is missing, the contract is violated. If the note is saved but the user receives a failure because of the supporting handler, the contract is also violated.
Check detection and prevent disclosure of details
OWASP recommends providing a way to detect when logging stops. In this fictional test, we use a separate failure counter that is accessible to the test observer and does not use the faulty handler. Record its value before each scenario: normal recording must not increase the counter, while the controlled failure must produce the expected increase. Separately check that generating the signal does not trigger another logging attempt through the same handler.
Include a unique synthetic diagnostic marker in the controlled exception. Check that neither the marker nor the stack trace appears in the result shown to the user. Unhandled errors can disclose technical information; OWASP recommends withholding details of unexpected errors from users. Here, we are specifically checking for disclosure during a dependency failure, without designing a new API error format.
Fix violations and check recovery
First, prevent the handler's exception from escaping the operation boundary and stop diagnostic details from being disclosed. For the chosen contract, handle this failure so that saving the note produces a consistent result. Then provide an independent signal: continuing to operate without detecting the problem does not fulfill the entire contract. After making changes, repeat the normal and failure scenarios using the same criteria.
Return the handler to working mode and save a third synthetic note. Confirm its content, the successful result and the appearance of a new event. This checks that recording has resumed. It does not establish that the previously missed event has been recovered: redelivery requires a separate contract and a separate test.
Document the result and the limits of the test
The outcome is a contract for one operation with observable criteria: the note's state, the result shown to the user, the presence or absence of the event, exception handling and an independent failure signal. It shows behavior under the selected handler error, but does not cover every network or storage failure and provides no statistical guarantee of security. Assess mandatory business audit requirements separately.
To test a scenario like this in your product, start with a free website or web-product audit from CheckMyApp. For the discussion, prepare a description of one operation, the role of its log and the expected behavior when recording fails. This will help define a testable contract.