Class: Parse::Middleware::Logging

Inherits:
Faraday::Middleware
  • Object
show all
Defined in:
lib/parse/client/logging.rb

Overview

Faraday middleware that logs Parse API requests and responses.

This middleware provides detailed logging of HTTP requests and responses with configurable log levels and optional body truncation for large payloads.

Log levels:

  • :info - Logs request method, URL, status, and timing
  • :debug - Also logs headers and truncated body content
  • :warn - Only logs errors and warnings

Examples:

Basic setup

Parse.logging = true

Detailed configuration

Parse.configure do |config|
  config.logging = true
  config.log_level = :debug
  config.logger = Rails.logger  # or Logger.new(STDOUT)
end

Constant Summary collapse

MAX_BODY_LENGTH =

Maximum length of body content to log before truncation

500

Class Attribute Summary collapse

Class Method Summary collapse

Class Attribute Details

.enabledBoolean

Returns Whether logging is enabled.

Returns:

  • (Boolean)

    Whether logging is enabled



36
37
38
# File 'lib/parse/client/logging.rb', line 36

def enabled
  @enabled
end

.log_levelSymbol

Returns The log level (:info, :debug, :warn).

Returns:

  • (Symbol)

    The log level (:info, :debug, :warn)



39
40
41
# File 'lib/parse/client/logging.rb', line 39

def log_level
  @log_level
end

.loggerLogger

Returns The logger instance to use.

Returns:

  • (Logger)

    The logger instance to use



42
43
44
# File 'lib/parse/client/logging.rb', line 42

def logger
  @logger
end

.max_body_lengthInteger

Returns Maximum body length to log (defaults to MAX_BODY_LENGTH).

Returns:

  • (Integer)

    Maximum body length to log (defaults to MAX_BODY_LENGTH)



45
46
47
# File 'lib/parse/client/logging.rb', line 45

def max_body_length
  @max_body_length
end

Class Method Details

.current_log_levelSymbol

Get the current log level (defaults to :info)

Returns:



68
69
70
# File 'lib/parse/client/logging.rb', line 68

def current_log_level
  log_level || :info
end

.current_loggerLogger

Get the configured logger or default

Returns:

  • (Logger)


62
63
64
# File 'lib/parse/client/logging.rb', line 62

def current_logger
  logger || default_logger
end

.current_max_body_lengthInteger

Get the max body length (defaults to MAX_BODY_LENGTH)

Returns:

  • (Integer)


74
75
76
# File 'lib/parse/client/logging.rb', line 74

def current_max_body_length
  max_body_length || MAX_BODY_LENGTH
end

.default_loggerLogger

Default logger instance

Returns:

  • (Logger)


49
50
51
52
53
54
55
56
57
58
# File 'lib/parse/client/logging.rb', line 49

def default_logger
  @default_logger ||= begin
      l = Logger.new(STDOUT)
      l.progname = "Parse"
      l.formatter = proc do |severity, datetime, progname, msg|
        "[#{progname}] #{msg}\n"
      end
      l
    end
end