highlogger 0.0.1 → 0.0.2

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.
@@ -2,7 +2,7 @@ module Highlogger #:nodoc:
2
2
  module VERSION #:nodoc:
3
3
  MAJOR = 0
4
4
  MINOR = 0
5
- TINY = 1
5
+ TINY = 2
6
6
 
7
7
  STRING = [MAJOR, MINOR, TINY].join('.')
8
8
  end
data/lib/highlogger.rb CHANGED
@@ -2,21 +2,6 @@ $:.unshift File.dirname(__FILE__)
2
2
 
3
3
  require "logger"
4
4
 
5
- module LogSource
6
- @logger = nil
7
-
8
- def set_logger(logger_obj)
9
- @logger = logger_obj
10
- end
11
-
12
- def log(severity, *strings, &block)
13
- caller_str = caller()[0]
14
- matchobj = /([^\/]+)\.rb/.match(caller_str)
15
- raise "Call set_logger before logging!" if(not @logger)
16
- @logger.add(matchobj[1], severity, *strings, &block)
17
- end
18
- end # module LogSource
19
-
20
5
  # This class implements a simple heirarchical logging system.
21
6
  #
22
7
  class HighLogger < Logger
@@ -169,3 +154,60 @@ class HighLogger < Logger
169
154
  end
170
155
 
171
156
  end # class HighLogger
157
+
158
+ module LogSource
159
+ @@highlogger_default_logger = HighLogger.new(STDERR)
160
+ @highlogger_logger = nil
161
+
162
+ def set_logger(logger_obj)
163
+ @highlogger_logger = logger_obj
164
+ @highlogger_component = nil
165
+ end
166
+
167
+ def set_component(comp_name)
168
+ @highlogger_component = comp_name
169
+ end
170
+
171
+ def log(severity, *strings, &block)
172
+ if @highlogger_component
173
+ comp = @highlogger_component
174
+ else
175
+ caller_str = caller()[0]
176
+ matchobj = /([^\/]+)\.rb/.match(caller_str)
177
+ comp = matchobj[1]
178
+ end
179
+
180
+ if @highlogger_logger
181
+ @highlogger_logger.add(comp, severity, *strings, &block)
182
+ else
183
+ @@highlogger_default_logger.add(comp, severity, *strings, &block)
184
+ end
185
+ end
186
+
187
+ alias add log
188
+
189
+ def debug(progname = nil, &block)
190
+ add(Logger::DEBUG, nil, progname, &block)
191
+ end
192
+
193
+ def info(progname = nil, &block)
194
+ add(Logger::INFO, nil, progname, &block)
195
+ end
196
+
197
+ def warn(progname = nil, &block)
198
+ add(Logger::WARN, nil, progname, &block)
199
+ end
200
+
201
+ def error(progname = nil, &block)
202
+ add(Logger::ERROR, nil, progname, &block)
203
+ end
204
+
205
+ def fatal(progname = nil, &block)
206
+ add(Logger::FATAL, nil, progname, &block)
207
+ end
208
+
209
+ def unknown(progname = nil, &block)
210
+ add(Logger::UNKNOWN, nil, progname, &block)
211
+ end
212
+
213
+ end # module LogSource
@@ -106,4 +106,56 @@ EOS
106
106
  end
107
107
  end
108
108
 
109
+ def test_logsource
110
+ dls = LogSourceTest.new(TESTFILE4)
111
+
112
+ dls.test_func
113
+
114
+ (1..4).each do |index|
115
+ assert_file_contains_on_line(TESTFILE4, "test line #{index}", index)
116
+ assert_file_contains_on_line(TESTFILE4, "componentname", index)
117
+ end
118
+ end
119
+
120
+ def test_default_logger
121
+ dt = DefaultLoggerTest.new
122
+
123
+ dt.test_func
124
+ end
125
+
126
+ end
127
+
128
+ class LogSourceTest
129
+ include LogSource
130
+
131
+ def initialize(filename)
132
+ set_logger(HighLogger.new(filename))
133
+ set_component("componentname")
134
+ end
135
+
136
+ def test_func
137
+ warn("Warn message, test line 1")
138
+ error("Error message, test line 2")
139
+ fatal("Fatal message, test line 3")
140
+ unknown("Unknown message, test line 4")
141
+ end
142
+
143
+ end
144
+
145
+ class DefaultLoggerTest
146
+ include LogSource
147
+
148
+ # Intentionally don't call set_logger
149
+
150
+ def test_func
151
+ $VERBOSE = false
152
+ # These will come out on STDERR
153
+ debug("Testing: Debug message on STDERR (SHOULD NOT SEE!)")
154
+ info("Testing: Info message on STDERR (SHOULD NOT SEE!)")
155
+ warn("Testing: Warn message on STDERR (should be one of three visible)")
156
+ fatal("Testing: Fatal message on STDERR (should be one of three visible)")
157
+ error("Testing: Error message on STDERR (should be one of three visible)")
158
+ $VERBOSE = true
159
+ end
160
+
109
161
  end
data/website/index.html CHANGED
@@ -1,11 +1,151 @@
1
- <html>
2
- <head>
3
- <meta http-equiv="Content-type" content="text/html; charset=utf-8">
4
- <title>highlogger</title>
5
-
6
- </head>
7
- <body id="body">
8
- <p>This page has not yet been created for RubyGem <code>highlogger</code></p>
9
- <p>To the developer: To generate it, update website/index.txt and run the rake task <code>website</code> to generate this <code>index.html</code> file.</p>
10
- </body>
11
- </html>
1
+ <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
2
+ "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
3
+ <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
4
+ <head>
5
+ <link rel="stylesheet" href="stylesheets/screen.css" type="text/css" media="screen" />
6
+ <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
7
+ <title>
8
+ highlogger
9
+ </title>
10
+ <script src="javascripts/rounded_corners_lite.inc.js" type="text/javascript"></script>
11
+ <style>
12
+
13
+ </style>
14
+ <script type="text/javascript">
15
+ window.onload = function() {
16
+ settings = {
17
+ tl: { radius: 10 },
18
+ tr: { radius: 10 },
19
+ bl: { radius: 10 },
20
+ br: { radius: 10 },
21
+ antiAlias: true,
22
+ autoPad: true,
23
+ validTags: ["div"]
24
+ }
25
+ var versionBox = new curvyCorners(settings, document.getElementById("version"));
26
+ versionBox.applyCornersToAll();
27
+ }
28
+ </script>
29
+ </head>
30
+ <body>
31
+ <div id="main">
32
+
33
+ <h1>highlogger</h1>
34
+ <div id="version" class="clickable" onclick='document.location = "http://rubyforge.org/projects/highlogger"; return false'>
35
+ <p>Get Version</p>
36
+ <a href="http://rubyforge.org/projects/highlogger" class="numbers">0.0.1</a>
37
+ </div>
38
+ <h1>&#x2192; &#8216;highlogger&#8217;</h1>
39
+
40
+
41
+ <h2>What</h2>
42
+
43
+
44
+ <p>HighLogger is a nearly-industrial-strength logging package for Ruby,
45
+ more suitable for the purpose than Ruby&#8217;s own Logger package, which it
46
+ uses as a back end. HighLogger logs all messages by component, which
47
+ may be a file, class or anything else, and each component may set a
48
+ visible logging level. All log messages of that level or &#8216;higher&#8217;
49
+ (i.e. more severe) will be sent to the backend logger.</p>
50
+
51
+
52
+ <p>If no level has been set for a given component and the component name
53
+ contains the colon character, it is assumed to be multipart. So if
54
+ the component is &#8216;MyProgram:Networking:TCP:NagelsAlgorithm&#8221;,
55
+ HighLogger will check &#8216;MyProgram:Networking:TCP&#8217; next, then
56
+ &#8216;MyProgram:Networking&#8217;, then &#8216;MyProgram&#8217;, and use the first level that
57
+ you&#8217;ve set. This is the &#8216;heirarchical&#8217; part in HighLogger&#8217;s
58
+ description. If no level has been set for any of these then
59
+ HighLogger will see if a default level has been set. If no default
60
+ level has been set then it will default to showing Warnings and
61
+ beyond. HighLogger uses the severity constants from the Logger
62
+ library, just as Logger does.</p>
63
+
64
+
65
+ <h2>Installing</h2>
66
+
67
+
68
+ <p><pre class='syntax'><span class="ident">sudo</span> <span class="ident">gem</span> <span class="ident">install</span> <span class="ident">highlogger</span></pre></p>
69
+
70
+
71
+ <h2>The basics</h2>
72
+
73
+
74
+ <p>A HighLogger can be created with the same syntax as a standard Ruby
75
+ Logger. Valid forms include <ins>HighLogger.new(STDOUT)</ins>,
76
+ <ins>HighLogger.new(STDERR)</ins>, and <ins>HighLogger.new(&#8220;myfile.log&#8221;)</ins>.</p>
77
+
78
+
79
+ <p>The logging functions on a HighLogger object (log, add, debug, info,
80
+ warn, error, etc) are identical to the ones for a Logger except they
81
+ require an additional first parameter which is the component name.</p>
82
+
83
+
84
+ <h2>Demonstration of usage</h2>
85
+
86
+
87
+ <pre>
88
+ logger = HighLogger.new(TESTFILE)
89
+
90
+ config_file = &amp;lt;&amp;lt;EOS
91
+ myprog = WARN
92
+ mylib = ERROR
93
+ myprog:graphics = FATAL
94
+ myprog:network:tcp:myproto = INFO
95
+ mylib:comp1 = WARN
96
+ mylib:comp2:subcomp1:subcomp2 = ANY
97
+ mylib:comp3:subcomp1 = none
98
+ otherlib = info
99
+ EOS
100
+ # Can also load from a filename with read_config_file
101
+ logger.read_config_buffer(conf_file)
102
+
103
+ logger.add("myprog:graphics:area1", Logger::UNKNOWN, "test line 1")
104
+ logger.add("myprog:graphics:area1", Logger::WARN, "should not see")
105
+ logger.fatal("mylib", "test line 2")
106
+ logger.error("myprog:graphics", "should not see")
107
+ logger.debug("mylib:comp1:sub", "should not see")
108
+ logger.info("mylib:comp2:subcomp1", "should not see")
109
+ logger.info("mylib:comp2:subcomp1:subcomp2:subcomp3", "test line 3")
110
+ logger.unknown("myprog:graphics", "test line 4")
111
+ logger.unknown("myprog:graphics") { "test line 5" }
112
+ logger.debug("myprog:network:tcp:myproto") { "should not see" }
113
+ logger.error("myprog:network:tcp:myproto:sub") { "test line 6" }
114
+ </pre>
115
+
116
+ <h2>Forum</h2>
117
+
118
+
119
+ <p>There is a Rubyforge forum for the ab-ext project which may be used for
120
+ questions about HighLogger.</p>
121
+
122
+
123
+ <h2>How to submit patches</h2>
124
+
125
+
126
+ <p>Read the <a href="http://drnicwilliams.com/2007/06/01/8-steps-for-fixing-other-peoples-code/">8 steps for fixing other people&#8217;s code</a> and submit patches by email to the author.</p>
127
+
128
+
129
+ <p>The trunk repository is <code>svn://rubyforge.org/var/svn/highlogger/trunk</code> for anonymous access.</p>
130
+
131
+
132
+ <h2>License</h2>
133
+
134
+
135
+ <p>This code is free to use under the terms of the Ruby license.</p>
136
+
137
+
138
+ <h2>Contact</h2>
139
+
140
+
141
+ <p>Comments are welcome. Send email to <a href="mailto:angelbob@nospam.users.sourceforge.net">Noah Gibbs</a></p>
142
+ <p class="coda">
143
+ <a href="FIXME email">FIXME full name</a>, 22nd October 2007<br>
144
+ Theme extended from <a href="http://rb2js.rubyforge.org/">Paul Battley</a>
145
+ </p>
146
+ </div>
147
+
148
+ <!-- insert site tracking codes here, like Google Urchin -->
149
+
150
+ </body>
151
+ </html>
data/website/index.txt CHANGED
@@ -5,6 +5,24 @@ h1. &#x2192; 'highlogger'
5
5
 
6
6
  h2. What
7
7
 
8
+ HighLogger is a nearly-industrial-strength logging package for Ruby,
9
+ more suitable for the purpose than Ruby's own Logger package, which it
10
+ uses as a back end. HighLogger logs all messages by component, which
11
+ may be a file, class or anything else, and each component may set a
12
+ visible logging level. All log messages of that level or 'higher'
13
+ (i.e. more severe) will be sent to the backend logger.
14
+
15
+ If no level has been set for a given component and the component name
16
+ contains the colon character, it is assumed to be multipart. So if
17
+ the component is 'MyProgram:Networking:TCP:NagelsAlgorithm",
18
+ HighLogger will check 'MyProgram:Networking:TCP' next, then
19
+ 'MyProgram:Networking', then 'MyProgram', and use the first level that
20
+ you've set. This is the 'heirarchical' part in HighLogger's
21
+ description. If no level has been set for any of these then
22
+ HighLogger will see if a default level has been set. If no default
23
+ level has been set then it will default to showing Warnings and
24
+ beyond. HighLogger uses the severity constants from the Logger
25
+ library, just as Logger does.
8
26
 
9
27
  h2. Installing
10
28
 
@@ -12,28 +30,60 @@ h2. Installing
12
30
 
13
31
  h2. The basics
14
32
 
33
+ A HighLogger can be created with the same syntax as a standard Ruby
34
+ Logger. Valid forms include +HighLogger.new(STDOUT)+,
35
+ +HighLogger.new(STDERR)+, and +HighLogger.new("myfile.log")+.
15
36
 
16
- h2. Demonstration of usage
37
+ The logging functions on a HighLogger object (log, add, debug, info,
38
+ warn, error, etc) are identical to the ones for a Logger except they
39
+ require an additional first parameter which is the component name.
17
40
 
41
+ h2. Demonstration of usage
18
42
 
43
+ <pre>
44
+ logger = HighLogger.new(TESTFILE)
45
+
46
+ config_file = &lt;&lt;EOS
47
+ myprog = WARN
48
+ mylib = ERROR
49
+ myprog:graphics = FATAL
50
+ myprog:network:tcp:myproto = INFO
51
+ mylib:comp1 = WARN
52
+ mylib:comp2:subcomp1:subcomp2 = ANY
53
+ mylib:comp3:subcomp1 = none
54
+ otherlib = info
55
+ EOS
56
+ # Can also load from a filename with read_config_file
57
+ logger.read_config_buffer(conf_file)
58
+
59
+ logger.add("myprog:graphics:area1", Logger::UNKNOWN, "test line 1")
60
+ logger.add("myprog:graphics:area1", Logger::WARN, "should not see")
61
+ logger.fatal("mylib", "test line 2")
62
+ logger.error("myprog:graphics", "should not see")
63
+ logger.debug("mylib:comp1:sub", "should not see")
64
+ logger.info("mylib:comp2:subcomp1", "should not see")
65
+ logger.info("mylib:comp2:subcomp1:subcomp2:subcomp3", "test line 3")
66
+ logger.unknown("myprog:graphics", "test line 4")
67
+ logger.unknown("myprog:graphics") { "test line 5" }
68
+ logger.debug("myprog:network:tcp:myproto") { "should not see" }
69
+ logger.error("myprog:network:tcp:myproto:sub") { "test line 6" }
70
+ </pre>
19
71
 
20
72
  h2. Forum
21
73
 
22
- "http://groups.google.com/group/highlogger":http://groups.google.com/group/highlogger
23
-
24
- TODO - create Google Group - highlogger
74
+ There is a Rubyforge forum for the ab-ext project which may be used for
75
+ questions about HighLogger.
25
76
 
26
77
  h2. How to submit patches
27
78
 
28
- Read the "8 steps for fixing other people's code":http://drnicwilliams.com/2007/06/01/8-steps-for-fixing-other-peoples-code/ and for section "8b: Submit patch to Google Groups":http://drnicwilliams.com/2007/06/01/8-steps-for-fixing-other-peoples-code/#8b-google-groups, use the Google Group above.
79
+ Read the "8 steps for fixing other people's code":http://drnicwilliams.com/2007/06/01/8-steps-for-fixing-other-peoples-code/ and submit patches by email to the author.
29
80
 
30
81
  The trunk repository is <code>svn://rubyforge.org/var/svn/highlogger/trunk</code> for anonymous access.
31
82
 
32
83
  h2. License
33
84
 
34
- This code is free to use under the terms of the MIT license.
85
+ This code is free to use under the terms of the Ruby license.
35
86
 
36
87
  h2. Contact
37
88
 
38
- Comments are welcome. Send an email to "FIXME full name":mailto:FIXME email via the "forum":http://groups.google.com/group/highlogger
39
-
89
+ Comments are welcome. Send email to "Noah Gibbs":mailto:angelbob@nospam.users.sourceforge.net
@@ -37,7 +37,7 @@
37
37
  </div>
38
38
  <%= body %>
39
39
  <p class="coda">
40
- <a href="FIXME email">FIXME full name</a>, <%= modified.pretty %><br>
40
+ <a href="angelbob@nospam.users.sourceforge.net">Noah Gibbs</a>, <%= modified.pretty %><br>
41
41
  Theme extended from <a href="http://rb2js.rubyforge.org/">Paul Battley</a>
42
42
  </p>
43
43
  </div>
metadata CHANGED
@@ -1,10 +1,10 @@
1
1
  --- !ruby/object:Gem::Specification
2
- rubygems_version: 0.8.11
2
+ rubygems_version: 0.9.4
3
3
  specification_version: 1
4
4
  name: highlogger
5
5
  version: !ruby/object:Gem::Version
6
- version: 0.0.1
7
- date: 2007-10-21 00:00:00 -07:00
6
+ version: 0.0.2
7
+ date: 2007-10-26 00:00:00 -07:00
8
8
  summary: A heirarchical component-based logging system
9
9
  require_paths:
10
10
  - lib
@@ -25,6 +25,7 @@ required_ruby_version: !ruby/object:Gem::Version::Requirement
25
25
  platform: ruby
26
26
  signing_key:
27
27
  cert_chain:
28
+ post_install_message:
28
29
  authors:
29
30
  - Noah Gibbs
30
31
  files: