Module: Axn::Internal::CallLogger
Overview
Logs action execution - handles building and emitting structured log messages for action calls with context formatting and truncation.
Constant Summary collapse
- MAX_CONTEXT_LENGTH =
150- TRUNCATION_SUFFIX =
"…<truncated>…"
Instance Method Summary collapse
-
#log_at_level(action_class, level:, message_parts:, error_context:, join_string: " ", before: nil, after: nil, prefix: nil, context_direction: nil, context_instance: nil, context_data: nil, facets: nil) ⇒ Object
Logs a message at the specified level with error handling.
-
#semantic_logger? ⇒ Boolean
True only when the logger that will actually emit is a SemanticLogger — merely having the gem loaded isn't enough, since its thread-local tagged context is read only by SemanticLogger instances (see design: gating on the configured logger avoids facets vanishing from a line emitted by a plain Logger).
Instance Method Details
#log_at_level(action_class, level:, message_parts:, error_context:, join_string: " ", before: nil, after: nil, prefix: nil, context_direction: nil, context_instance: nil, context_data: nil, facets: nil) ⇒ Object
Logs a message at the specified level with error handling
34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 |
# File 'lib/axn/internal/call_logger.rb', line 34 def log_at_level( # rubocop:disable Metrics/ParameterLists action_class, level:, message_parts:, error_context:, join_string: " ", before: nil, after: nil, prefix: nil, context_direction: nil, context_instance: nil, context_data: nil, facets: nil ) return unless level Axn::Extensions.best_effort(error_context, action: action_class) do # Prepare and format context if needed context_str = if context_instance && context_direction # Instance-level: use private inputs_for_logging / outputs_for_logging data = case context_direction when :inbound then context_instance.send(:inputs_for_logging) when :outbound then context_instance.send(:outputs_for_logging) end format_context(data) elsif context_data && context_direction # Class-level: use internal _context_slice data = action_class._context_slice(data: context_data, direction: context_direction) format_context(data) end # Add context to message parts if present = context_str ? + [context_str] : = .compact.join(join_string) # Annotate with resolved tag/dimension facets: structured named tags when the configured # logger is a SemanticLogger (legible as log fields / Datadog facets), otherwise a readable # suffix on the plain line. Mutually exclusive — semantic_logger's own formatter renders the # named tags, so the suffix would be redundant there. = facets ? Axn::Core::Tagging.namespaced(tags: facets[:tags] || {}, dimensions: facets[:dimensions] || {}) : {} if .any? && semantic_logger? SemanticLogger.tagged(**) do action_class.public_send(level, , before:, after:, prefix:) end else += facet_suffix(facets) if .any? action_class.public_send(level, , before:, after:, prefix:) end end end |
#semantic_logger? ⇒ Boolean
True only when the logger that will actually emit is a SemanticLogger — merely having the gem loaded isn't enough, since its thread-local tagged context is read only by SemanticLogger instances (see design: gating on the configured logger avoids facets vanishing from a line emitted by a plain Logger). Public so the Executor can gate the in-flight body context on it.
90 91 92 |
# File 'lib/axn/internal/call_logger.rb', line 90 def semantic_logger? defined?(SemanticLogger::Logger) && Axn.config.logger.is_a?(SemanticLogger::Logger) end |