Phoenix.SessionProcess.Logger (phoenix_session_process v1.0.1)

Copy Markdown View Source

Default telemetry event logger for Phoenix.SessionProcess.

This module provides handlers that can be attached to telemetry events to replicate the original Logger behavior while maintaining the benefits of telemetry-based observability.

Usage

Attach the default logger to capture all session process events:

Phoenix.SessionProcess.Logger.attach_default_logger()

You can also attach individual event handlers:

Phoenix.SessionProcess.Logger.attach_worker_events()
Phoenix.SessionProcess.Logger.attach_session_events()
Phoenix.SessionProcess.Logger.attach_cleanup_events()

Event Filtering

You can filter events by log level:

# Only log errors and warnings
Phoenix.SessionProcess.Logger.attach_default_logger(level: :warning)

# Only log session lifecycle events
Phoenix.SessionProcess.Logger.attach_session_events(level: :info)

Custom Handlers

For custom logging behavior, you can attach your own handlers:

:telemetry.attach_many("custom-logger", [
  [:phoenix, :session_process, :start],
  [:phoenix, :session_process, :stop]
], &MyApp.SessionLogger.handle_event/4, nil)

Summary

Functions

Attaches handlers for cleanup events.

Attaches handlers for communication events.

Attaches handlers for all Phoenix.SessionProcess telemetry events.

Attaches handlers for session lifecycle events.

Attaches handlers for worker process events.

Detaches all telemetry logger handlers.

Types

level()

@type level() :: :debug | :info | :warning | :error

Functions

attach_cleanup_events(opts \\ [])

@spec attach_cleanup_events(keyword()) :: :ok

Attaches handlers for cleanup events.

attach_communication_events(opts \\ [])

@spec attach_communication_events(keyword()) :: :ok

Attaches handlers for communication events.

attach_default_logger(opts \\ [])

@spec attach_default_logger(keyword()) :: :ok

Attaches handlers for all Phoenix.SessionProcess telemetry events.

attach_session_events(opts \\ [])

@spec attach_session_events(keyword()) :: :ok

Attaches handlers for session lifecycle events.

attach_worker_events(opts \\ [])

@spec attach_worker_events(keyword()) :: :ok

Attaches handlers for worker process events.

detach_all_loggers()

@spec detach_all_loggers() :: :ok

Detaches all telemetry logger handlers.