module Logbuch::Tracing

Overview

Traces the methods of the including class, struct or module that carry @[Logged]. logbuch includes it in every type with such a method, except a private type or one inside a private type, which includes it, or Logbuch::Annotations, itself; the build fails until it does.

A private top-level module, the modules inside it, and a type defined in the program's own macro finished must include it themselves too, but the build does not fail without it: logbuch cannot see them, so their methods are not traced until they do. An enum cannot include a module, so @[Logged] on a method of an enum fails the build.

Each traced method gets a wrapper with the same signature that logs entry, calls the original method with previous_def, and logs exit or exception. Subclasses of an including class are traced too. A module's traced methods are wrapped in the module, so they are traced wherever they are called: through any class that includes the module, or on the module itself.

A wrapper belongs to the type that defines the method, so an inherited method logs with that type's label and log: with class Plain < Base, Plain.new.foo logs Base#foo under base, whatever Log or @[LogType(log: …)] Plain has. An override with its own @[Logged] that calls super logs the call as Plain#foo instead.

Defined in:

logbuch/tracing.cr