job_enqueue_logger 0.2.0 → 0.3.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 8d4b7eb9d105f9c73af421299c43d70573c5ac5b519cf5a334d0a78ed2b704f9
4
- data.tar.gz: efe3b6d93873f70676e6c7b9cd085328332fda9cba8fcad99007f4151f3e253c
3
+ metadata.gz: dea7d0e16e19e83d6a41a6ac12dfb637670b6c2767ffd859a65c33eb1fe6fb1b
4
+ data.tar.gz: 44da64bbfc0bcc1984dff1bb971768d0ebec961e4eefba46b9223c38115f6376
5
5
  SHA512:
6
- metadata.gz: 523da331a92ea785d6a58ce1fbd3e4bcbc9dbbe1a8f3f2974ee2bb0b581a805e100f7e4d0f225710e7e83bf699916514b84e163ba7bec1e302bfcb143752e858
7
- data.tar.gz: 2c2b9128d579945615e85eebdd71531e64027b82ad9e16bbff4d1203a96c875f237a977e3b33aaa7f65ea41b433f4cee8abbaba81201c622383e9336ca47663b
6
+ metadata.gz: 2b20c92834369550756fe71f0f27c76dca198fe267fad432765740bbcf3a1ed034e89aa126fb2acf6e76978f632813241176af77a7d139762ffd4d7ba9f4c2e5
7
+ data.tar.gz: e5ef769550740936181d7fa72b78bc6c132542095e0bb66f7c4973bf90298bc6ffed1d168e4aa553f4b60ae8266fc8221dbfa611fc02c1855ffa48a110157592
data/CHANGELOG.md CHANGED
@@ -1,5 +1,11 @@
1
1
  ## master (unreleased)
2
2
 
3
+ ## 0.3.0 (2023-11-09)
4
+
5
+ - Truncate long string arguments in log output
6
+ - Add ability to set logger
7
+ - Prefix this gem log lines with `[JobEnqueueLogger]`
8
+
3
9
  ## 0.2.0 (2023-04-04)
4
10
 
5
11
  - Support `que`
data/README.md CHANGED
@@ -11,13 +11,13 @@ This is very much a development and debugging tool; it is not recommended to use
11
11
  When the job is enqueued within the guts of the application, the log line is generated:
12
12
 
13
13
  ```
14
- Enqueued AvatarThumbnailsJob (jid=578b3d10fc5403f97ee0a8e1) to Sidekiq(default) with arguments: 1092412064
14
+ [JobEnqueueLogger] Enqueued AvatarThumbnailsJob (jid=578b3d10fc5403f97ee0a8e1) to Sidekiq(default) with arguments: 1092412064
15
15
  ```
16
16
 
17
17
  Or with backtraces enabled:
18
18
 
19
19
  ```
20
- Enqueued AvatarThumbnailsJob (jid=578b3d10fc5403f97ee0a8e1) to Sidekiq(default) with arguments: 1092412064
20
+ [JobEnqueueLogger] Enqueued AvatarThumbnailsJob (jid=578b3d10fc5403f97ee0a8e1) to Sidekiq(default) with arguments: 1092412064
21
21
  ↳ app/models/user.rb:421:in `generate_avatar_thumbnails'
22
22
  app/services/user_creator.rb:21:in `call'
23
23
  app/controllers/users_controller.rb:49:in `create'
@@ -71,13 +71,15 @@ JobEnqueueLogger.configure do |config|
71
71
  # Controls whether to print backtraces. Set to `true` to print backtraces, or
72
72
  # a number to limit how many lines to print.
73
73
  config.backtrace = false
74
+
75
+ # The logger to log to.
76
+ # Is set to Rails.logger by default, when the gem is used in the Rails app.
77
+ config.logger = nil
74
78
  end
75
79
  ```
76
80
 
77
81
  ## Development
78
82
 
79
- After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake test` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
80
-
81
83
  To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and the created tag, and push the `.gem` file to [rubygems.org](https://rubygems.org).
82
84
 
83
85
  ## Contributing
@@ -34,8 +34,8 @@ module JobEnqueueLogger
34
34
  alias server? server
35
35
 
36
36
  def logger
37
- if !server? && defined?(Rails)
38
- Rails.logger
37
+ if !server? && JobEnqueueLogger.logger
38
+ JobEnqueueLogger.logger
39
39
  else
40
40
  Delayed::Worker.logger
41
41
  end
@@ -56,8 +56,8 @@ module JobEnqueueLogger
56
56
  # Que.server? is defined in the newest version of Que - https://github.com/que-rb/que/pull/382
57
57
  is_server = defined?(Que::CommandLineInterface)
58
58
 
59
- if !is_server && defined?(Rails)
60
- Rails.logger
59
+ if !is_server && JobEnqueueLogger.logger
60
+ JobEnqueueLogger.logger
61
61
  elsif Que.logger.respond_to?(:call)
62
62
  Que.logger.call
63
63
  else
@@ -6,6 +6,7 @@ module JobEnqueueLogger
6
6
  class Railtie < Rails::Railtie
7
7
  initializer "job_enqueue_logger.backtrace_cleaner" do
8
8
  JobEnqueueLogger.backtrace_cleaner = Rails.backtrace_cleaner
9
+ JobEnqueueLogger.logger = Rails.logger
9
10
  end
10
11
  end
11
12
  end
@@ -41,8 +41,8 @@ module JobEnqueueLogger
41
41
  alias server? server
42
42
 
43
43
  def logger
44
- if !server? && defined?(Rails)
45
- Rails.logger
44
+ if !server? && JobEnqueueLogger.logger
45
+ JobEnqueueLogger.logger
46
46
  else
47
47
  Resque.logger
48
48
  end
@@ -47,8 +47,8 @@ module JobEnqueueLogger
47
47
  end
48
48
 
49
49
  def self.logger
50
- if !Sidekiq.server? && defined?(Rails)
51
- Rails.logger
50
+ if !Sidekiq.server? && JobEnqueueLogger.logger
51
+ JobEnqueueLogger.logger
52
52
  else
53
53
  Sidekiq.logger
54
54
  end
@@ -28,11 +28,7 @@ module JobEnqueueLogger
28
28
  end
29
29
 
30
30
  def self.logger
31
- if defined?(Rails)
32
- Rails.logger
33
- else
34
- SuckerPunch.logger
35
- end
31
+ JobEnqueueLogger.logger || SuckerPunch.logger
36
32
  end
37
33
  end
38
34
  end
@@ -3,6 +3,7 @@
3
3
  module JobEnqueueLogger
4
4
  module Utils
5
5
  def self.log_job_enqueue(logger, message)
6
+ message = "[JobEnqueueLogger] #{message}"
6
7
  return logger.info(message) unless JobEnqueueLogger.backtrace
7
8
 
8
9
  backtrace = caller
@@ -19,10 +20,19 @@ module JobEnqueueLogger
19
20
 
20
21
  def self.args_info(args)
21
22
  if Array(args).any?
22
- " with arguments: #{Array(args).map(&:inspect).join(', ')}"
23
+ " with arguments: #{Array(args).map { |arg| format_arg(arg).inspect }.join(', ')}"
23
24
  else
24
25
  ""
25
26
  end
26
27
  end
28
+
29
+ def self.format_arg(arg)
30
+ case arg
31
+ when String
32
+ arg.size > 100 ? "#{arg[0, 100]}…" : arg
33
+ else
34
+ arg
35
+ end
36
+ end
27
37
  end
28
38
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module JobEnqueueLogger
4
- VERSION = "0.2.0"
4
+ VERSION = "0.3.0"
5
5
  end
@@ -16,7 +16,7 @@ module JobEnqueueLogger
16
16
  end
17
17
  end
18
18
 
19
- attr_accessor :backtrace
19
+ attr_accessor :backtrace, :logger
20
20
 
21
21
  def configure
22
22
  yield self
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: job_enqueue_logger
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.0
4
+ version: 0.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - fatkodima
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2023-04-04 00:00:00.000000000 Z
11
+ date: 2023-11-08 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description: |-
14
14
  Log background jobs enqueued by your application (additionally with backtraces).
@@ -54,7 +54,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
54
54
  - !ruby/object:Gem::Version
55
55
  version: '0'
56
56
  requirements: []
57
- rubygems_version: 3.4.7
57
+ rubygems_version: 3.4.10
58
58
  signing_key:
59
59
  specification_version: 4
60
60
  summary: Log background jobs enqueued by your application (additionally with backtraces).