rails-logstasher 0.1.2 → 0.1.3

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,15 +1,15 @@
1
1
  ---
2
2
  !binary "U0hBMQ==":
3
3
  metadata.gz: !binary |-
4
- ZTdlYWFhNTYwOWQxODFiOTRkNGIzNDIwZDU3NzkxOWRmMjQ5YzJiOA==
4
+ YjMyYmI1OWQ4YzgzMTYzMTlmMjRmZmIxYjZkNDAxN2Q0YTIwOTc0NA==
5
5
  data.tar.gz: !binary |-
6
- N2M0NTlmMDNjYzAyZGI4YzZhMWFmZGM2ODc5MzJhMGM3ZTljM2M2Mg==
6
+ MDUyMTI1YmQ1Y2QzNTNhNzMxYjAxYjkwMTczMGNhZmZiNzA2MTEzYQ==
7
7
  SHA512:
8
8
  metadata.gz: !binary |-
9
- M2RkZDlmYTNiYjVkYjA3ODhlYWNjMzdkNzgwZTk2MTQzOTM3MjI1Njk3Nzg3
10
- N2UyNjYzYmVhOTZmYWQwM2RiMjFlZGUyMTBiNGQ3ZmFmZTllMGQ0MzgzMjAx
11
- ODhkY2MzMjQ3MGVmYjhkYzliNDg4NzMzZDBiM2NmZmJmZDIyZWY=
9
+ ZDlkODNkOWNiMDFjYjg3NDRiY2JjMGY3Nzk4YTlkNjUxZmMwOTYyOGE5YmQ1
10
+ OTcwMDBiYmZiNDQ0N2E0ZmE1NTE5OGRlYThmY2YzZjExYzY3YWFlODVmZWY5
11
+ YzhhMGM2NDRmNGJlZmVmMDNmYmRlZGNhODJlNWY0NTA3OTZlZTQ=
12
12
  data.tar.gz: !binary |-
13
- OTI3NDk1OWExMjI5NzcwNTY4OWMxYjFmMGRmMWM5N2IxYjQ3OTAzODMzZTE0
14
- NDQ2MzNiZjFiMzMzYjBiOGIyMmE3NjYwMmIyYTY2ODI5MjM1Y2Y4ZGE1NTVj
15
- MDFmY2JlOTMyOGJhY2Q0MDFhYWY4NzcwZjg4ODZlN2MwNmYwOWI=
13
+ ZTUwMjBkMzcxYzY0MzJhY2ZkYWEzYjRhNmM2MmE2OGQwMjZlNTg4OWZlZWI5
14
+ YzViNzZjMTg2NjA5YTQ0NzcwOThjZWQ5OWNlYjYyNWE4MzFlYjA1MzYxZjIw
15
+ NmNkYmYzY2I3NjgxZjY4NDlhZjdiMzNlN2ZhZWU4MGY2ODY3ODE=
data/README.md CHANGED
@@ -46,8 +46,11 @@ module MyApp
46
46
  # Set a logger compatible with the standard ruby logger to be used by RailsLogstasher
47
47
  config.logger = RailsLogstasher::Logger.new(Rails.root.join('log',"#{Rails.env}.log").to_s)
48
48
 
49
+ # Optionally specify a log type tag (default is 'rails')
50
+ config.log_type = 'my_type'
51
+
49
52
  # Optionally process log entries before they are written to the log
50
- RailsLogstasher.config[:entry_processor] = Proc.new {|entry| ... do stuff with entry...}
53
+ config.log_entry_processor = Proc.new {|entry| ... do stuff with entry...}
51
54
 
52
55
  end
53
56
  end
@@ -81,6 +84,18 @@ module MyApp
81
84
  end
82
85
  ```
83
86
 
87
+ It is possible to configure a Proc to custom handle log entries before they are written to the log file, like so:
88
+
89
+ ```
90
+ module MyApp
91
+ class Application < Rails::Application
92
+
93
+ config.log_entry_processor = Proc.new {|entry| entry.fields['my_custom_field'] = 'hello' }
94
+
95
+ end
96
+ end
97
+ ```
98
+
84
99
  You will need to edit the path to point to your application's log file. Because RailsLogstasher creates json
85
100
  serialized Logstash::Event entries there is no need to setup any filters
86
101
 
@@ -31,7 +31,7 @@ module RailsLogstasher
31
31
  # Take the current logger and replace it with itself wrapped by the
32
32
  # RailsLogstasher::TaggedLogging class
33
33
  app.config.log_type = 'rails' unless app.config.respond_to? :log_type
34
- app.config.logger = RailsLogstasher::TaggedLogging.new(app.config.logger, app.config.log_type)
34
+ app.config.logger = RailsLogstasher::TaggedLogging.new(app.config.logger, app.config.log_type, app.config.log_entry_processor)
35
35
  end
36
36
 
37
37
 
@@ -38,10 +38,8 @@ module RailsLogstasher
38
38
  end
39
39
 
40
40
  def process_entry
41
- entry_processor = RailsLogstasher.config[:entry_processor]
42
- return unless entry_processor && entry_processor.class == Proc
43
-
44
- entry_processor.call @entry
41
+ return unless @log_entry_processor && @log_entry_processor.class == Proc
42
+ @log_entry_processor.call @entry
45
43
  end
46
44
 
47
45
  def tagged(*tags)
@@ -94,13 +92,18 @@ module RailsLogstasher
94
92
  @log_type = log_type
95
93
  end
96
94
 
95
+ def log_entry_processor=(log_entry_processor)
96
+ @log_entry_processor = log_entry_processor
97
+ end
98
+
97
99
  end
98
100
 
99
- def self.new(logger, log_type)
101
+ def self.new(logger, log_type, log_entry_processor=nil)
100
102
  # Ensure we set a default formatter so we aren't extending nil!
101
103
  logger.formatter ||= ActiveSupport::Logger::SimpleFormatter.new
102
104
  logger.formatter.extend Formatter
103
105
  logger.formatter.log_type = log_type
106
+ logger.formatter.log_entry_processor = log_entry_processor
104
107
  logger.extend(self)
105
108
  end
106
109
 
@@ -1,3 +1,3 @@
1
1
  module RailsLogstasher
2
- VERSION = "0.1.2"
2
+ VERSION = "0.1.3"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rails-logstasher
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.2
4
+ version: 0.1.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Nadav Fischer