any_logger 0.1.3 → 0.1.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 334a3aebbaebdfacb7515933cd3bacb1a75e8e06ef8c97610a45bba6456eb84e
4
- data.tar.gz: 163ecc53aeca64261a1fb85fc5c43d6056866c66d187b9dadd3f1e928e75304b
3
+ metadata.gz: de56cdda136e683ae52ee87f6a0cb802792f1e3aa1c6e946ade58b6dde832664
4
+ data.tar.gz: 9760f9c169b6d1f721e353d2a995b3da7ed07218cfd3f9d7ff1d7f7bd58417cf
5
5
  SHA512:
6
- metadata.gz: 809c03c57003c27026ad6b948f51928bfead45fbfe1d61a7207a587cd0276a7feefd940c4852440703d0bb6ea02eb45af9ce00e0cf89f7c1c5c90fff87918596
7
- data.tar.gz: 250cf71e5950b04ac2421d24830d58a4e6ef5df12d7138c0d5eb29295db40b2f83396aa1ca50c50d28861f4439670972aba00665712fcbb0f7c1fecc0bc67218
6
+ metadata.gz: c3f6346e9da6a573bddc918a41195a7827c9d34086c3ab1a5b47290017615ef1c5d182968ee06a94d8eab2b31d672533cf7166fb7109849d327a7e39e5455dfb
7
+ data.tar.gz: de5672b026af7fbf51619d947e72ca52495781fc39397c559b10ca467227fb3811e61555eac684310b219e1628007dea3220f19ae0f5571e44cfeb46266723b6
data/.rubocop.yml CHANGED
@@ -27,3 +27,9 @@ Style/RegexpLiteral:
27
27
 
28
28
  Bundler/OrderedGems:
29
29
  Enabled: false
30
+
31
+ Metrics/AbcSize:
32
+ Enabled: false
33
+
34
+ Metrics/MethodLength:
35
+ Enabled: false
data/CHANGELOG.md CHANGED
@@ -11,3 +11,7 @@
11
11
  ## [0.1.3] - 2025-01-15
12
12
 
13
13
  - AnyLogger.startをデフォルトで不要に変更
14
+
15
+ ## [0.1.4] - 2025-01-15
16
+
17
+ - Example::ControllerSubscriberのログの改行位置がおかしかったのを修正
data/README.md CHANGED
@@ -5,7 +5,7 @@ A DSL for simplifying modification of Rails LogSubscribers
5
5
  ### Example
6
6
 
7
7
  ```ruby
8
- # initializer/any_logger.rb
8
+ # initializers/any_logger.rb
9
9
  require "any_logger"
10
10
  require "any_logger/example/controller_subscriber"
11
11
 
@@ -28,65 +28,44 @@ module AnyLogger
28
28
  # params: {"foo" => "bar"}
29
29
  # redirect: "/fuga"
30
30
  private def formatted_message
31
- <<~MESSAGE
32
-
33
- #{l_method} #{l_action} #{l_for} #{l_at}
34
- #{l_path}
35
- #{l_status} #{l_duration} (#{l_view_runtime} | #{l_db_runtime})
36
- #{"#{l_params}\n" if @payload[:params].present?}#{l_redirect if @headers[:location].present?}
37
- MESSAGE
31
+ e = formatted_log_details
32
+ # ヒアドキュメントだとparamsとredirectの有無で改行の入り方が変わってしまうので、配列を結合する方法を採用
33
+ lines = []
34
+ lines << ""
35
+ lines << "[#{e[:method]}] #{e[:controller]}##{e[:action]} for: #{e[:ip]} at: #{e[:datetime]}"
36
+ lines << " 🔍 path: \"#{e[:path]}\""
37
+ lines << " 🧱 status: #{e[:status]} in #{e[:duration]}ms " \
38
+ "(view: #{e[:view_runtime]}ms | db: #{e[:db_runtime]}ms)"
39
+ lines << " 📝 params: #{e[:params]}" if @payload[:params].present?
40
+ lines << " 🚀 redirect: \"#{e[:redirect_to]}\"" if @headers[:location].present?
41
+ lines.join("\n")
38
42
  end
39
43
 
40
44
  private def match_unnecessary_path?
41
45
  UNNECESSARY_PATHS.include?(@payload[:path])
42
46
  end
43
47
 
44
- private def l_method
45
- "[#{@payload[:method].upcase}]"
46
- end
47
-
48
- private def l_action
49
- "#{@payload[:controller]}##{@payload[:action]}"
50
- end
51
-
52
- private def l_for
53
- "for: #{@payload[:request].remote_ip}"
54
- end
55
-
56
- private def l_at
57
- "at: #{conversion_event_time_to_datetime}"
58
- end
59
-
60
- private def l_path
61
- "🔍 path: \"#{@payload[:path]}\""
62
- end
63
-
64
- private def l_status
65
- "🧱 status: #{@payload[:status]}"
66
- end
67
-
68
- private def l_duration
69
- "in #{@event.duration&.round(2) || 0}ms"
70
- end
71
-
72
- private def l_view_runtime
73
- "view: #{@payload[:view_runtime]&.round(2) || 0}ms"
74
- end
75
-
76
- private def l_db_runtime
77
- "db: #{@payload[:db_runtime]&.round(2) || 0}ms"
78
- end
79
-
80
- private def l_params
81
- @payload[:params] = except_unnecessary_params
82
- "📝 params: #{@payload[:params]&.inspect || {}}"
83
- end
84
-
85
- private def l_redirect
48
+ private def formatted_log_details
49
+ {
50
+ method: @payload[:method].upcase,
51
+ controller: @payload[:controller],
52
+ action: @payload[:action],
53
+ ip: @payload[:request].remote_ip,
54
+ datetime: conversion_event_time_to_datetime,
55
+ path: @payload[:path],
56
+ status: @payload[:status],
57
+ duration: round_value(@event.duration),
58
+ view_runtime: round_value(@payload[:view_runtime]),
59
+ db_runtime: round_value(@payload[:db_runtime]),
60
+ params: expect_unnecessary_params || {},
61
+ redirect_to: formatted_redirect_location
62
+ }
63
+ end
64
+
65
+ private def formatted_redirect_location
86
66
  return unless REDIRECT_CODES.any? { @payload[:status] == Rack::Utils.status_code(it) }
87
67
 
88
- ellipsised_url = ellipsis_scheme_and_authority(@headers[:location])
89
- "🚀 redirect: \"#{ellipsised_url}\""
68
+ ellipsis_scheme_and_authority(@headers[:location])
90
69
  end
91
70
 
92
71
  private def conversion_event_time_to_datetime
@@ -97,6 +76,10 @@ module AnyLogger
97
76
  Time.at((now - elapsed).to_i)
98
77
  end
99
78
 
79
+ private def round_value(value)
80
+ value&.round(2) || 0
81
+ end
82
+
100
83
  private def except_unnecessary_params
101
84
  @payload[:params].except("controller", "action")
102
85
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module AnyLogger
4
- VERSION = "0.1.3"
4
+ VERSION = "0.1.4"
5
5
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: any_logger
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.3
4
+ version: 0.1.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - milkeclair