gom-core 0.1.0 → 0.1.1
Sign up to get free protection for your applications and to get access to all the features.
- data/VERSION +1 -1
- data/lib/gom-core.rb +1 -0
- data/lib/gom/log.rb +49 -0
- data/lib/gom/logger.rb +61 -0
- data/spec/gom/logger_spec.rb +30 -0
- data/spec/spec_helper.rb +1 -24
- metadata +6 -2
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.1.
|
1
|
+
0.1.1
|
data/lib/gom-core.rb
CHANGED
data/lib/gom/log.rb
ADDED
@@ -0,0 +1,49 @@
|
|
1
|
+
require 'gom/logger'
|
2
|
+
|
3
|
+
module Gom
|
4
|
+
# GOM default Logger instance
|
5
|
+
Log = Gom::Logger.new
|
6
|
+
|
7
|
+
# TODO: runtime configuration might move to config/initializers/...
|
8
|
+
Log.level = ::Logger::DEBUG
|
9
|
+
end
|
10
|
+
|
11
|
+
__END__
|
12
|
+
|
13
|
+
Log = ::Logger.new case RAILS_ENV
|
14
|
+
when "test"
|
15
|
+
STDOUT
|
16
|
+
else
|
17
|
+
"#{RAILS_ROOT}/log/gom-#{RAILS_ENV}.log"
|
18
|
+
end
|
19
|
+
|
20
|
+
class << Log
|
21
|
+
# this is to de-patch the rails formatting patch..
|
22
|
+
def format_message(severity, timestamp, progname, msg)
|
23
|
+
"#{timestamp.to_formatted_s(:db)} #{severity.first} #{msg}\n"
|
24
|
+
end
|
25
|
+
|
26
|
+
# experimental convenience function:
|
27
|
+
#
|
28
|
+
# Log.ex e
|
29
|
+
#
|
30
|
+
# does actually do:
|
31
|
+
# Log.error e
|
32
|
+
# Log.debug "#{e.backtrace.join "\n\t"}"
|
33
|
+
#
|
34
|
+
# and:
|
35
|
+
# Log.ex e, "some message here"
|
36
|
+
#
|
37
|
+
# stands for:
|
38
|
+
# Log.error "some message here"
|
39
|
+
# Log.debug "#{e.backtrace.join "\n\t"}"
|
40
|
+
#
|
41
|
+
def ex e, msg = nil, level = :error
|
42
|
+
send level, (msg || e)
|
43
|
+
debug "#{e} -- error was: #{msg}\n\t#{e.backtrace.join "\n\t"}"
|
44
|
+
end
|
45
|
+
end
|
46
|
+
|
47
|
+
# TODO: runtime configuration might move to config/initializers/...
|
48
|
+
Log.level = ::Logger::DEBUG
|
49
|
+
end
|
data/lib/gom/logger.rb
ADDED
@@ -0,0 +1,61 @@
|
|
1
|
+
require 'logger'
|
2
|
+
|
3
|
+
module Gom
|
4
|
+
|
5
|
+
class Logger < ::Logger
|
6
|
+
|
7
|
+
#Gom::Log.level = Gom::Attribute.value("/gom/log:level", ::Logger::INFO)
|
8
|
+
|
9
|
+
Levels = {
|
10
|
+
"debug" => ::Logger::DEBUG,
|
11
|
+
"info" => ::Logger::INFO,
|
12
|
+
"warn" => ::Logger::WARN,
|
13
|
+
"error" => ::Logger::ERROR,
|
14
|
+
"fatal" => ::Logger::FATAL,
|
15
|
+
}
|
16
|
+
|
17
|
+
# output defaults to STDOUT for rails test and non-rails apps, to a
|
18
|
+
# logfile otherwise
|
19
|
+
#
|
20
|
+
DEFAULT_OUT = begin
|
21
|
+
if (RAILS_ROOT.nil? rescue true)
|
22
|
+
STDOUT
|
23
|
+
else
|
24
|
+
if 'test' === RAILS_ENV
|
25
|
+
STDOUT
|
26
|
+
else
|
27
|
+
"#{RAILS_ROOT}/log/gom-#{RAILS_ENV}.log"
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
def initialize out = DEFAULT_OUT
|
33
|
+
super out
|
34
|
+
end
|
35
|
+
|
36
|
+
# this is to de-patch the rails formatting patch..
|
37
|
+
def format_message(severity, timestamp, progname, msg)
|
38
|
+
"#{timestamp.strftime '%Y-%m-%d %H:%M:%S'} #{severity[0,1]} #{msg}\n"
|
39
|
+
end
|
40
|
+
|
41
|
+
# experimental convenience function:
|
42
|
+
#
|
43
|
+
# Log.ex e
|
44
|
+
#
|
45
|
+
# does actually do:
|
46
|
+
# Log.error e
|
47
|
+
# Log.debug "#{e.backtrace.join "\n\t"}"
|
48
|
+
#
|
49
|
+
# and:
|
50
|
+
# Log.ex e, "some message here"
|
51
|
+
#
|
52
|
+
# stands for:
|
53
|
+
# Log.error "some message here"
|
54
|
+
# Log.debug "#{e.backtrace.join "\n\t"}"
|
55
|
+
#
|
56
|
+
def ex e, msg = nil, level = :error
|
57
|
+
send level, "#{e}: #{(msg || e)}"
|
58
|
+
debug "#{e} -- callstack: #{msg}\n\t#{e.backtrace.join "\n\t"}"
|
59
|
+
end
|
60
|
+
end
|
61
|
+
end
|
@@ -0,0 +1,30 @@
|
|
1
|
+
require File.dirname(__FILE__)+'/../spec_helper'
|
2
|
+
|
3
|
+
describe Gom::Logger do
|
4
|
+
it "should find the class" do
|
5
|
+
Gom::Logger.should_not == nil
|
6
|
+
end
|
7
|
+
|
8
|
+
describe "with a Logger" do
|
9
|
+
before :each do
|
10
|
+
require 'tempfile'
|
11
|
+
@logfile = Tempfile.new self
|
12
|
+
@log = Gom::Logger.new @logfile.path
|
13
|
+
end
|
14
|
+
|
15
|
+
it "should have a default 'I' log level" do
|
16
|
+
@log.info self.to_s
|
17
|
+
(line = @logfile.read).should_not == nil
|
18
|
+
line.should =~ / I #{self.to_s}/
|
19
|
+
end
|
20
|
+
|
21
|
+
it "should log execeptions" do
|
22
|
+
raise "foo" rescue @log.ex $!, "bar"
|
23
|
+
(txt = @logfile.read).should_not == nil
|
24
|
+
|
25
|
+
#assert_match " E RuntimeError: bar", txt, @logfile.path
|
26
|
+
txt.should =~ / E foo: bar/
|
27
|
+
txt.should =~ / D foo -- callstack: bar/
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
data/spec/spec_helper.rb
CHANGED
@@ -1,32 +1,9 @@
|
|
1
|
-
# figure out where we are being loaded from
|
2
|
-
if $LOADED_FEATURES.grep(/spec\/spec_helper\.rb/).any?
|
3
|
-
begin
|
4
|
-
raise "foo"
|
5
|
-
rescue => e
|
6
|
-
puts <<-MSG
|
7
|
-
===================================================
|
8
|
-
It looks like spec_helper.rb has been loaded
|
9
|
-
multiple times. Normalize the require to:
|
10
|
-
|
11
|
-
require "spec/spec_helper"
|
12
|
-
|
13
|
-
Things like File.join and File.expand_path will
|
14
|
-
cause it to be loaded multiple times.
|
15
|
-
|
16
|
-
Loaded this time from:
|
17
|
-
|
18
|
-
#{e.backtrace.join("\n ")}
|
19
|
-
===================================================
|
20
|
-
MSG
|
21
|
-
end
|
22
|
-
end
|
23
|
-
|
24
1
|
$LOAD_PATH.unshift(File.dirname(__FILE__))
|
25
2
|
$LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
|
26
3
|
require 'spec'
|
27
4
|
require 'spec/autorun'
|
28
5
|
|
29
|
-
require 'gom
|
6
|
+
require 'gom-core'
|
30
7
|
|
31
8
|
Spec::Runner.configure do |config|
|
32
9
|
config.before :each do
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: gom-core
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- art+com/dirk luesebrink
|
@@ -9,7 +9,7 @@ autorequire:
|
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
11
|
|
12
|
-
date:
|
12
|
+
date: 2010-02-02 00:00:00 +01:00
|
13
13
|
default_executable:
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
@@ -41,7 +41,10 @@ files:
|
|
41
41
|
- lib/gom-core.rb
|
42
42
|
- lib/gom/core.rb
|
43
43
|
- lib/gom/core/primitive.rb
|
44
|
+
- lib/gom/log.rb
|
45
|
+
- lib/gom/logger.rb
|
44
46
|
- spec/gom/core/primitive_spec.rb
|
47
|
+
- spec/gom/logger_spec.rb
|
45
48
|
- spec/spec.opts
|
46
49
|
- spec/spec_helper.rb
|
47
50
|
has_rdoc: true
|
@@ -74,4 +77,5 @@ specification_version: 3
|
|
74
77
|
summary: basic GOM functionallity
|
75
78
|
test_files:
|
76
79
|
- spec/gom/core/primitive_spec.rb
|
80
|
+
- spec/gom/logger_spec.rb
|
77
81
|
- spec/spec_helper.rb
|