cabin 0.1.5 → 0.1.6
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGELIST +9 -0
- data/lib/cabin/channel.rb +2 -2
- data/lib/cabin/mixins/dragons.rb +34 -0
- data/lib/cabin/{logger.rb → mixins/logger.rb} +2 -2
- data/lib/cabin/namespace.rb +1 -0
- data/lib/cabin/outputs/em-stdlib-logger.rb +39 -0
- data/lib/test.rb +8 -0
- metadata +60 -38
data/CHANGELIST
CHANGED
@@ -1,3 +1,12 @@
|
|
1
|
+
v0.1.6 (2011-11-07)
|
2
|
+
- Add 'Dragons' mixin for times when info/debug/fatal log levels don't cut it
|
3
|
+
and you'd rather deal in D&D alignments instead.
|
4
|
+
- Add Cabin::Outputs::EmStdlibLogger which wraps ruby's stdlib logger but in
|
5
|
+
a way smartly usable with EventMachine. (Contributed by Sean Porter)
|
6
|
+
- Moved mixins to Cabin::Mixins like Logger and the new Dragon mixin.
|
7
|
+
|
8
|
+
v0.1.3 through v0.1.5 were not documented here. Sad.
|
9
|
+
|
1
10
|
v0.1.2 (2011-10-12)
|
2
11
|
- Added file+line+method context if the logger level is debug
|
3
12
|
|
data/lib/cabin/channel.rb
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
require "cabin/logger"
|
1
|
+
require "cabin/mixins/logger"
|
2
2
|
require "cabin/namespace"
|
3
3
|
require "cabin/timer"
|
4
4
|
require "cabin/context"
|
@@ -43,7 +43,7 @@ require "logger"
|
|
43
43
|
# I, [2011-10-11T01:00:57.993575 #1209] INFO -- : {:timestamp=>"2011-10-11T01:00:57.993517-0700", :message=>"Done in foo", :level=>:info}
|
44
44
|
#
|
45
45
|
class Cabin::Channel
|
46
|
-
include Cabin::Logger
|
46
|
+
include Cabin::Mixins::Logger
|
47
47
|
|
48
48
|
# Create a new logging channel.
|
49
49
|
# The default log level is 'info'
|
@@ -0,0 +1,34 @@
|
|
1
|
+
require "cabin/namespace"
|
2
|
+
|
3
|
+
# An experiment to use AD&D-style log levels, because why not? 'info' and
|
4
|
+
# 'fatal' and other log levels are pretty lame anyway.
|
5
|
+
#
|
6
|
+
# Plus, now you can 'include Dragons' in your logger, which means it
|
7
|
+
# has +2 against Knights and a special fire breathing attack..
|
8
|
+
module Cabin::Mixins::Dragons
|
9
|
+
orders = %w(lawful ambivalent chaotic)
|
10
|
+
desires = %w(good neutral evil)
|
11
|
+
|
12
|
+
orders.each do |order|
|
13
|
+
desires.each do |desire|
|
14
|
+
# alignment will be like 'lawful_good' etc
|
15
|
+
alignment = "#{order} #{desire}"
|
16
|
+
define_method(alignment.gsub(" ", "_")) do |message, data={}|
|
17
|
+
log(alignment, message, data)
|
18
|
+
end
|
19
|
+
end # desires
|
20
|
+
end # orders
|
21
|
+
|
22
|
+
private
|
23
|
+
def log(alignment, message, data={})
|
24
|
+
# Invoke 'info?' etc to ask if we should act.
|
25
|
+
if message.is_a?(Hash)
|
26
|
+
data.merge!(message)
|
27
|
+
else
|
28
|
+
data[:message] = message
|
29
|
+
end
|
30
|
+
|
31
|
+
data[:alignment] = alignment
|
32
|
+
publish(data)
|
33
|
+
end # def log
|
34
|
+
end # module Cabin::Dragons
|
@@ -2,7 +2,7 @@ require "cabin/namespace"
|
|
2
2
|
|
3
3
|
# This module implements methods that act somewhat like Ruby's Logger class
|
4
4
|
# It is included in Cabin::Channel
|
5
|
-
module Cabin::Logger
|
5
|
+
module Cabin::Mixins::Logger
|
6
6
|
attr_accessor :level
|
7
7
|
LEVELS = {
|
8
8
|
:fatal => 0,
|
@@ -79,4 +79,4 @@ module Cabin::Logger
|
|
79
79
|
data[:line] = line
|
80
80
|
data[:method] = method
|
81
81
|
end # def debugharder
|
82
|
-
end # module Cabin::Logger
|
82
|
+
end # module Cabin::Mixins::Logger
|
data/lib/cabin/namespace.rb
CHANGED
@@ -0,0 +1,39 @@
|
|
1
|
+
require "cabin"
|
2
|
+
require "json"
|
3
|
+
require "eventmachine"
|
4
|
+
|
5
|
+
# Wrap Ruby stdlib's logger and make it EventMachine friendly. This
|
6
|
+
# allows you to output to a normal ruby logger with Cabin. Since
|
7
|
+
# Ruby's Logger has a love for strings alone, this wrapper will
|
8
|
+
# convert the data/event to json before sending it to Logger.
|
9
|
+
class Cabin::Outputs::EmStdlibLogger
|
10
|
+
public
|
11
|
+
def initialize(logger)
|
12
|
+
@logger_queue = EM::Queue.new
|
13
|
+
@logger = logger
|
14
|
+
consumer # Consume lines from a queue and send them with logger
|
15
|
+
end # def initialize
|
16
|
+
|
17
|
+
def consumer
|
18
|
+
line_sender = Proc.new do |line|
|
19
|
+
# This will call @logger.info(data) or something similar
|
20
|
+
@logger.send(line[:method], line[:message])
|
21
|
+
EM.next_tick do
|
22
|
+
# Do it again
|
23
|
+
@logger_queue.pop(&line_sender)
|
24
|
+
end
|
25
|
+
end
|
26
|
+
# Pop line off queue and send it with logger
|
27
|
+
@logger_queue.pop(&line_sender)
|
28
|
+
end
|
29
|
+
|
30
|
+
# Receive an event
|
31
|
+
public
|
32
|
+
def <<(data)
|
33
|
+
line = Hash.new
|
34
|
+
line[:method] = data[:level] || "info"
|
35
|
+
line[:message] = "#{data[:message]} #{data.to_json}"
|
36
|
+
# Push line onto queue for later sending
|
37
|
+
@logger_queue.push(line)
|
38
|
+
end # def <<
|
39
|
+
end # class Cabin::Outputs::EmStdlibLogger
|
data/lib/test.rb
ADDED
metadata
CHANGED
@@ -1,75 +1,97 @@
|
|
1
|
-
--- !ruby/object:Gem::Specification
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
2
|
name: cabin
|
3
|
-
version: !ruby/object:Gem::Version
|
4
|
-
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
hash: 23
|
5
5
|
prerelease:
|
6
|
+
segments:
|
7
|
+
- 0
|
8
|
+
- 1
|
9
|
+
- 6
|
10
|
+
version: 0.1.6
|
6
11
|
platform: ruby
|
7
|
-
authors:
|
12
|
+
authors:
|
8
13
|
- Jordan Sissel
|
9
14
|
autorequire:
|
10
15
|
bindir: bin
|
11
16
|
cert_chain: []
|
12
|
-
|
13
|
-
|
14
|
-
|
17
|
+
|
18
|
+
date: 2011-11-08 00:00:00 Z
|
19
|
+
dependencies:
|
20
|
+
- !ruby/object:Gem::Dependency
|
15
21
|
name: json
|
16
|
-
|
22
|
+
prerelease: false
|
23
|
+
requirement: &id001 !ruby/object:Gem::Requirement
|
17
24
|
none: false
|
18
|
-
requirements:
|
19
|
-
- -
|
20
|
-
- !ruby/object:Gem::Version
|
21
|
-
|
25
|
+
requirements:
|
26
|
+
- - ">="
|
27
|
+
- !ruby/object:Gem::Version
|
28
|
+
hash: 3
|
29
|
+
segments:
|
30
|
+
- 0
|
31
|
+
version: "0"
|
22
32
|
type: :runtime
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
consumable. Plain text logs are bullshit, let's emit structured and contextual logs.
|
27
|
-
email:
|
33
|
+
version_requirements: *id001
|
34
|
+
description: This is an experiment to try and make logging more flexible and more consumable. Plain text logs are bullshit, let's emit structured and contextual logs.
|
35
|
+
email:
|
28
36
|
- jls@semicomplete.com
|
29
|
-
executables:
|
37
|
+
executables:
|
30
38
|
- rubygems-cabin-test
|
31
39
|
extensions: []
|
40
|
+
|
32
41
|
extra_rdoc_files: []
|
33
|
-
|
34
|
-
|
42
|
+
|
43
|
+
files:
|
44
|
+
- lib/test.rb
|
45
|
+
- lib/cabin/context.rb
|
46
|
+
- lib/cabin/timer.rb
|
35
47
|
- lib/cabin/outputs/stdlib-logger.rb
|
36
|
-
- lib/cabin/
|
48
|
+
- lib/cabin/outputs/em-stdlib-logger.rb
|
49
|
+
- lib/cabin/mixins/logger.rb
|
50
|
+
- lib/cabin/mixins/dragons.rb
|
37
51
|
- lib/cabin/namespace.rb
|
38
|
-
- lib/cabin/
|
39
|
-
- lib/cabin
|
40
|
-
- lib/cabin/logger.rb
|
52
|
+
- lib/cabin/channel.rb
|
53
|
+
- lib/cabin.rb
|
41
54
|
- examples/fibonacci-timing.rb
|
42
55
|
- examples/sinatra-logging.rb
|
43
56
|
- examples/sample.rb
|
44
|
-
- test/minitest-patch.rb
|
45
57
|
- test/test_logging.rb
|
58
|
+
- test/minitest-patch.rb
|
46
59
|
- LICENSE
|
47
60
|
- CHANGELIST
|
48
61
|
- bin/rubygems-cabin-test
|
49
62
|
homepage: https://github.com/jordansissel/ruby-cabin
|
50
|
-
licenses:
|
63
|
+
licenses:
|
51
64
|
- Apache License (2.0)
|
52
65
|
post_install_message:
|
53
66
|
rdoc_options: []
|
54
|
-
|
67
|
+
|
68
|
+
require_paths:
|
55
69
|
- lib
|
56
70
|
- lib
|
57
|
-
required_ruby_version: !ruby/object:Gem::Requirement
|
71
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
58
72
|
none: false
|
59
|
-
requirements:
|
60
|
-
- -
|
61
|
-
- !ruby/object:Gem::Version
|
62
|
-
|
63
|
-
|
73
|
+
requirements:
|
74
|
+
- - ">="
|
75
|
+
- !ruby/object:Gem::Version
|
76
|
+
hash: 3
|
77
|
+
segments:
|
78
|
+
- 0
|
79
|
+
version: "0"
|
80
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
64
81
|
none: false
|
65
|
-
requirements:
|
66
|
-
- -
|
67
|
-
- !ruby/object:Gem::Version
|
68
|
-
|
82
|
+
requirements:
|
83
|
+
- - ">="
|
84
|
+
- !ruby/object:Gem::Version
|
85
|
+
hash: 3
|
86
|
+
segments:
|
87
|
+
- 0
|
88
|
+
version: "0"
|
69
89
|
requirements: []
|
90
|
+
|
70
91
|
rubyforge_project:
|
71
|
-
rubygems_version: 1.
|
92
|
+
rubygems_version: 1.7.2
|
72
93
|
signing_key:
|
73
94
|
specification_version: 3
|
74
95
|
summary: Experiments in structured and contextual logging
|
75
96
|
test_files: []
|
97
|
+
|