context_logger 0.0.15 → 0.0.16

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.
Files changed (3) hide show
  1. checksums.yaml +4 -4
  2. data/lib/context_logger.rb +30 -6
  3. metadata +1 -1
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 4560497980a88fd1ad5eadaa1b5bc1cff8deec80
4
- data.tar.gz: 6aa731cee42fab6c89c000dca76576db863b88c7
3
+ metadata.gz: f4930725e3681907ba106b8bb1e16821973ea131
4
+ data.tar.gz: f7de8fe2d2491c2061235d263d2e06d9bbda5991
5
5
  SHA512:
6
- metadata.gz: 36159a7c126c3709b9800ee33f95bc46d2e77a75c75e20324408dc2c4a496f96fdbcbbd444c296bff322de0fd442af0b04fc4d52def21338bcdb697e9b53554f
7
- data.tar.gz: 79a7f7dcd842043978d011fcd98b4fd5d8282aded2cc8d4351a910e366b78ba58f01f881129b37133d44fadfda946687a15ee8305b5da588ab0c591a8b3f453f
6
+ metadata.gz: d293ffea9e33fd8547fedfa330d9dda6ca90ccfcb3820c0d0e709525ace9a4f4caa38728387b7d4bcc0a2e51411529c8d57c17b8a8135148ab2e5af8e40f9997
7
+ data.tar.gz: 04c7779bd74c358988230d4f4462a0cb309eb19959e0f5902c2c69362e9a53d4d72135433866a24b53044d2137ab92a966606dae11b17db94df53362c0f524e4
@@ -4,7 +4,7 @@ module ContextLogger
4
4
 
5
5
  SEVERITY_TYPES = [:info, :warn, :error, :debug, :unknown, :fatal]
6
6
 
7
- @defaults = {
7
+ DEFAULTS = {
8
8
  context: :context_log,
9
9
  # action_id: nil,
10
10
  # server_name: nil,
@@ -14,7 +14,7 @@ module ContextLogger
14
14
  # stack_trace: nil
15
15
  }
16
16
 
17
- @options = {}.merge(@defaults)
17
+ @options = {}.merge(DEFAULTS)
18
18
 
19
19
  SEVERITY_TYPES.each do |severity_type|
20
20
  define_singleton_method severity_type do |context, server, action_id, method, params, message, stack_trace|
@@ -24,6 +24,13 @@ module ContextLogger
24
24
 
25
25
  @context_loggers = {}
26
26
 
27
+ @destinations = {}
28
+ ALL_DESTINATIONS = {
29
+ write_rails_log: true,
30
+ write_context_log: true,
31
+ write_db_log: true
32
+ }
33
+
27
34
  def self.setup(options)
28
35
  @options = (@options || {}).merge(options)
29
36
  end
@@ -32,6 +39,19 @@ module ContextLogger
32
39
  return @options
33
40
  end
34
41
 
42
+ def self.set_destinations(_destinations)
43
+ if _destinations == :all
44
+ @destinations = ALL_DESTINATIONS.clone
45
+ return
46
+ end
47
+
48
+ @destinations = _destinations.select{|k, _| ALL_DESTINATIONS[k]}
49
+ end
50
+
51
+ def self.destinations
52
+ return @destinations
53
+ end
54
+
35
55
  def self.logs_folder
36
56
  # TODO: set the path from config
37
57
  @logs_folder ||= "#{Rails.root}/log"
@@ -48,9 +68,13 @@ module ContextLogger
48
68
  def self.log(params)
49
69
  params_with_defaults = options.merge(params.reject{|_, v| v.nil?})
50
70
 
51
- write_rails_log(params_with_defaults)
52
- write_context_log(params_with_defaults)
53
- write_db_log(params_with_defaults)
71
+ destinations.each do |log_destination, should_write_log|
72
+ self.send(log_destination, params_with_defaults) if should_write_log
73
+ end
74
+
75
+ # write_rails_log(params_with_defaults)
76
+ # write_context_log(params_with_defaults)
77
+ # write_db_log(params_with_defaults)
54
78
  end
55
79
 
56
80
  def self.logger_of_context(current_context)
@@ -67,7 +91,7 @@ module ContextLogger
67
91
  end
68
92
 
69
93
  def self.write_db_log(params_with_defaults)
70
- ::ContextLog.create(params_with_defaults)
94
+ ::ContextLog.create(params_with_defaults.select{|k, _| ::ContextLog.method_defined?(k)})
71
95
  end
72
96
 
73
97
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: context_logger
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.15
4
+ version: 0.0.16
5
5
  platform: ruby
6
6
  authors:
7
7
  - Alexander Libster