cabin 0.1.3 → 0.1.5

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.
@@ -0,0 +1,5 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "minitest/autorun"
4
+ test_dir = File.join(File.dirname(__FILE__), "..", "test")
5
+ load File.join(test_dir, "test_logging.rb")
data/lib/cabin/context.rb CHANGED
@@ -11,6 +11,11 @@ require "cabin/namespace"
11
11
  # context.clear
12
12
  # channel.info("Sample log 2") # context cleared, key "foo" removed.
13
13
  #
14
+ # Essentially, a Cabin::Context acts as a transactional proxy on top of a
15
+ # Cabin::Channel. Any changes you make in a context are passed through to
16
+ # the channel while keeping an ordered record of the changes made so
17
+ # you can unroll those changes when the context is no longer needed..
18
+ #
14
19
  class Cabin::Context
15
20
  def initialize(channel)
16
21
  @changes = []
data/lib/cabin/logger.rb CHANGED
@@ -1,5 +1,4 @@
1
1
  require "cabin/namespace"
2
- require "ap"
3
2
 
4
3
  # This module implements methods that act somewhat like Ruby's Logger class
5
4
  # It is included in Cabin::Channel
@@ -19,11 +18,21 @@ module Cabin::Logger
19
18
 
20
19
  # Define the usual log methods: info, fatal, etc.
21
20
  # Each level-based method accepts both a message and a hash data.
21
+ #
22
+ # This will define methods such as 'fatal' and 'fatal?' for each
23
+ # of: fatal, error, warn, info, debug
24
+ #
25
+ # The first method type (ie Cabin::Channel#fatal) is what logs, and it takes a
26
+ # message and an optional Hash with context.
27
+ #
28
+ # The second method type (ie; Cabin::Channel#fatal?) returns true if
29
+ # fatal logs are being emitted, false otherwise.
22
30
  %w(fatal error warn info debug).each do |level|
23
31
  level = level.to_sym
24
32
  predicate = "#{level}?".to_sym
25
33
 
26
34
  # def info, def warn, etc...
35
+
27
36
  define_method(level) do |message, data={}|
28
37
  log(level, message, data) if send(predicate)
29
38
  end
@@ -50,8 +59,10 @@ module Cabin::Logger
50
59
 
51
60
  data[:level] = level
52
61
  publish(data)
53
- end # def info, def warn ...
62
+ end # def log
54
63
 
64
+ # This method is used to pull useful information about the caller
65
+ # of the logging method such as the caller's file, method, and line number.
55
66
  private
56
67
  def debugharder(callstack, data)
57
68
  path, line, method = callstack[1].split(/(?::in `|:|')/)
@@ -63,7 +74,6 @@ module Cabin::Logger
63
74
  # We get here if the path is not in $:
64
75
  file = path
65
76
  end
66
- who = "#{file}:#{line}##{method}"
67
77
 
68
78
  data[:file] = file
69
79
  data[:line] = line
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: cabin
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.3
4
+ version: 0.1.5
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,11 +9,11 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2011-10-12 00:00:00.000000000Z
12
+ date: 2011-10-28 00:00:00.000000000Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: json
16
- requirement: &22224480 !ruby/object:Gem::Requirement
16
+ requirement: &7463400 !ruby/object:Gem::Requirement
17
17
  none: false
18
18
  requirements:
19
19
  - - ! '>='
@@ -21,12 +21,13 @@ dependencies:
21
21
  version: '0'
22
22
  type: :runtime
23
23
  prerelease: false
24
- version_requirements: *22224480
24
+ version_requirements: *7463400
25
25
  description: This is an experiment to try and make logging more flexible and more
26
26
  consumable. Plain text logs are bullshit, let's emit structured and contextual logs.
27
27
  email:
28
28
  - jls@semicomplete.com
29
- executables: []
29
+ executables:
30
+ - rubygems-cabin-test
30
31
  extensions: []
31
32
  extra_rdoc_files: []
32
33
  files:
@@ -44,6 +45,7 @@ files:
44
45
  - test/test_logging.rb
45
46
  - LICENSE
46
47
  - CHANGELIST
48
+ - bin/rubygems-cabin-test
47
49
  homepage: https://github.com/jordansissel/ruby-cabin
48
50
  licenses:
49
51
  - Apache License (2.0)