logtail-rails 0.1.7 → 0.2.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.github/workflows/main.yml +10 -87
- data/README.md +23 -8
- data/example-project/.gitattributes +7 -0
- data/example-project/.gitignore +35 -0
- data/example-project/Gemfile +74 -0
- data/example-project/README.md +12 -6
- data/example-project/app/assets/config/manifest.js +4 -0
- data/example-project/app/assets/images/.keep +0 -0
- data/example-project/app/controllers/concerns/.keep +0 -0
- data/example-project/{Logtail-rails-main/app → app}/controllers/example_controller.rb +6 -1
- data/example-project/app/javascript/application.js +3 -0
- data/example-project/app/javascript/controllers/application.js +9 -0
- data/example-project/app/javascript/controllers/hello_controller.js +7 -0
- data/example-project/app/javascript/controllers/index.js +11 -0
- data/example-project/app/models/concerns/.keep +0 -0
- data/example-project/bin/bundle +114 -0
- data/example-project/bin/importmap +4 -0
- data/example-project/{Logtail-rails-main/bin → bin}/rails +0 -0
- data/example-project/{Logtail-rails-main/bin → bin}/rake +0 -0
- data/example-project/{Logtail-rails-main/bin → bin}/setup +0 -0
- data/example-project/{Logtail-rails-main/config → config}/application.rb +3 -1
- data/example-project/{Logtail-rails-main/config → config}/cable.yml +3 -2
- data/example-project/config/credentials.yml.enc +1 -0
- data/example-project/{Logtail-rails-main/config → config}/environments/production.rb +1 -1
- data/example-project/config/importmap.rb +7 -0
- data/example-project/{Logtail-rails-main/config → config}/initializers/content_security_policy.rb +4 -5
- data/example-project/db/seeds.rb +7 -0
- data/example-project/lib/assets/.keep +0 -0
- data/example-project/lib/tasks/.keep +0 -0
- data/example-project/log/.keep +0 -0
- data/example-project/public/404.html +67 -0
- data/example-project/public/422.html +67 -0
- data/example-project/public/500.html +66 -0
- data/example-project/public/apple-touch-icon-precomposed.png +0 -0
- data/example-project/public/apple-touch-icon.png +0 -0
- data/example-project/public/favicon.ico +0 -0
- data/example-project/public/robots.txt +1 -0
- data/example-project/storage/.keep +0 -0
- data/example-project/test/controllers/.keep +0 -0
- data/example-project/test/fixtures/files/.keep +0 -0
- data/example-project/test/helpers/.keep +0 -0
- data/example-project/test/integration/.keep +0 -0
- data/example-project/test/mailers/.keep +0 -0
- data/example-project/test/models/.keep +0 -0
- data/example-project/test/system/.keep +0 -0
- data/example-project/tmp/.keep +0 -0
- data/example-project/tmp/pids/.keep +0 -0
- data/example-project/tmp/storage/.keep +0 -0
- data/example-project/vendor/.keep +0 -0
- data/example-project/vendor/javascript/.keep +0 -0
- data/lib/logtail-rails/log_entry.rb +14 -0
- data/lib/logtail-rails/logger.rb +19 -1
- data/lib/logtail-rails/overrides/active_support_tagged_logging.rb +7 -6
- data/lib/logtail-rails/overrides.rb +0 -1
- data/lib/logtail-rails/version.rb +1 -1
- data/lib/logtail-rails.rb +1 -1
- data/logtail-rails.gemspec +7 -7
- metadata +93 -65
- data/example-project/Logtail-rails-main/app/assets/config/manifest.js +0 -2
- data/example-project/Logtail-rails-main/config/credentials.yml.enc +0 -1
- data/example-project/Logtail-rails-main/config/initializers/logtail.rb +0 -6
- data/example-project/Logtail-rails-main/test/controllers/example_controller_test.rb +0 -7
- data/gemfiles/rails-3.0.gemfile +0 -8
- data/gemfiles/rails-3.1.gemfile +0 -8
- data/gemfiles/rails-3.2.gemfile +0 -8
- data/gemfiles/rails-4.0.gemfile +0 -12
- data/gemfiles/rails-4.1.gemfile +0 -12
- data/gemfiles/rails-4.2.gemfile +0 -12
- data/lib/logtail-rails/overrides/active_support_3_tagged_logging.rb +0 -111
- data/lib/logtail-rails/tasks/logtail.rake +0 -57
- /data/example-project/{Logtail-rails-main/Rakefile → Rakefile} +0 -0
- /data/example-project/{Logtail-rails-main/app → app}/assets/stylesheets/application.css +0 -0
- /data/example-project/{Logtail-rails-main/app → app}/channels/application_cable/channel.rb +0 -0
- /data/example-project/{Logtail-rails-main/app → app}/channels/application_cable/connection.rb +0 -0
- /data/example-project/{Logtail-rails-main/app → app}/controllers/application_controller.rb +0 -0
- /data/example-project/{Logtail-rails-main/app → app}/helpers/application_helper.rb +0 -0
- /data/example-project/{Logtail-rails-main/app → app}/helpers/example_helper.rb +0 -0
- /data/example-project/{Logtail-rails-main/app → app}/jobs/application_job.rb +0 -0
- /data/example-project/{Logtail-rails-main/app → app}/mailers/application_mailer.rb +0 -0
- /data/example-project/{Logtail-rails-main/app → app}/models/application_record.rb +0 -0
- /data/example-project/{Logtail-rails-main/app → app}/views/example/index.html.erb +0 -0
- /data/example-project/{Logtail-rails-main/app → app}/views/example/send_logs.html.erb +0 -0
- /data/example-project/{Logtail-rails-main/app → app}/views/layouts/application.html.erb +0 -0
- /data/example-project/{Logtail-rails-main/app → app}/views/layouts/mailer.html.erb +0 -0
- /data/example-project/{Logtail-rails-main/app → app}/views/layouts/mailer.text.erb +0 -0
- /data/example-project/{Logtail-rails-main/config → config}/boot.rb +0 -0
- /data/example-project/{Logtail-rails-main/config → config}/database.yml +0 -0
- /data/example-project/{Logtail-rails-main/config → config}/environment.rb +0 -0
- /data/example-project/{Logtail-rails-main/config → config}/environments/development.rb +0 -0
- /data/example-project/{Logtail-rails-main/config → config}/environments/test.rb +0 -0
- /data/example-project/{Logtail-rails-main/config → config}/initializers/assets.rb +0 -0
- /data/example-project/{Logtail-rails-main/config → config}/initializers/filter_parameter_logging.rb +0 -0
- /data/example-project/{Logtail-rails-main/config → config}/initializers/inflections.rb +0 -0
- /data/example-project/{Logtail-rails-main/config → config}/initializers/permissions_policy.rb +0 -0
- /data/example-project/{Logtail-rails-main/config → config}/locales/en.yml +0 -0
- /data/example-project/{Logtail-rails-main/config → config}/puma.rb +0 -0
- /data/example-project/{Logtail-rails-main/config → config}/routes.rb +0 -0
- /data/example-project/{Logtail-rails-main/config → config}/storage.yml +0 -0
- /data/example-project/{Logtail-rails-main/config.ru → config.ru} +0 -0
- /data/example-project/{Logtail-rails-main/test → test}/application_system_test_case.rb +0 -0
- /data/example-project/{Logtail-rails-main/test → test}/channels/application_cable/connection_test.rb +0 -0
- /data/example-project/{Logtail-rails-main/test → test}/test_helper.rb +0 -0
data/gemfiles/rails-3.2.gemfile
DELETED
data/gemfiles/rails-4.0.gemfile
DELETED
data/gemfiles/rails-4.1.gemfile
DELETED
data/gemfiles/rails-4.2.gemfile
DELETED
@@ -1,111 +0,0 @@
|
|
1
|
-
# Please note, this patch is merely an upgrade, backporting improved tagged logging code
|
2
|
-
# from newer versions of Rails:
|
3
|
-
# https://github.com/rails/rails/blob/5-1-stable/activesupport/lib/active_support/tagged_logging.rb
|
4
|
-
# The behavior of tagged logging will not change in any way.
|
5
|
-
#
|
6
|
-
# This patch is specifically for Rails 3. The legacy approach to wrapping the logger in
|
7
|
-
# ActiveSupport::TaggedLogging is rather poor, hence the reason it was changed entirely
|
8
|
-
# for Rails 4 and 5. The problem is that ActiveSupport::TaggedLogging is a wrapping
|
9
|
-
# class that entirely redefines the public API for the logger. As a result, any deviations
|
10
|
-
# from this API in the logger are not exposed (such as accepting event data as a second argument).
|
11
|
-
# This is assuming, so we're fixing it here.
|
12
|
-
|
13
|
-
begin
|
14
|
-
require "active_support/tagged_logging"
|
15
|
-
|
16
|
-
# Instead of patching the class we're pulling the code from Rails master. This brings in
|
17
|
-
# a number of improvements while also addressing the issue above.
|
18
|
-
if ActiveSupport::TaggedLogging.instance_of?(Class)
|
19
|
-
ActiveSupport.send(:remove_const, :TaggedLogging)
|
20
|
-
|
21
|
-
require "active_support/core_ext/module/delegation"
|
22
|
-
require "active_support/core_ext/object/blank"
|
23
|
-
require "logger"
|
24
|
-
|
25
|
-
module ActiveSupport
|
26
|
-
# Wraps any standard Logger object to provide tagging capabilities.
|
27
|
-
#
|
28
|
-
# logger = ActiveSupport::TaggedLogging.new(Logger.new(STDOUT))
|
29
|
-
# logger.tagged('BCX') { logger.info 'Stuff' } # Logs "[BCX] Stuff"
|
30
|
-
# logger.tagged('BCX', "Jason") { logger.info 'Stuff' } # Logs "[BCX] [Jason] Stuff"
|
31
|
-
# logger.tagged('BCX') { logger.tagged('Jason') { logger.info 'Stuff' } } # Logs "[BCX] [Jason] Stuff"
|
32
|
-
#
|
33
|
-
# This is used by the default Rails.logger as configured by Railties to make
|
34
|
-
# it easy to stamp log lines with subdomains, request ids, and anything else
|
35
|
-
# to aid debugging of multi-user production applications.
|
36
|
-
module TaggedLogging
|
37
|
-
module Formatter # :nodoc:
|
38
|
-
# This method is invoked when a log event occurs.
|
39
|
-
def call(severity, timestamp, progname, msg)
|
40
|
-
super(severity, timestamp, progname, "#{tags_text}#{msg}")
|
41
|
-
end
|
42
|
-
|
43
|
-
def tagged(*tags)
|
44
|
-
new_tags = push_tags(*tags)
|
45
|
-
yield self
|
46
|
-
ensure
|
47
|
-
pop_tags(new_tags.size)
|
48
|
-
end
|
49
|
-
|
50
|
-
def push_tags(*tags)
|
51
|
-
tags.flatten.reject(&:blank?).tap do |new_tags|
|
52
|
-
current_tags.concat new_tags
|
53
|
-
end
|
54
|
-
end
|
55
|
-
|
56
|
-
def pop_tags(size = 1)
|
57
|
-
current_tags.pop size
|
58
|
-
end
|
59
|
-
|
60
|
-
def clear_tags!
|
61
|
-
current_tags.clear
|
62
|
-
end
|
63
|
-
|
64
|
-
def current_tags
|
65
|
-
# We use our object ID here to avoid conflicting with other instances
|
66
|
-
thread_key = @thread_key ||= "activesupport_tagged_logging_tags:#{object_id}".freeze
|
67
|
-
Thread.current[thread_key] ||= []
|
68
|
-
end
|
69
|
-
|
70
|
-
def tags_text
|
71
|
-
tags = current_tags
|
72
|
-
if tags.any?
|
73
|
-
tags.collect { |tag| "[#{tag}] " }.join
|
74
|
-
end
|
75
|
-
end
|
76
|
-
end
|
77
|
-
|
78
|
-
# Simple formatter which only displays the message.
|
79
|
-
class SimpleFormatter < ::Logger::Formatter
|
80
|
-
# This method is invoked when a log event occurs
|
81
|
-
def call(severity, timestamp, progname, msg)
|
82
|
-
"#{String === msg ? msg : msg.inspect}\n"
|
83
|
-
end
|
84
|
-
end
|
85
|
-
|
86
|
-
def self.new(logger)
|
87
|
-
if logger.respond_to?(:formatter=) && logger.respond_to?(:formatter)
|
88
|
-
# Ensure we set a default formatter so we aren't extending nil!
|
89
|
-
logger.formatter ||= SimpleFormatter.new
|
90
|
-
logger.formatter.extend Formatter
|
91
|
-
end
|
92
|
-
|
93
|
-
logger.extend(self)
|
94
|
-
end
|
95
|
-
|
96
|
-
delegate :push_tags, :pop_tags, :clear_tags!, to: :formatter
|
97
|
-
|
98
|
-
def tagged(*tags)
|
99
|
-
formatter.tagged(*tags) { yield self }
|
100
|
-
end
|
101
|
-
|
102
|
-
def flush
|
103
|
-
clear_tags!
|
104
|
-
super if defined?(super)
|
105
|
-
end
|
106
|
-
end
|
107
|
-
end
|
108
|
-
end
|
109
|
-
|
110
|
-
rescue Exception
|
111
|
-
end
|
@@ -1,57 +0,0 @@
|
|
1
|
-
namespace :logtail do
|
2
|
-
desc 'Install a default config/initializers/logtail.rb file'
|
3
|
-
|
4
|
-
PLACEHOLDER = '<SOURCE_TOKEN>'.freeze
|
5
|
-
def content(source_token = nil)
|
6
|
-
<<~RUBY
|
7
|
-
if ENV['LOGTAIL_SKIP_LOGS'].blank? && !Rails.env.test?
|
8
|
-
http_device = Logtail::LogDevices::HTTP.new('#{source_token || PLACEHOLDER}')
|
9
|
-
Rails.logger = Logtail::Logger.new(http_device)
|
10
|
-
else
|
11
|
-
Rails.logger = Logtail::Logger.new(STDOUT)
|
12
|
-
end
|
13
|
-
RUBY
|
14
|
-
end
|
15
|
-
|
16
|
-
task install: :environment do
|
17
|
-
quiet = ENV['quiet']
|
18
|
-
force = ENV['force']
|
19
|
-
source_token = ENV['source_token']
|
20
|
-
|
21
|
-
config_file = 'config/initializers/logtail.rb'
|
22
|
-
|
23
|
-
if File.exist?(config_file) && !force
|
24
|
-
puts "logtail.rb file already exists. Use `rake logtail:install force=true` to overwrite."
|
25
|
-
next
|
26
|
-
end
|
27
|
-
|
28
|
-
File.open(config_file, 'w') { |out| out.puts(content(source_token)) }
|
29
|
-
|
30
|
-
return if quiet
|
31
|
-
|
32
|
-
if source_token.nil? || source_token == ''
|
33
|
-
puts <<~EOF
|
34
|
-
Installed a default configuration file at #{config_file}.
|
35
|
-
EOF
|
36
|
-
|
37
|
-
puts <<~EOF
|
38
|
-
To monitor your logs in production mode, sign up for an account
|
39
|
-
at logtail.com, and replace the source token in the logtail.rb file
|
40
|
-
with the one you receive upon registration.
|
41
|
-
EOF
|
42
|
-
|
43
|
-
puts <<~EOF
|
44
|
-
Visit logtail.com/help if you are experiencing installation issues.
|
45
|
-
EOF
|
46
|
-
else
|
47
|
-
puts <<~EOF
|
48
|
-
Installed a configuration file at #{config_file} with a source token
|
49
|
-
ending with '#{source_token[-4..-1]}'.
|
50
|
-
EOF
|
51
|
-
|
52
|
-
puts <<~EOF
|
53
|
-
Visit logtail.com/help if you are experiencing installation issues.
|
54
|
-
EOF
|
55
|
-
end
|
56
|
-
end
|
57
|
-
end
|
File without changes
|
File without changes
|
File without changes
|
/data/example-project/{Logtail-rails-main/app → app}/channels/application_cable/connection.rb
RENAMED
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
/data/example-project/{Logtail-rails-main/config → config}/initializers/filter_parameter_logging.rb
RENAMED
File without changes
|
File without changes
|
/data/example-project/{Logtail-rails-main/config → config}/initializers/permissions_policy.rb
RENAMED
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
/data/example-project/{Logtail-rails-main/test → test}/channels/application_cable/connection_test.rb
RENAMED
File without changes
|
File without changes
|