scrolls 0.3.6 → 0.3.7

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 0dd730a76cce1b9b08ea5dfe7bae8edb9bed2fc3
4
+ data.tar.gz: 1d48b1371bff58dc40ce28148ce95f91c756aefa
5
+ SHA512:
6
+ metadata.gz: 587412cda539145df827237b30a54d651ab67641689b972fe21bf75fcb79702b9263e7bc646b298301d95bcee75e7951be28e294179de3d77e1b3f93b8198b95
7
+ data.tar.gz: db5eb2c16f307861ffaa1f9ab724e0eae99e675017736466a8e819f358a42cacba914473ce3291f640112ad3bde4d35045e824d78a1ee11e1e2484e5b271441a
data/README.md CHANGED
@@ -20,6 +20,10 @@ Or install it yourself as:
20
20
 
21
21
  Scrolls follows the belief that logs should be treated as data. One way to think of them is the blood of your infrastructure. Logs are a realtime view of what is happening on your systems.
22
22
 
23
+ ## Need to know!
24
+
25
+ The way Scrolls handles "global_context" is changing after v0.3.8. Please see the [release notes](https://github.com/asenchi/scrolls/releases/tag/v0.3.8) and [this documentation](https://github.com/asenchi/scrolls/tree/master/docs/global-context.md) for more information. I apologize for any trouble this may cause.
26
+
23
27
  ## Documentation:
24
28
 
25
29
  I apologize, some of these are a WIP.
@@ -0,0 +1,53 @@
1
+ ## Scrolls: Global Context
2
+
3
+ Early on Scrolls established a method for adding a "global_context" to log messages. This was perfect for data that should be appended to every log message in a project. Items like environment, request_id, app name all fit perfectly within the global logging context of a project. Later on @slemiere added in a way to dynamically update this global context.
4
+
5
+ However, due to [changes in Ruby 2.0](https://github.com/asenchi/scrolls/issues/53) it has become necessary to make the global context immutable and thus remove the locking necessary in our atomic operation. The effects of which Scrolls API changes slightly.
6
+
7
+ Previously, the global context was set using the following:
8
+
9
+ ```ruby
10
+ require 'scrolls'
11
+
12
+ Scrolls.global_context(:app => example)
13
+ Scrolls.log(:at => test)
14
+ ```
15
+
16
+ However, this will no longer be the method used. All releases after 0.3.8 will use the following method:
17
+
18
+ ```ruby
19
+ require 'scrolls'
20
+
21
+ Scrolls.init(
22
+ :global_context => { :app => example }
23
+ )
24
+ Scrolls.log(:at => test)
25
+ ```
26
+
27
+ `Scrolls#init` is a new method for initializing the internal Logger in Scrolls and will allow other configuration details to be set. Once the work is finalized more documentation on this method will be available and linked here. Until then you can follow along with development [here](https://github.com/asenchi/scrolls/pulls/54). It was introduced in `0.3.8` to allow developers to start moving toward that pattern.
28
+
29
+ Here is a another example:
30
+
31
+ ```ruby
32
+ Scrolls.init(
33
+ :global_context => {:g => "g"},
34
+ :timestamp => true,
35
+ :exceptions => "single",
36
+ )
37
+
38
+ Scrolls.log(:t => "t")
39
+ ```
40
+
41
+ Is the same as this currently:
42
+
43
+ ```ruby
44
+ Scrolls.global_context(:g => "g")
45
+ Scrolls.add_timestamp = true
46
+ Scrolls.single_line_exceptions = true
47
+
48
+ Scrolls.log(:t => "t")
49
+ ```
50
+
51
+ All of this also means that the "global_context" is no longer mutable and `Scrolls#add_global_context` will be deprecated.
52
+
53
+ I apologize for the incompatability of these changes, I work very hard not to break existing behavior. However, with the changes in Ruby core, I think we have a better path forward. I'm looking forward to "cementing" the API and releasing a 1.0 soon after this major refactor.
@@ -6,6 +6,37 @@ require "scrolls/version"
6
6
  module Scrolls
7
7
  extend self
8
8
 
9
+ # Public: Initialize a Scrolls logger
10
+ #
11
+ # Convienence method to prepare for future releases. Currently mimics
12
+ # behavior found in other methods. This prepares the developer for a future
13
+ # backward incompatible change, see:
14
+ # https://github.com/asenchi/scrolls/pull/54
15
+ #
16
+ # options - A hash of key/values for configuring Scrolls
17
+ #
18
+ def init(options)
19
+ stream = options.fetch(:stream, STDOUT)
20
+ facility = options.fetch(:facility, Syslog::LOG_USER)
21
+ time_unit = options.fetch(:time_unit, "seconds")
22
+ timestamp = options.fetch(:timestamp, false)
23
+ exceptions = options.fetch(:exceptions, "multi")
24
+ global_ctx = options.fetch(:global_context, {})
25
+
26
+ Log.stream = stream
27
+ Log.facility = facility if facility
28
+ Log.time_unit = time_unit unless time_unit == "seconds"
29
+ Log.add_timestamp = timestamp unless timestamp == false
30
+
31
+ if exceptions == "single"
32
+ Log.single_line_exceptions = true
33
+ end
34
+
35
+ unless global_ctx == {}
36
+ Log.global_context = global_ctx
37
+ end
38
+ end
39
+
9
40
  # Public: Set a context in a block for logs
10
41
  #
11
42
  # data - A hash of key/values to prepend to each log in a block
@@ -17,11 +48,16 @@ module Scrolls
17
48
  Log.with_context(data, &blk)
18
49
  end
19
50
 
20
- # Public: Get or set a global context that prefixs all logs
51
+ # Deprecated: Get or set a global context that prefixs all logs
21
52
  #
22
53
  # data - A hash of key/values to prepend to each log
23
54
  #
55
+ # This method will be deprecated two releases after 0.3.8.
56
+ # See https://github.com/asenchi/scrolls/releases/tag/v0.3.8
57
+ # for more details.
58
+ #
24
59
  def global_context(data=nil)
60
+ $stderr.puts "global_context() will be deprecated after v0.3.8, please see https://github.com/asenchi/scrolls for more information."
25
61
  if data
26
62
  Log.global_context = data
27
63
  else
@@ -29,7 +65,16 @@ module Scrolls
29
65
  end
30
66
  end
31
67
 
68
+ # Deprecated: Get or set a global context that prefixs all logs
69
+ #
70
+ # data - A hash of key/values to prepend to each log
71
+ #
72
+ # This method will be deprecated two releases after 0.3.8.
73
+ # See https://github.com/asenchi/scrolls/releases/tag/v0.3.8
74
+ # for more details.
75
+ #
32
76
  def add_global_context(data)
77
+ $stderr.puts "add_global_context will be deprecated after v0.3.8, please see https://github.com/asenchi/scrolls for more information."
33
78
  Log.add_global_context(data)
34
79
  end
35
80
 
@@ -45,9 +90,9 @@ module Scrolls
45
90
  # => nil
46
91
  #
47
92
  # Scrolls.log(test: "test") { puts "inner block" }
48
- # at=start
93
+ # test=test at=start
49
94
  # inner block
50
- # at=finish elapsed=0.000
95
+ # test=test at=finish elapsed=0.000
51
96
  # => nil
52
97
  #
53
98
  def log(data, &blk)
@@ -191,4 +236,110 @@ module Scrolls
191
236
  Log.single_line_exceptions
192
237
  end
193
238
 
239
+ # Public: Convience method for Logger replacement
240
+ #
241
+ # data - A hash of key/values to log
242
+ # blk - A block to be wrapped by log lines
243
+ #
244
+ # Examples:
245
+ #
246
+ # Scrolls.debug(test: "test")
247
+ # test=test level=debug
248
+ # => nil
249
+ #
250
+ def debug(data, &blk)
251
+ data = data.merge(:level => "debug")
252
+ Log.log(data, &blk)
253
+ end
254
+
255
+ # Public: Convience method for Logger replacement
256
+ #
257
+ # Translates the `level` to Syslog equivalent
258
+ #
259
+ # data - A hash of key/values to log
260
+ # blk - A block to be wrapped by log lines
261
+ #
262
+ # Examples:
263
+ #
264
+ # Scrolls.error(test: "test")
265
+ # test=test level=warning
266
+ # => nil
267
+ #
268
+ def error(data, &blk)
269
+ data = data.merge(:level => "warning")
270
+ Log.log(data, &blk)
271
+ end
272
+
273
+ # Public: Convience method for Logger replacement
274
+ #
275
+ # Translates the `level` to Syslog equivalent
276
+ #
277
+ # data - A hash of key/values to log
278
+ # blk - A block to be wrapped by log lines
279
+ #
280
+ # Examples:
281
+ #
282
+ # Scrolls.fatal(test: "test")
283
+ # test=test level=error
284
+ # => nil
285
+ #
286
+ def fatal(data, &blk)
287
+ data = data.merge(:level => "error")
288
+ Log.log(data, &blk)
289
+ end
290
+
291
+ # Public: Convience method for Logger replacement
292
+ #
293
+ # Translates the `level` to Syslog equivalent
294
+ #
295
+ # data - A hash of key/values to log
296
+ # blk - A block to be wrapped by log lines
297
+ #
298
+ # Examples:
299
+ #
300
+ # Scrolls.info(test: "test")
301
+ # test=test level=info
302
+ # => nil
303
+ #
304
+ def info(data, &blk)
305
+ data = data.merge(:level => "info")
306
+ Log.log(data, &blk)
307
+ end
308
+
309
+ # Public: Convience method for Logger replacement
310
+ #
311
+ # Translates the `level` to Syslog equivalent
312
+ #
313
+ # data - A hash of key/values to log
314
+ # blk - A block to be wrapped by log lines
315
+ #
316
+ # Examples:
317
+ #
318
+ # Scrolls.warn(test: "test")
319
+ # test=test level=notice
320
+ # => nil
321
+ #
322
+ def warn(data, &blk)
323
+ data = data.merge(:level => "notice")
324
+ Log.log(data, &blk)
325
+ end
326
+
327
+ # Public: Convience method for Logger replacement
328
+ #
329
+ # Translates the `level` to Syslog equivalent
330
+ #
331
+ # data - A hash of key/values to log
332
+ # blk - A block to be wrapped by log lines
333
+ #
334
+ # Examples:
335
+ #
336
+ # Scrolls.unknown(test: "test")
337
+ # test=test level=alert
338
+ # => nil
339
+ #
340
+ def unknown(data, &blk)
341
+ data = data.merge(:level => "alert")
342
+ Log.log(data, &blk)
343
+ end
344
+
194
345
  end
@@ -12,7 +12,7 @@ module Scrolls
12
12
  extend Parser
13
13
  extend Utils
14
14
 
15
- LOG_LEVEL = (ENV['LOG_LEVEL'] || 3).to_i
15
+ LOG_LEVEL = (ENV['LOG_LEVEL'] || 6).to_i
16
16
  LOG_LEVEL_MAP = {
17
17
  "emergency" => 0,
18
18
  "alert" => 1,
@@ -1,3 +1,3 @@
1
1
  module Scrolls
2
- VERSION = "0.3.6"
2
+ VERSION = "0.3.7"
3
3
  end
@@ -24,14 +24,16 @@ class TestScrolls < Test::Unit::TestCase
24
24
  def test_setting_global_context
25
25
  Scrolls.global_context(:g => "g")
26
26
  Scrolls.log(:d => "d")
27
- assert_equal "g=g d=d\n", @out.string
27
+ global = @out.string.gsub("\n", 'XX')
28
+ assert_match /g=g.*d=d/, global
28
29
  end
29
30
 
30
31
  def test_adding_to_global_context
31
32
  Scrolls.global_context(:g => "g")
32
33
  Scrolls.add_global_context(:h => "h")
33
34
  Scrolls.log(:d => "d")
34
- assert_equal "g=g h=h d=d\n", @out.string
35
+ global = @out.string.gsub("\n", 'XX')
36
+ assert_match /g=g.*h=h.*d=d/, global
35
37
  end
36
38
 
37
39
  def test_default_context
@@ -53,9 +55,8 @@ class TestScrolls < Test::Unit::TestCase
53
55
  end
54
56
  Scrolls.log(:i => "i")
55
57
  end
56
- @out.truncate(37)
57
- output = "g=g o=o at=start\ng=g c=c ic=i\ng=g i=i"
58
- assert_equal output, @out.string
58
+ global = @out.string.gsub("\n", 'XX')
59
+ assert_match /g=g.*at=start.*i=i/, global
59
60
  end
60
61
 
61
62
  def test_deeply_nested_context
@@ -175,4 +176,32 @@ class TestScrolls < Test::Unit::TestCase
175
176
  Scrolls.log("string")
176
177
  assert_equal "log_message=string\n", @out.string
177
178
  end
179
+
180
+ def test_default_logging_levels
181
+ Scrolls.debug(:t => "t")
182
+ assert_equal "", @out.string
183
+ Scrolls.info(:t => "t")
184
+ assert_equal "t=t level=info\n", @out.string
185
+ end
186
+
187
+ def test_level_translation_error
188
+ Scrolls.error(:t => "t")
189
+ assert_equal "t=t level=warning\n", @out.string
190
+ end
191
+
192
+ def test_level_translation_fatal
193
+ Scrolls.fatal(:t => "t")
194
+ assert_equal "t=t level=error\n", @out.string
195
+ end
196
+
197
+ def test_level_translation_warn
198
+ Scrolls.warn(:t => "t")
199
+ assert_equal "t=t level=notice\n", @out.string
200
+ end
201
+
202
+ def test_level_translation_unknown
203
+ Scrolls.unknown(:t => "t")
204
+ assert_equal "t=t level=alert\n", @out.string
205
+ end
206
+
178
207
  end
metadata CHANGED
@@ -1,15 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: scrolls
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.6
5
- prerelease:
4
+ version: 0.3.7
6
5
  platform: ruby
7
6
  authors:
8
7
  - Curt Micol
9
8
  autorequire:
10
9
  bindir: bin
11
10
  cert_chain: []
12
- date: 2014-01-23 00:00:00.000000000 Z
11
+ date: 2014-02-10 00:00:00.000000000 Z
13
12
  dependencies: []
14
13
  description: Logging, easier, more consistent.
15
14
  email:
@@ -18,11 +17,12 @@ executables: []
18
17
  extensions: []
19
18
  extra_rdoc_files: []
20
19
  files:
21
- - .gitignore
20
+ - ".gitignore"
22
21
  - Gemfile
23
22
  - LICENSE
24
23
  - README.md
25
24
  - Rakefile
25
+ - docs/global-context.md
26
26
  - docs/syslog.md
27
27
  - lib/scrolls.rb
28
28
  - lib/scrolls/atomic.rb
@@ -39,27 +39,26 @@ files:
39
39
  homepage: https://github.com/asenchi/scrolls
40
40
  licenses:
41
41
  - MIT
42
+ metadata: {}
42
43
  post_install_message:
43
44
  rdoc_options: []
44
45
  require_paths:
45
46
  - lib
46
47
  required_ruby_version: !ruby/object:Gem::Requirement
47
- none: false
48
48
  requirements:
49
- - - ! '>='
49
+ - - ">="
50
50
  - !ruby/object:Gem::Version
51
51
  version: '0'
52
52
  required_rubygems_version: !ruby/object:Gem::Requirement
53
- none: false
54
53
  requirements:
55
- - - ! '>='
54
+ - - ">="
56
55
  - !ruby/object:Gem::Version
57
56
  version: '0'
58
57
  requirements: []
59
58
  rubyforge_project:
60
- rubygems_version: 1.8.23
59
+ rubygems_version: 2.2.0
61
60
  signing_key:
62
- specification_version: 3
61
+ specification_version: 4
63
62
  summary: When do we log? All the time.
64
63
  test_files:
65
64
  - test/test_atomic.rb