logify 0.1.0 → 0.2.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
  SHA1:
3
- metadata.gz: f397195c1a3f20f14adfa54eaa76ad742ee0b624
4
- data.tar.gz: 0643d3a0c5570f0fa8da7a2c9ce577f17e921929
3
+ metadata.gz: 1bcc3e3495cbe4217d1198e098fdc99ae1165688
4
+ data.tar.gz: 4f9a07b1d502d5a7879dcbfe97b2a25833f64757
5
5
  SHA512:
6
- metadata.gz: 3030a68c9296d02af53bb1f30236e4e182c1267da0582f011012da79f1549ad92dc6c71d9123beeeee7a0beb7c5c3691068e4b2da7625a0771f5ce4aadf743ff
7
- data.tar.gz: 9a6041c145949efa74ed05aee71d50ad1df890c556834169603bbad70f0081729ddf6f67dec4df69c92206bcf3a736e2f2f590c56b4be980d3350402ecd2001d
6
+ metadata.gz: 44623445e580503c358470ea0316e4b00e3aae92f7ec1b143c6fca84c05f77411f030221c423894e0172273a4d27b9b6d9be9d4adea61fbe063a81cbe46f593f
7
+ data.tar.gz: ef691f792b07183e5a2892b1be1088f399f8cc56e9e4e5002dcc18f41590a0c478fcfc600b534bc1224da62ef8222436ad267eccc4ae88758cca4c1af18c43c4
@@ -0,0 +1,12 @@
1
+ Logify Changelog
2
+ ================
3
+
4
+ v0.2.0
5
+ ------
6
+ - Document manual logger creation
7
+ - Add filter parameters
8
+ - `log` methods now return the yielded string
9
+
10
+ v0.1.0
11
+ ------
12
+ - Initial public release
data/README.md CHANGED
@@ -76,6 +76,26 @@ WARN #=> "W"
76
76
  INFO #=> "I"
77
77
  ```
78
78
 
79
+ If you are anti-modules (or if you want to use `log` for something else), you can manually create your Logger object in an initializer:
80
+
81
+ ```ruby
82
+ require 'logify'
83
+
84
+ class MyClass
85
+ def initialize
86
+ @logger = Logify.logger_for(self.class.name) # Or any custom name
87
+ end
88
+ end
89
+ ```
90
+
91
+ And then use `@logger` to call your log methods:
92
+
93
+ ```ruby
94
+ def other_method
95
+ @logger.info 'Running other_method'
96
+ end
97
+ ```
98
+
79
99
  Configuring
80
100
  -----------
81
101
  Logify is configurable via the top-level `Logify` module.
@@ -125,6 +145,12 @@ Or set the `log_level` to `:none`:
125
145
  Logify.level = :none
126
146
  ```
127
147
 
148
+ If you are logging sensitive information (such as passwords and API keys), you can add that information as a filter to Logify. Logify will replace those values with "`[FILTERED]`" in logging output.
149
+
150
+ ```ruby
151
+ Logify.filter('P@s$w0r)')
152
+ ```
153
+
128
154
 
129
155
  Installation
130
156
  ------------
@@ -90,6 +90,28 @@ module Logify
90
90
  Thread.current[IO_ID] = io
91
91
  end
92
92
 
93
+ #
94
+ # Add a filter parameter to Logify.
95
+ #
96
+ # @example Filter a password in the logger
97
+ # Logify.filter('P@s$w0r)')
98
+ # log.debug "This is the P@s$w0r)" #=> "This is the [FILTERED]"
99
+ #
100
+ # @return [void]
101
+ #
102
+ def filter(param)
103
+ filters[param] = nil
104
+ end
105
+
106
+ #
107
+ # The list of filters for Logify.
108
+ #
109
+ # @return [Hash]
110
+ #
111
+ def filters
112
+ @filters ||= {}
113
+ end
114
+
93
115
  private
94
116
 
95
117
  # @private
@@ -21,7 +21,8 @@ module Logify
21
21
  # @param [Proc] block
22
22
  # the block to call that returns a string to write
23
23
  #
24
- # @return [true]
24
+ # @return [String]
25
+ # the compiled log message
25
26
  #
26
27
  def level(name)
27
28
  constant = name.to_s.upcase
@@ -39,13 +40,13 @@ module Logify
39
40
  buffer << PREFIX_#{constant}
40
41
  end
41
42
 
42
- buffer << message if message
43
- buffer << yield if block_given?
43
+ buffer << filter(message) if message
44
+ buffer << filter(yield) if block_given?
44
45
  buffer << "#{NEWLINE}"
45
46
 
46
47
  MONITOR.synchronize { Logify.io.write(buffer) }
47
48
 
48
- true
49
+ buffer
49
50
  end
50
51
  end
51
52
  EOH
@@ -53,6 +54,7 @@ module Logify
53
54
  end
54
55
 
55
56
  ANONYMOUS = '(Anonymous)'
57
+ FILTERED = '[FILTERED]'
56
58
  MAX_LENGTH = 32
57
59
  NEWLINE = "\n"
58
60
  SEPARATOR = ' | '
@@ -106,7 +108,14 @@ module Logify
106
108
 
107
109
  private
108
110
 
111
+ #
109
112
  # @private
113
+ #
114
+ # The truncated id (for debug only).
115
+ #
116
+ # @return [String]
117
+ # the formatted id
118
+ #
110
119
  def formatted_id
111
120
  return @formatted_id if @formatted_id
112
121
 
@@ -131,5 +140,26 @@ module Logify
131
140
  @formatted_id = temp.rjust(MAX_LENGTH)
132
141
  end
133
142
  end
143
+
144
+ #
145
+ # @private
146
+ #
147
+ # Filter the given string of any filtered parameters.
148
+ #
149
+ # @see Logify.filter
150
+ #
151
+ # @param [String]
152
+ # the string to filter
153
+ #
154
+ # @return [String]
155
+ # the filtered string
156
+ #
157
+ def filter(string)
158
+ string.dup.tap do |copy|
159
+ Logify.filters.each do |param, _|
160
+ copy.gsub!(param, FILTERED)
161
+ end
162
+ end
163
+ end
134
164
  end
135
165
  end
@@ -4,5 +4,5 @@ module Logify
4
4
  #
5
5
  # @return [String]
6
6
  #
7
- VERSION = '0.1.0'
7
+ VERSION = '0.2.0'
8
8
  end
@@ -20,7 +20,7 @@ Gem::Specification.new do |spec|
20
20
 
21
21
  spec.required_ruby_version = '>= 1.9.3'
22
22
 
23
- spec.files = `git ls-files`.split($/)
23
+ spec.files = `git ls-files -z`.split("\x0")
24
24
  spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
25
25
  spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
26
26
  spec.require_paths = ['lib']
@@ -240,5 +240,14 @@ module Logify
240
240
  expect(stdout).to_not include('This is a fatal')
241
241
  end
242
242
  end
243
+
244
+ context 'with filter params' do
245
+ before { Logify.filter('bacon') }
246
+
247
+ it 'filters the parameter' do
248
+ log.info 'The password is bacon'
249
+ expect(stdout).to include('The password is [FILTERED]')
250
+ end
251
+ end
243
252
  end
244
253
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: logify
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Seth Vargo
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-03-14 00:00:00.000000000 Z
11
+ date: 2014-03-16 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rspec
@@ -77,6 +77,7 @@ extra_rdoc_files: []
77
77
  files:
78
78
  - ".gitignore"
79
79
  - ".travis.yml"
80
+ - CHANGELOG.md
80
81
  - Gemfile
81
82
  - LICENSE
82
83
  - README.md