Chronicle.Classifier (chronicle v0.1.0)

Copy Markdown

Built-in result-to-audit-outcome classifiers.

:default is used when a call does not set :classify. It records a failure when the callback returned :error or {:error, reason} and a success otherwise, so an audited operation is never recorded as successful merely because it did not raise.

Classifier:ok / {:ok, _}:error / {:error, _}anything else
:defaultsuccessfailuresuccess
:result_tuplesuccessfailureunknown
:booleantrue successfalse failureunknown
:http_statusstatus < 400status >= 400unknown
:always_successsuccesssuccesssuccess

A custom classifier is a one-argument function returning :success, :failure, :unknown, or a non-empty outcome string.

:unknown is a real outcome rather than a gap to be filled in. A classifier that cannot tell what happened has two dishonest options and one honest one: recording success hides failures, recording failure invents them, and saying so leaves a record an investigator can act on. The stricter classifiers return it freely for that reason.

Summary

Types

classifier()

@type classifier() ::
  :default
  | :always_success
  | :result_tuple
  | :boolean
  | :http_status
  | (term() -> Chronicle.Event.outcome())

Functions

classify(status, classifier)

@spec classify(term(), classifier() | nil) :: Chronicle.Event.outcome()