slf4r 0.1.1 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
data/History.txt CHANGED
@@ -1,6 +1,6 @@
1
1
  === 0.1.1 / 2008-12-19
2
2
 
3
- * fixed printout of backtrace
3
+ * fixed printoout of backtrace
4
4
 
5
5
  * added log methods for ruby_logger_adapter
6
6
 
data/Manifest.txt CHANGED
@@ -7,10 +7,18 @@ lib/logging_adapter.rb
7
7
  lib/ruby_logger_adapter.rb
8
8
  lib/slf4r.rb
9
9
  lib/slf4r/abstract_logger_facade.rb
10
+ lib/slf4r/log4r_logger.rb
10
11
  lib/slf4r/logger.rb
11
12
  lib/slf4r/logging_logger.rb
12
13
  lib/slf4r/noop_logger.rb
13
14
  lib/slf4r/ruby_logger.rb
14
15
  lib/slf4r/version.rb
15
16
  lib/slf4r/wrapped_logger.rb
16
- test/test_slf4r.rb
17
+ load.rb
18
+ spec/log4r_logger_spec.rb
19
+ spec/logger_helper.rb
20
+ spec/logging_logger_spec.rb
21
+ spec/ruby_logger_spec.rb
22
+ spec/spec.opts
23
+ spec/spec_helper.rb
24
+ spec/wrapper_logger_spec.rb
data/README.txt CHANGED
@@ -39,7 +39,6 @@ appender.layout = Logging::Layouts::Pattern.new(:pattern => "%d [%-l] (%c) %m\n"
39
39
  logger = Logging::Logger.new(:root)
40
40
  logger.add_appenders(appender)
41
41
  logger.level = :debug
42
- logger.info "initialized logger . . ."
43
42
 
44
43
  === using with ruby logger
45
44
 
@@ -51,9 +50,9 @@ require 'log4r_adapter'
51
50
 
52
51
  === using with rails/merb/datamapper logger
53
52
 
54
- require 'slf4r/wrappered_logger'
53
+ require 'slf4r/wrapped_logger'
55
54
 
56
- LoggerFacade4WrappedLogger.logger(framwork_logger)
55
+ Slf4r::LoggerFacade4WrappedLogger.logger = framwork_logger
57
56
 
58
57
  === getting an instance of a logger
59
58
 
data/Rakefile CHANGED
@@ -4,6 +4,10 @@ require 'rubygems'
4
4
  require 'hoe'
5
5
  require './lib/slf4r/version.rb'
6
6
 
7
+ require 'spec'
8
+ require 'spec/rake/spectask'
9
+ require 'pathname'
10
+
7
11
  Hoe.new('slf4r', Slf4r::VERSION) do |p|
8
12
  p.rubyforge_name = 'slf4r' # if different than lowercase project name
9
13
  p.summary = 'Slf4r provides a uniform interface for instantiating und using of a logger'
@@ -15,8 +19,19 @@ end
15
19
 
16
20
  desc 'Install the package as a gem.'
17
21
  task :install => [:clean, :package] do
22
+ Dir.new('tmp').each do |f|
23
+ File.delete('tmp/' + f) if File.file?('tmp/' + f)
24
+ end
18
25
  gem = Dir['pkg/*.gem'].first
19
26
  sh "gem install --local #{gem} --no-ri --no-rdoc"
20
27
  end
21
28
 
29
+ desc 'Run specifications'
30
+ Spec::Rake::SpecTask.new(:spec) do |t|
31
+ if File.exists?('spec/spec.opts')
32
+ t.spec_opts << '--options' << 'spec/spec.opts'
33
+ end
34
+ t.spec_files = Pathname.glob('./spec/**/*_spec.rb')
35
+ end
36
+
22
37
  # vim: syntax=Ruby
@@ -4,7 +4,7 @@ module Slf4r
4
4
  protected
5
5
 
6
6
  def format(exception)
7
- ": #{exception.message}:\n\t#{exception.backtrace.join("\n\t")}" if exception
7
+ (": #{exception.message}:\n\t#{exception.backtrace.join("\n\t") if exception.backtrace }") if exception
8
8
  end
9
9
 
10
10
  def _debug(msg)
@@ -0,0 +1,49 @@
1
+ require 'log4r'
2
+ require 'slf4r/abstract_logger_facade'
3
+
4
+ module Slf4r
5
+ class LoggerFacade < AbstractLoggerFacade
6
+
7
+ attr_reader :logger
8
+
9
+ def initialize(name)
10
+ super
11
+ @logger = ::Log4r::Logger::Repository[name] || ::Log4r::Logger.new(name)
12
+ end
13
+
14
+ public
15
+
16
+ def debug?
17
+ @logger.level == 0
18
+ end
19
+
20
+ def _debug(msg)
21
+ @logger.debug(msg)
22
+ end
23
+
24
+ def info?
25
+ @logger.level <= 1
26
+ end
27
+
28
+ def _info(msg)
29
+ @logger.info(msg)
30
+ end
31
+
32
+ def warn?
33
+ @logger.level <= 2
34
+ end
35
+
36
+ def _warn(msg)
37
+ @logger.warn(msg)
38
+ end
39
+
40
+ def error?
41
+ @logger.level <= 3
42
+ end
43
+
44
+ def _error(msg)
45
+ @logger.error(msg)
46
+ end
47
+
48
+ end
49
+ end
data/lib/slf4r/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Slf4r
2
- VERSION = '0.1.1'
2
+ VERSION = '0.2.0'
3
3
  end
@@ -1,4 +1,4 @@
1
- require 'abstract_logger_facade'
1
+ require 'slf4r/abstract_logger_facade'
2
2
  module Slf4r
3
3
  class LoggerFacade4WrappedLogger
4
4
 
data/lib/slf4r.rb CHANGED
@@ -5,4 +5,4 @@ dir = Pathname(__FILE__).dirname.expand_path + 'slf4r'
5
5
 
6
6
  require dir + 'version'
7
7
  require dir + 'logger'
8
-
8
+ require dir + 'ruby_logger'
data/load.rb ADDED
@@ -0,0 +1,7 @@
1
+ require 'rubygems'
2
+ require 'slf4j'
3
+ # require 'slf4j/simple'
4
+
5
+ p java.lang.System.getProperty("java.class.path")
6
+ log = SLF4J[ "my.app.logger" ]
7
+ log.info "Hello World!"
@@ -0,0 +1,22 @@
1
+ require 'pathname'
2
+ require Pathname(__FILE__).dirname.expand_path + 'logger_helper'
3
+
4
+ Object.class_eval do
5
+ remove_const :Slf4r
6
+ end
7
+
8
+ basedir = Pathname(__FILE__).dirname.parent.expand_path
9
+ load basedir + 'lib' + 'slf4r' + 'abstract_logger_facade.rb'
10
+ load basedir + 'lib' + 'slf4r' + 'log4r_logger.rb'
11
+ require 'slf4r/log4r_logger'
12
+
13
+ Log4r::Logger.root.level = Log4r::DEBUG
14
+
15
+ out = Log4r::FileOutputter.new('logfile',
16
+ :filename => (basedir + 'tmp' + 'log4r.txt').to_s,
17
+ :trunc=>false,
18
+ :level => Log4r::DEBUG)
19
+ logger = Log4r::Logger.new("log4r")
20
+ logger.add('logfile')
21
+
22
+ behave_as_logger(Slf4r::LoggerFacade.new('log4r'))
@@ -0,0 +1,66 @@
1
+ require 'pathname'
2
+ require Pathname(__FILE__).dirname.expand_path + 'spec_helper'
3
+ def Slf4r.flush(klass)
4
+ remove_const(klass.to_sym) if const_defined? klass.to_sym
5
+ end
6
+
7
+ def behave_as_logger(logger)
8
+ filename = logger.name
9
+ describe logger.name do
10
+
11
+ it 'should have a name' do
12
+ logger.name.should == filename
13
+ logger.name.should_not be_nil
14
+ end
15
+
16
+ it 'should log into a file - no method args' do
17
+ len1 = File2String.new("tmp/#{filename}.txt").length
18
+ logger.debug()
19
+ len2 = File2String.new("tmp/#{filename}.txt").length
20
+ len2.should > len1
21
+ logger.info()
22
+ len1 = File2String.new("tmp/#{filename}.txt").length
23
+ len1.should > len2
24
+ logger.warn()
25
+ len2 = File2String.new("tmp/#{filename}.txt").length
26
+ len2.should > len1
27
+ logger.error()
28
+ len1 = File2String.new("tmp/#{filename}.txt").length
29
+ len1.should > len2
30
+ end
31
+
32
+ it 'should log into a file - via block' do
33
+ len1 = File2String.new("tmp/#{filename}.txt").length
34
+ logger.debug{}
35
+ len2 = File2String.new("tmp/#{filename}.txt").length
36
+ len2.should > len1
37
+ logger.info{}
38
+ len1 = File2String.new("tmp/#{filename}.txt").length
39
+ len1.should > len2
40
+ logger.warn{}
41
+ len2 = File2String.new("tmp/#{filename}.txt").length
42
+ len2.should > len1
43
+ logger.error{}
44
+ len1 = File2String.new("tmp/#{filename}.txt").length
45
+ len1.should > len2
46
+ end
47
+
48
+ it 'should log into a file - exception' do
49
+ exception = StandardError.new
50
+ len1 = File2String.new("tmp/#{filename}.txt").length
51
+ logger.debug{[nil,exception]}
52
+ len2 = File2String.new("tmp/#{filename}.txt").length
53
+ len2.should > len1
54
+ logger.info{[nil,exception]}
55
+ len1 = File2String.new("tmp/#{filename}.txt").length
56
+ len1.should > len2
57
+ logger.warn{[nil,exception]}
58
+ len2 = File2String.new("tmp/#{filename}.txt").length
59
+ len2.should > len1
60
+ logger.error{[nil,exception]}
61
+ len1 = File2String.new("tmp/#{filename}.txt").length
62
+ len1.should > len2
63
+ end
64
+
65
+ end
66
+ end
@@ -0,0 +1,16 @@
1
+ require 'pathname'
2
+ require Pathname(__FILE__).dirname.expand_path + 'logger_helper'
3
+
4
+ basedir = Pathname(__FILE__).dirname.parent.expand_path
5
+ load basedir + 'lib' + 'slf4r' + 'logging_logger.rb'
6
+ require 'slf4r/logging_logger'
7
+
8
+ Logging.init :debug, :info, :warn, :error
9
+
10
+ appender = Logging::Appenders::File.new("test", :filename => basedir + 'tmp' + 'logging.txt' )
11
+ #appender.layout = Logging::Layouts::Pattern.new(:pattern => "%d [%-l] (%c) %m\n")
12
+ logger = Logging::Logger.new(:root)
13
+ logger.add_appenders(appender)
14
+ logger.level = :debug
15
+
16
+ behave_as_logger(Slf4r::LoggerFacade.new('logging'))
@@ -0,0 +1,18 @@
1
+ require 'pathname'
2
+ require 'fileutils'
3
+ require Pathname(__FILE__).dirname.expand_path + 'logger_helper'
4
+
5
+ Object.class_eval do
6
+ remove_const :Slf4r
7
+ end
8
+
9
+ basedir = Pathname(__FILE__).dirname.parent.expand_path
10
+ load basedir + 'lib' + 'slf4r' + 'abstract_logger_facade.rb'
11
+ load basedir + 'lib' + 'slf4r' + 'ruby_logger.rb'
12
+ require 'slf4r/ruby_logger'
13
+
14
+ facade = Slf4r::LoggerFacade4RubyLogger
15
+ facade.file = basedir + 'tmp' + 'ruby_log.txt'
16
+ facade.level = ::Logger::DEBUG
17
+
18
+ behave_as_logger(Slf4r::LoggerFacade.new('ruby_log'))
data/spec/spec.opts ADDED
@@ -0,0 +1,3 @@
1
+ --colour
2
+ --loadby random
3
+ --format progress
@@ -0,0 +1,18 @@
1
+ class File2String < String
2
+
3
+ def initialize(file)
4
+ content = ''
5
+ f = File.open(file, "r")
6
+ f.each_line { |line|
7
+ content += line
8
+ }
9
+ f.close
10
+ super(content)
11
+ end
12
+
13
+ end
14
+
15
+ $LOAD_PATH << Pathname(__FILE__).dirname.parent.expand_path + 'lib'
16
+ require 'slf4r'
17
+
18
+ Dir.mkdir(Pathname(__FILE__).dirname.parent.expand_path + 'tmp') unless File.exists?('tmp')
@@ -0,0 +1,13 @@
1
+ require 'pathname'
2
+ require 'fileutils'
3
+ require Pathname(__FILE__).dirname.expand_path + 'logger_helper'
4
+
5
+ basedir = Pathname(__FILE__).dirname.parent.expand_path
6
+ load basedir + 'lib' + 'slf4r' + 'wrapped_logger.rb'
7
+
8
+ logger = ::Logger.new(basedir + 'tmp' + 'wrapped.txt')
9
+ logger.level == ::Logger::DEBUG
10
+
11
+ Slf4r::LoggerFacade4WrappedLogger.logger = logger
12
+
13
+ behave_as_logger(Slf4r::LoggerFacade.new('wrapped'))
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: slf4r
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.1
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - mkristian
@@ -9,7 +9,7 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2009-02-12 00:00:00 +05:30
12
+ date: 2009-05-22 00:00:00 +05:30
13
13
  default_executable:
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
@@ -20,7 +20,7 @@ dependencies:
20
20
  requirements:
21
21
  - - ">="
22
22
  - !ruby/object:Gem::Version
23
- version: 1.8.2
23
+ version: 1.8.3
24
24
  version:
25
25
  description: the main idea is from www.slf4j.org which is to provide a uniform interface for instantiating und using of a logger. but the actual logging is done by some third party logging framework. one idea is to have a logger per class or object (see ). in ruby you would have something like @logger = Slf4r::LoggerFacade.new(self.class) or the convinience module include Slf4r::Logger if the underlying logging framework allows it (like logging or log4r) then you get a logger for each namespace of your class and create a hierachy of loggers. with this you can control the log level for each logger and/or namespace. for example you have a framework A with namespace 'A' then you can set the log level for the logger with name 'A' to debug and get all the debug from the framework, etc. in case you have a framework B which uses log4r internally you can use the 'log4r_adapter' to delegate the logger creation from log4r to slf4r. in this way you have only one place where logging gets configured and controlled.
26
26
  email:
@@ -43,13 +43,21 @@ files:
43
43
  - lib/ruby_logger_adapter.rb
44
44
  - lib/slf4r.rb
45
45
  - lib/slf4r/abstract_logger_facade.rb
46
+ - lib/slf4r/log4r_logger.rb
46
47
  - lib/slf4r/logger.rb
47
48
  - lib/slf4r/logging_logger.rb
48
49
  - lib/slf4r/noop_logger.rb
49
50
  - lib/slf4r/ruby_logger.rb
50
51
  - lib/slf4r/version.rb
51
52
  - lib/slf4r/wrapped_logger.rb
52
- - test/test_slf4r.rb
53
+ - load.rb
54
+ - spec/log4r_logger_spec.rb
55
+ - spec/logger_helper.rb
56
+ - spec/logging_logger_spec.rb
57
+ - spec/ruby_logger_spec.rb
58
+ - spec/spec.opts
59
+ - spec/spec_helper.rb
60
+ - spec/wrapper_logger_spec.rb
53
61
  has_rdoc: true
54
62
  homepage: http://slf4r.rubyforge.com/
55
63
  post_install_message:
@@ -73,9 +81,9 @@ required_rubygems_version: !ruby/object:Gem::Requirement
73
81
  requirements: []
74
82
 
75
83
  rubyforge_project: slf4r
76
- rubygems_version: 1.2.0
84
+ rubygems_version: 1.3.1
77
85
  signing_key:
78
86
  specification_version: 2
79
87
  summary: Slf4r provides a uniform interface for instantiating und using of a logger
80
- test_files:
81
- - test/test_slf4r.rb
88
+ test_files: []
89
+
data/test/test_slf4r.rb DELETED
File without changes