log4r 1.1.5 → 1.1.6

Sign up to get free protection for your applications and to get access to all the features.
data/README CHANGED
@@ -1,8 +1,8 @@
1
1
  Log4r - A flexible logging library for Ruby
2
2
 
3
3
 
4
- This release: 1.1.5
5
- Release date: 02/Feb/2010
4
+ This release: 1.1.6
5
+ Release date: 11/Mar/2010
6
6
  License: Ruby's
7
7
  Maintainer: Colby Gutierrez-Kraybill
8
8
  Contributors: Leon Torres Original Maintainer
@@ -10,6 +10,7 @@ Contributors: Leon Torres Original Maintainer
10
10
  Steve Lumos SyslogOutputter
11
11
  Andreas Hund YamlConfigurator
12
12
  Jamis Buck log4r.gemspec
13
+ Charles Strahan log4jxml/chainsaw integration
13
14
  Homepage: http://rubyforge.org/projects/log4r/
14
15
  Download: http://rubyforge.org/frs/?group_id=203
15
16
 
@@ -30,6 +31,7 @@ Requirements
30
31
  * (optional) RubyGems for installing Log4r as a gem
31
32
  * (optional) Ruby syslog library for SyslogOutputter
32
33
  * (optional) XML configuration requires REXML
34
+ * (optional) log4j chainsaw integration requires 'builder' >= 2.0
33
35
 
34
36
 
35
37
  More Info
@@ -87,4 +89,4 @@ code yourself. It's well documented and written in Ruby. :)
87
89
  Also, try out the bug/request tracking system at
88
90
  http://rubyforge.org/tracker/?group_id=203
89
91
 
90
- Version: $Id: README,v 1.8 2010/02/03 05:16:27 colbygk Exp $
92
+ Version: $Id: README,v 1.9 2010/03/11 23:00:56 colbygk Exp $
data/Rakefile CHANGED
@@ -1,5 +1,5 @@
1
1
 
2
- # $Id: Rakefile,v 1.8 2010/02/08 20:18:55 colbygk Exp $
2
+ # $Id: Rakefile,v 1.9 2010/03/11 23:00:56 colbygk Exp $
3
3
 
4
4
  # incorporated from Revolution Health version of log4r
5
5
 
@@ -10,7 +10,7 @@ require 'date'
10
10
  require 'fileutils'
11
11
 
12
12
  GEM = "log4r"
13
- GEM_VERSION = "1.1.5"
13
+ GEM_VERSION = "1.1.6"
14
14
  AUTHOR = "Colby Gutierrez-Kraybill"
15
15
  EMAIL = "colby@astro.berkeley.edu"
16
16
  HOMEPAGE = %q{http://log4r.rubyforge.org}
@@ -0,0 +1,7 @@
1
+ <?xml version="1.0" encoding="UTF-8" ?>
2
+ <!DOCTYPE log4j:configuration SYSTEM "log4j.dtd">
3
+ <log4j:configuration xmlns:log4j="http://jakarta.apache.org/log4j/" debug="true">
4
+ <plugin name="log4r_test" class="org.apache.log4j.net.UDPReceiver">
5
+ <param name="Port" value="8071" />
6
+ </plugin>
7
+ </log4j:configuration>
@@ -3,7 +3,7 @@
3
3
  # == Other Info
4
4
  #
5
5
  # Author:: Leon Torres
6
- # Version:: $Id: log4r.rb,v 1.8 2010/02/03 05:16:12 colbygk Exp $
6
+ # Version:: $Id: log4r.rb,v 1.9 2010/03/11 22:59:51 colbygk Exp $
7
7
 
8
8
  require "log4r/outputter/fileoutputter"
9
9
  require "log4r/outputter/consoleoutputters"
@@ -16,5 +16,5 @@ require "log4r/NDC"
16
16
  require "log4r/MDC"
17
17
 
18
18
  module Log4r
19
- Log4rVersion = [1, 1, 5].join '.'
19
+ Log4rVersion = [1, 1, 6].join '.'
20
20
  end
@@ -0,0 +1,61 @@
1
+ # :include: ../rdoc/log4jxmlformatter
2
+ #
3
+ # == Other Info
4
+ #
5
+ # Version:: $Id: log4jxmlformatter.rb,v 1.2 2010/03/11 23:38:22 colbygk Exp $
6
+
7
+ require "log4r/formatter/formatter"
8
+
9
+ require "rubygems"
10
+ require "builder"
11
+
12
+ module Log4r
13
+
14
+ class Log4jXmlFormatter < BasicFormatter
15
+
16
+ def format(logevent)
17
+ logger = logevent.fullname.gsub('::', '.')
18
+ timestamp = (Time.now.to_f * 1000).to_i
19
+ level = LNAMES[logevent.level]
20
+ message = format_object(logevent.data)
21
+ exception = message if logevent.data.kind_of? Exception
22
+ file, line, method = parse_caller(logevent.tracer[0]) if logevent.tracer
23
+
24
+ builder = Builder::XmlMarkup.new
25
+ xml = builder.log4j :event, :logger => logger,
26
+ :timestamp => timestamp,
27
+ :level => level,
28
+ :thread => '' do |e|
29
+ e.log4j :NDC, NDC.get
30
+ e.log4j :message, message
31
+ e.log4j :throwable, exception if exception
32
+ e.log4j :locationInfo, :class => '',
33
+ :method => method,
34
+ :file => file,
35
+ :line => line
36
+ e.log4j :properties do |p|
37
+ MDC.get_context.each do |key, value|
38
+ p.log4j :data, :name => key, :value => value
39
+ end
40
+ end
41
+ end
42
+ xml
43
+ end
44
+
45
+ #######
46
+ private
47
+ #######
48
+
49
+ def parse_caller(line)
50
+ if /^(.+?):(\d+)(?::in `(.*)')?/ =~ line
51
+ file = Regexp.last_match[1]
52
+ line = Regexp.last_match[2].to_i
53
+ method = Regexp.last_match[3]
54
+ [file, line, method]
55
+ else
56
+ []
57
+ end
58
+ end
59
+ end
60
+
61
+ end
@@ -0,0 +1,24 @@
1
+ --- datefileoutputter.rb 2004-03-18 19:31:09.000000000 -0800
2
+ +++ new-datefileoutputter.rb 2010-03-11 18:36:37.000000000 -0800
3
+ @@ -54,12 +54,19 @@
4
+ if not FileTest.directory?( _dirname)
5
+ raise StandardError, "'#{_dirname}' must be a valid directory", caller
6
+ end
7
+ + end
8
+ +
9
+ + _filename = (hash[:filename] or hash['filename'])
10
+ + if _filename.nil?
11
+ @filebase = File.basename( $0, '.rb') + ".log"
12
+ else
13
+ @filebase = File.basename((hash[:filename] or hash['filename'] or ""))
14
+ end
15
+ - hash['filename'] = File.join(_dirname,
16
+ - @filebase.sub(/(\.\w*)$/, "_#{@DateStamp}" + '\1'))
17
+ +
18
+ + # Get rid of the 'nil' in the path
19
+ + path = [_dirname, @filebase.sub(/(\.\w*)$/, "_#{@DateStamp}" + '\1')].compact
20
+ + hash[:filename] = hash['filename'] = File.join(path)
21
+ +
22
+ super(_name, hash)
23
+ end
24
+
@@ -54,12 +54,19 @@ module Log4r
54
54
  if not FileTest.directory?( _dirname)
55
55
  raise StandardError, "'#{_dirname}' must be a valid directory", caller
56
56
  end
57
+ end
58
+
59
+ _filename = (hash[:filename] or hash['filename'])
60
+ if _filename.nil?
57
61
  @filebase = File.basename( $0, '.rb') + ".log"
58
62
  else
59
63
  @filebase = File.basename((hash[:filename] or hash['filename'] or ""))
60
64
  end
61
- hash['filename'] = File.join(_dirname,
62
- @filebase.sub(/(\.\w*)$/, "_#{@DateStamp}" + '\1'))
65
+
66
+ # Get rid of the 'nil' in the path
67
+ path = [_dirname, @filebase.sub(/(\.\w*)$/, "_#{@DateStamp}" + '\1')].compact
68
+ hash[:filename] = hash['filename'] = File.join(path)
69
+
63
70
  super(_name, hash)
64
71
  end
65
72
 
@@ -0,0 +1,14 @@
1
+ 56a57,60
2
+ > end
3
+ >
4
+ > _filename = (hash[:filename] or hash['filename'])
5
+ > if _filename.nil?
6
+ 61,62c65,69
7
+ < hash['filename'] = File.join(_dirname,
8
+ < @filebase.sub(/(\.\w*)$/, "_#{@DateStamp}" + '\1'))
9
+ ---
10
+ >
11
+ > # Get rid of the 'nil' in the path
12
+ > path = [_dirname, @filebase.sub(/(\.\w*)$/, "_#{@DateStamp}" + '\1')].compact
13
+ > hash[:filename] = hash['filename'] = File.join(path)
14
+ >
@@ -0,0 +1,117 @@
1
+ # = DateFileOutputter
2
+ #
3
+ # Subclass of FileOutputter that changes the log file daily. When a new
4
+ # day begins, a new file is created with the date included in the name.
5
+ #
6
+ # == Usage
7
+ #
8
+ # df_out = DateFileOutputter.new('name',
9
+ # :dirname="/tmp", :date_pattern=>"%m-%d"
10
+ # )
11
+ #
12
+ # == Rate of Change
13
+ #
14
+ # A new logfile is created whenever the current time as formatted by the date
15
+ # pattern no longer matches the previous time. (This is a simple String
16
+ # comparison.) So, in order to change the frequency of the rollover, just
17
+ # alter the date pattern to match how fast the files should be generated.
18
+ # For instance, to generate files by the minute,
19
+ #
20
+ # df_out.date_pattern = "%M"
21
+ #
22
+ # This causes the following files to show up one minute apart, asuming the
23
+ # script starts at the 4th minute of the hour:
24
+ #
25
+ # file_04.rb
26
+ # file_05.rb
27
+ # file_06.rb
28
+ # ...
29
+ #
30
+ # The only limitation of this approach is that the precise time cannot be
31
+ # recorded as the smallest time interval equals the rollover period for this
32
+ # system.
33
+
34
+ require "log4r/outputter/fileoutputter"
35
+ require "log4r/staticlogger"
36
+
37
+ module Log4r
38
+
39
+ # Additional hash arguments are:
40
+ #
41
+ # [<tt>:dirname</tt>] Directory of the log file
42
+ # [<tt>:date_pattern</tt>] Time.strftime format string (default is "%Y-%m-%d")
43
+
44
+ class DateFileOutputter < FileOutputter
45
+ DEFAULT_DATE_FMT = "%Y-%m-%d"
46
+
47
+ def initialize(_name, hash={})
48
+ @DatePattern = (hash[:date_pattern] or hash['date_pattern'] or
49
+ DEFAULT_DATE_FMT)
50
+ @DateStamp = Time.now.strftime( @DatePattern);
51
+ _dirname = (hash[:dirname] or hash['dirname'])
52
+ # hash[:dirname] masks hash[:filename]
53
+ if _dirname
54
+ if not FileTest.directory?( _dirname)
55
+ raise StandardError, "'#{_dirname}' must be a valid directory", caller
56
+ end
57
+ end
58
+
59
+ _filename = (hash[:filename] or hash['filename'])
60
+ if _filename.nil?
61
+ @filebase = File.basename( $0, '.rb') + ".log"
62
+ else
63
+ @filebase = File.basename((hash[:filename] or hash['filename'] or ""))
64
+ end
65
+
66
+ # Get rid of the 'nil' in the path
67
+ path = [_dirname, @filebase.sub(/(\.\w*)$/, "_#{@DateStamp}" + '\1')].compact
68
+ hash[:filename] = hash['filename'] = File.join(path)
69
+
70
+ super(_name, hash)
71
+ end
72
+
73
+ #######
74
+ private
75
+ #######
76
+
77
+ # perform the write
78
+ def write(data)
79
+ change if requiresChange
80
+ super
81
+ end
82
+
83
+ # construct a new filename from the DateStamp
84
+ def makeNewFilename
85
+ @DateStamp = Time.now.strftime( @DatePattern);
86
+ @filename = File.join(File.dirname(@filename),
87
+ @filebase.sub(/(\.\w*)$/, "_#{@DateStamp}" + '\1'))
88
+ end
89
+
90
+ # does the file require a change?
91
+ def requiresChange
92
+ _DateStamp = Time.now.strftime( @DatePattern);
93
+ if not _DateStamp == @DateStamp
94
+ @DateStamp = _DateStamp
95
+ return true
96
+ end
97
+ false
98
+ end
99
+
100
+ # change the file
101
+ def change
102
+ begin
103
+ @out.close
104
+ rescue
105
+ Logger.log_internal {
106
+ "DateFileOutputter '#{@name}' could not close #{@filename}"
107
+ }
108
+ end
109
+ makeNewFilename
110
+ @out = File.new(@filename, (@trunc ? "w" : "a"))
111
+ Logger.log_internal {
112
+ "DateFileOutputter '#{@name}' now writing to #{@filename}"
113
+ }
114
+ end
115
+ end
116
+
117
+ end
@@ -0,0 +1,53 @@
1
+ # :include: ../rdoc/outputter
2
+ #
3
+ # == Other Info
4
+ #
5
+ # Version:: $Id: udpoutputter.rb,v 1.2 2010/03/11 23:38:36 colbygk Exp $
6
+ # Author:: Leon Torres <leon@ugcs.caltech.edu>
7
+
8
+ require "log4r/outputter/outputter"
9
+ require 'log4r/staticlogger'
10
+ require "socket"
11
+
12
+ module Log4r
13
+
14
+ class UDPOutputter < Outputter
15
+ attr_reader :host, :port
16
+ attr_accessor :udpsock
17
+
18
+ def initialize(_name, _host, _port, hash={})
19
+ super(_name, hash)
20
+ @host = _host
21
+ @port = _port
22
+
23
+ begin
24
+ Logger.log_internal {
25
+ "UDPOutputter will send to #{@host}:#{@port}"
26
+ }
27
+ @udpsock = UDPSocket.new
28
+ @udpsock.connect( @host, @port )
29
+ rescue Exception => e
30
+ Logger.log_internal(ERROR) {
31
+ "UDPOutputter failed to create UDP socket: #{e}"
32
+ }
33
+ Logger.log_internal {e}
34
+ self.level = OFF
35
+ raise e
36
+ end
37
+ end
38
+
39
+ #######
40
+ private
41
+ #######
42
+
43
+ def write(data)
44
+ @udpsock.send(data, 0)
45
+ rescue Exception => e
46
+ Logger.log_internal(ERROR) {
47
+ "UDPOutputter failed to send data to #{@host}:#{@port}, #{e}"
48
+ }
49
+ end
50
+
51
+ end
52
+
53
+ end
@@ -0,0 +1,48 @@
1
+ $: << File.join("..", "src")
2
+
3
+ require 'log4r'
4
+ require 'log4r/staticlogger'
5
+ require 'log4r/formatter/log4jxmlformatter'
6
+ require 'log4r/outputter/udpoutputter'
7
+ require 'log4r/outputter/consoleoutputters'
8
+
9
+ include Log4r
10
+
11
+ log4r = Logger.new 'log4r'
12
+ log4r.trace = true
13
+ log4r.outputters = StdoutOutputter.new 'log4r'
14
+ log4r.level = ALL
15
+
16
+ formatter = Log4jXmlFormatter.new
17
+ outputter = UDPOutputter.new 'udp', "localhost", 8071
18
+ outputter.formatter = formatter
19
+
20
+ mylog = Logger.new 'mylog'
21
+ mylog.trace = true
22
+ mylog.outputters = [outputter]
23
+
24
+ # Log4r::Formatter throws when formatting
25
+ # an excpetion with a nil backtrace (line 73).
26
+ def get_exception(msg)
27
+ begin
28
+ raise msg
29
+ rescue Exception => e
30
+ e
31
+ end
32
+ end
33
+
34
+ NDC.push "saw test"
35
+
36
+ MDC.put "clientip", %q{10.33.33.33}
37
+
38
+ def do_log(log)
39
+ log.debug "This is a message with level DEBUG"
40
+ log.info "This is a message with level INFO"
41
+ log.warn "This is a message with level WARN"
42
+ log.error "This is a message with level ERROR"
43
+ log.fatal "This is a message with level FATAL"
44
+
45
+ log.fatal get_exception( "This is an exception" )
46
+ end
47
+
48
+ do_log(mylog)
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: log4r
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.1.5
4
+ version: 1.1.6
5
5
  platform: ruby
6
6
  authors:
7
7
  - Colby Gutierrez-Kraybill
@@ -9,7 +9,7 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2010-02-08 00:00:00 -08:00
12
+ date: 2010-03-11 00:00:00 -08:00
13
13
  default_executable:
14
14
  dependencies: []
15
15
 
@@ -43,6 +43,7 @@ files:
43
43
  - doc/log4r.css
44
44
  - doc/rdoc-log4r.css
45
45
  - doc/templates/main.html
46
+ - examples/chainsaw_settings.xml
46
47
  - examples/customlevels.rb
47
48
  - examples/filelog.rb
48
49
  - examples/fileroll.rb
@@ -64,6 +65,7 @@ files:
64
65
  - src/log4r/config.rb
65
66
  - src/log4r/configurator.rb
66
67
  - src/log4r/formatter/formatter.rb
68
+ - src/log4r/formatter/log4jxmlformatter.rb
67
69
  - src/log4r/formatter/patternformatter.rb
68
70
  - src/log4r/GDC.rb
69
71
  - src/log4r/lib/drbloader.rb
@@ -75,16 +77,20 @@ files:
75
77
  - src/log4r/MDC.rb
76
78
  - src/log4r/NDC.rb
77
79
  - src/log4r/outputter/consoleoutputters.rb
80
+ - src/log4r/outputter/datefileoutputter.patch
78
81
  - src/log4r/outputter/datefileoutputter.rb
82
+ - src/log4r/outputter/diff
79
83
  - src/log4r/outputter/emailoutputter.rb
80
84
  - src/log4r/outputter/fileoutputter.rb
81
85
  - src/log4r/outputter/iooutputter.rb
86
+ - src/log4r/outputter/new-datefileoutputter.rb
82
87
  - src/log4r/outputter/outputter.rb
83
88
  - src/log4r/outputter/outputterfactory.rb
84
89
  - src/log4r/outputter/remoteoutputter.rb
85
90
  - src/log4r/outputter/rollingfileoutputter.rb
86
91
  - src/log4r/outputter/staticoutputter.rb
87
92
  - src/log4r/outputter/syslogoutputter.rb
93
+ - src/log4r/outputter/udpoutputter.rb
88
94
  - src/log4r/rdoc/configurator
89
95
  - src/log4r/rdoc/emailoutputter
90
96
  - src/log4r/rdoc/formatter
@@ -106,6 +112,7 @@ files:
106
112
  - tests/README
107
113
  - tests/testall.rb
108
114
  - tests/testbase.rb
115
+ - tests/testchainsaw.rb
109
116
  - tests/testconf.xml
110
117
  - tests/testcustom.rb
111
118
  - tests/testformatter.rb