Credence.Pattern.NoMissingRequireLogger (credence v0.5.0)

Copy Markdown

Detects Logger macro calls without a require Logger in the enclosing module.

Logger's logging functions (info, debug, warning, error, etc.) are macros, not regular functions. Calling them without require Logger compiles fine but crashes at runtime with UndefinedFunctionError:

** (UndefinedFunctionError) function Logger.info/1 is undefined or private.
   However, there is a macro with the same name and arity.
   Be sure to require Logger if you intend to invoke this macro

LLMs frequently forget the require because Python's logging.info() needs no equivalent setup.

Bad

defmodule MyApp do
  def run do
    Logger.info("starting")
  end
end

Good

defmodule MyApp do
  require Logger

  def run do
    Logger.info("starting")
  end
end

What is flagged

Any defmodule whose body calls a Logger macro (debug, info, notice, warning, warn, error, critical, alert, emergency, log) without a corresponding require Logger, import Logger, or use Logger.

Logger function calls like Logger.configure/1 or Logger.metadata/1 are not flagged — they are regular functions that don't need require.

Auto-fix

Inserts require Logger at the top of the module body, after any existing @moduledoc, use, import, require, or alias directives.

Known limitations

Aliased Logger (alias Logger, as: L then L.info(...)) is not detected.