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



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

def enabled
  @enabled
end

.log_levelSymbol

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

Returns:

  • (Symbol)

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



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

def log_level
  @log_level
end

.loggerLogger

Returns The logger instance to use.

Returns:

  • (Logger)

    The logger instance to use



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

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)



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

def max_body_length
  @max_body_length
end

Class Method Details

.current_log_levelSymbol

Get the current log level (defaults to :info)

Returns:



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

def current_log_level
  log_level || :info
end

.current_loggerLogger

Get the configured logger or default

Returns:

  • (Logger)


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

def current_logger
  logger || default_logger
end

.current_max_body_lengthInteger

Get the max body length (defaults to MAX_BODY_LENGTH)

Returns:

  • (Integer)


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

def current_max_body_length
  max_body_length || MAX_BODY_LENGTH
end

.default_loggerLogger

Default logger instance

Returns:

  • (Logger)


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

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