highlogger 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- data/History.txt +4 -0
- data/License.txt +4 -0
- data/Manifest.txt +24 -0
- data/README.txt +20 -0
- data/Rakefile +4 -0
- data/config/hoe.rb +70 -0
- data/config/requirements.rb +17 -0
- data/lib/highlogger/version.rb +9 -0
- data/lib/highlogger.rb +171 -0
- data/log/debug.log +0 -0
- data/script/destroy +14 -0
- data/script/generate +14 -0
- data/script/txt2html +74 -0
- data/setup.rb +1585 -0
- data/tasks/deployment.rake +27 -0
- data/tasks/environment.rake +7 -0
- data/tasks/website.rake +21 -0
- data/test/test_helper.rb +2 -0
- data/test/test_highlogger.rb +109 -0
- data/website/index.html +11 -0
- data/website/index.txt +39 -0
- data/website/javascripts/rounded_corners_lite.inc.js +285 -0
- data/website/stylesheets/screen.css +138 -0
- data/website/template.rhtml +48 -0
- metadata +74 -0
data/History.txt
ADDED
data/License.txt
ADDED
data/Manifest.txt
ADDED
@@ -0,0 +1,24 @@
|
|
1
|
+
History.txt
|
2
|
+
License.txt
|
3
|
+
Manifest.txt
|
4
|
+
README.txt
|
5
|
+
Rakefile
|
6
|
+
config/hoe.rb
|
7
|
+
config/requirements.rb
|
8
|
+
lib/highlogger.rb
|
9
|
+
lib/highlogger/version.rb
|
10
|
+
log/debug.log
|
11
|
+
script/destroy
|
12
|
+
script/generate
|
13
|
+
script/txt2html
|
14
|
+
setup.rb
|
15
|
+
tasks/deployment.rake
|
16
|
+
tasks/environment.rake
|
17
|
+
tasks/website.rake
|
18
|
+
test/test_helper.rb
|
19
|
+
test/test_highlogger.rb
|
20
|
+
website/index.html
|
21
|
+
website/index.txt
|
22
|
+
website/javascripts/rounded_corners_lite.inc.js
|
23
|
+
website/stylesheets/screen.css
|
24
|
+
website/template.rhtml
|
data/README.txt
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
HighLogger
|
2
|
+
|
3
|
+
This is a simple heirarchical component-based logging system based on
|
4
|
+
Ruby's standard "Logger". Component-based means that you call the
|
5
|
+
logging function with a component such as a filename in addition to the
|
6
|
+
severity. This allows HighLogger to be configured from a file to
|
7
|
+
filter each component by severity. Thus, you could filter output from
|
8
|
+
one file to only errors and up, while another file that you just added
|
9
|
+
will log every message of every severity. This is useful for debugging
|
10
|
+
larger projects, and adding new components to projects of any size.
|
11
|
+
|
12
|
+
HighLogger is heirarchical because if a component has one or more
|
13
|
+
colons in the name, they are treated as separators. For instance, the
|
14
|
+
component name "Math:DiffEQ:Integrator:Cash-Karp" has four levels. If
|
15
|
+
a severity setting isn't given for the full name, each sub-name will
|
16
|
+
be checked in turn. For the above example, "Math:DiffEQ:Integrator"
|
17
|
+
would be checked next, then "Math:DiffEQ", then "Math". So if there
|
18
|
+
were no setting for the first three of those but "Math" was set to log
|
19
|
+
fatal errors only, then log messages directed to component
|
20
|
+
"Math:DiffEQ:Integrator:Cash-Karp" would be recorded only if fatal.
|
data/Rakefile
ADDED
data/config/hoe.rb
ADDED
@@ -0,0 +1,70 @@
|
|
1
|
+
require 'highlogger/version'
|
2
|
+
|
3
|
+
AUTHOR = 'Noah Gibbs'
|
4
|
+
EMAIL = "angelbob@nospam.users.sourceforge.net"
|
5
|
+
DESCRIPTION = "A heirarchical component-based logging system"
|
6
|
+
GEM_NAME = 'highlogger'
|
7
|
+
RUBYFORGE_PROJECT = 'ab-ext'
|
8
|
+
HOMEPATH = "http://#{RUBYFORGE_PROJECT}.rubyforge.org"
|
9
|
+
DOWNLOAD_PATH = "http://rubyforge.org/projects/#{RUBYFORGE_PROJECT}"
|
10
|
+
|
11
|
+
@config_file = "~/.rubyforge/user-config.yml"
|
12
|
+
@config = nil
|
13
|
+
RUBYFORGE_USERNAME = "unknown"
|
14
|
+
def rubyforge_username
|
15
|
+
unless @config
|
16
|
+
begin
|
17
|
+
@config = YAML.load(File.read(File.expand_path(@config_file)))
|
18
|
+
rescue
|
19
|
+
puts <<-EOS
|
20
|
+
ERROR: No rubyforge config file found: #{@config_file}
|
21
|
+
Run 'rubyforge setup' to prepare your env for access to Rubyforge
|
22
|
+
- See http://newgem.rubyforge.org/rubyforge.html for more details
|
23
|
+
EOS
|
24
|
+
exit
|
25
|
+
end
|
26
|
+
end
|
27
|
+
RUBYFORGE_USERNAME.replace @config["username"]
|
28
|
+
end
|
29
|
+
|
30
|
+
|
31
|
+
REV = nil
|
32
|
+
# UNCOMMENT IF REQUIRED:
|
33
|
+
# REV = `svn info`.each {|line| if line =~ /^Revision:/ then k,v = line.split(': '); break v.chomp; else next; end} rescue nil
|
34
|
+
VERS = Highlogger::VERSION::STRING + (REV ? ".#{REV}" : "")
|
35
|
+
RDOC_OPTS = ['--quiet', '--title', 'highlogger documentation',
|
36
|
+
"--opname", "index.html",
|
37
|
+
"--line-numbers",
|
38
|
+
"--main", "README",
|
39
|
+
"--inline-source"]
|
40
|
+
|
41
|
+
class Hoe
|
42
|
+
def extra_deps
|
43
|
+
@extra_deps.reject! { |x| Array(x).first == 'hoe' }
|
44
|
+
@extra_deps
|
45
|
+
end
|
46
|
+
end
|
47
|
+
|
48
|
+
# Generate all the Rake tasks
|
49
|
+
# Run 'rake -T' to see list of generated tasks (from gem root directory)
|
50
|
+
hoe = Hoe.new(GEM_NAME, VERS) do |p|
|
51
|
+
p.author = AUTHOR
|
52
|
+
p.description = DESCRIPTION
|
53
|
+
p.email = EMAIL
|
54
|
+
p.summary = DESCRIPTION
|
55
|
+
p.url = HOMEPATH
|
56
|
+
p.rubyforge_name = RUBYFORGE_PROJECT if RUBYFORGE_PROJECT
|
57
|
+
p.test_globs = ["test/**/test_*.rb"]
|
58
|
+
p.clean_globs |= ['**/.*.sw?', '*.gem', '.config', '**/.DS_Store'] #An array of file patterns to delete on clean.
|
59
|
+
|
60
|
+
# == Optional
|
61
|
+
p.changes = p.paragraphs_of("History.txt", 0..1).join("\\n\\n")
|
62
|
+
#p.extra_deps = [] # An array of rubygem dependencies [name, version], e.g. [ ['active_support', '>= 1.3.1'] ]
|
63
|
+
|
64
|
+
#p.spec_extras = {} # A hash of extra values to set in the gemspec.
|
65
|
+
|
66
|
+
end
|
67
|
+
|
68
|
+
CHANGES = hoe.paragraphs_of('History.txt', 0..1).join("\\n\\n")
|
69
|
+
PATH = (RUBYFORGE_PROJECT == GEM_NAME) ? RUBYFORGE_PROJECT : "#{RUBYFORGE_PROJECT}/#{GEM_NAME}"
|
70
|
+
hoe.remote_rdoc_dir = File.join(PATH.gsub(/^#{RUBYFORGE_PROJECT}\/?/,''), 'rdoc')
|
@@ -0,0 +1,17 @@
|
|
1
|
+
require 'fileutils'
|
2
|
+
include FileUtils
|
3
|
+
|
4
|
+
require 'rubygems'
|
5
|
+
%w[rake hoe newgem rubigen].each do |req_gem|
|
6
|
+
begin
|
7
|
+
require req_gem
|
8
|
+
rescue LoadError
|
9
|
+
puts "This Rakefile requires the '#{req_gem}' RubyGem."
|
10
|
+
puts "Installation: gem install #{req_gem} -y"
|
11
|
+
exit
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
$:.unshift(File.join(File.dirname(__FILE__), %w[.. lib]))
|
16
|
+
|
17
|
+
require 'highlogger'
|
data/lib/highlogger.rb
ADDED
@@ -0,0 +1,171 @@
|
|
1
|
+
$:.unshift File.dirname(__FILE__)
|
2
|
+
|
3
|
+
require "logger"
|
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
|
+
# This class implements a simple heirarchical logging system.
|
21
|
+
#
|
22
|
+
class HighLogger < Logger
|
23
|
+
def initialize(*super_args)
|
24
|
+
super(*super_args)
|
25
|
+
@logmap = {}
|
26
|
+
@default_level = Logger::WARN
|
27
|
+
end
|
28
|
+
|
29
|
+
def add(component, severity, message = nil, progname = nil, &block)
|
30
|
+
return if severity == :none
|
31
|
+
|
32
|
+
level = level_for_component(component)
|
33
|
+
return if level and severity < level
|
34
|
+
|
35
|
+
# Logic copied from Logger class
|
36
|
+
if message.nil?
|
37
|
+
if block_given?
|
38
|
+
message = yield
|
39
|
+
else
|
40
|
+
message = progname
|
41
|
+
progname = @progname
|
42
|
+
end
|
43
|
+
end
|
44
|
+
|
45
|
+
super(severity, component + ": " + message, progname, &block);
|
46
|
+
end
|
47
|
+
|
48
|
+
alias log add
|
49
|
+
|
50
|
+
def debug?(*args)
|
51
|
+
return super() if args.empty?
|
52
|
+
@logmap[args[0]] <= Logger::DEBUG
|
53
|
+
end
|
54
|
+
|
55
|
+
def info?(*args)
|
56
|
+
return super() if args.empty?
|
57
|
+
@logmap[args[0]] <= Logger::INFO
|
58
|
+
end
|
59
|
+
|
60
|
+
def warn?(*args)
|
61
|
+
return super() if args.empty?
|
62
|
+
@logmap[args[0]] <= Logger::WARN
|
63
|
+
end
|
64
|
+
|
65
|
+
def error?(*args)
|
66
|
+
return super() if args.empty?
|
67
|
+
@logmap[args[0]] <= Logger::ERROR
|
68
|
+
end
|
69
|
+
|
70
|
+
def fatal?(*args)
|
71
|
+
return super() if args.empty?
|
72
|
+
@logmap[args[0]] <= Logger::FATAL
|
73
|
+
end
|
74
|
+
|
75
|
+
def debug(component, progname = nil, &block)
|
76
|
+
add(component, Logger::DEBUG, nil, progname, &block)
|
77
|
+
end
|
78
|
+
|
79
|
+
def info(component, progname = nil, &block)
|
80
|
+
add(component, Logger::INFO, nil, progname, &block)
|
81
|
+
end
|
82
|
+
|
83
|
+
def warn(component, progname = nil, &block)
|
84
|
+
add(component, Logger::WARN, nil, progname, &block)
|
85
|
+
end
|
86
|
+
|
87
|
+
def error(component, progname = nil, &block)
|
88
|
+
add(component, Logger::ERROR, nil, progname, &block)
|
89
|
+
end
|
90
|
+
|
91
|
+
def fatal(component, progname = nil, &block)
|
92
|
+
add(component, Logger::FATAL, nil, progname, &block)
|
93
|
+
end
|
94
|
+
|
95
|
+
def unknown(component, progname = nil, &block)
|
96
|
+
add(component, Logger::UNKNOWN, nil, progname, &block)
|
97
|
+
end
|
98
|
+
|
99
|
+
|
100
|
+
# Have this logger read a configuration file to determine
|
101
|
+
# what components will log at what levels.
|
102
|
+
#
|
103
|
+
def read_config_file(filename)
|
104
|
+
f = File.new(filename)
|
105
|
+
buf = f.read()
|
106
|
+
read_config_buffer(buf)
|
107
|
+
end
|
108
|
+
|
109
|
+
# Have this logger read a configuration buffer to determine
|
110
|
+
# what components will log at what levels.
|
111
|
+
#
|
112
|
+
def read_config_buffer(buf)
|
113
|
+
buf.each_line do |line|
|
114
|
+
mobj = /^\s*([A-Za-z0-9_:]+)\s*=\s*(.*?)\s*$/.match(line)
|
115
|
+
raise "Can't parse config line '#{line}'!" unless mobj
|
116
|
+
|
117
|
+
loglevel = parse_loglevel(mobj[2])
|
118
|
+
if mobj[1] =~ /default/i
|
119
|
+
@default_level = loglevel
|
120
|
+
parent.level = loglevel
|
121
|
+
next
|
122
|
+
end
|
123
|
+
|
124
|
+
@logmap[mobj[1]] = loglevel
|
125
|
+
end
|
126
|
+
end
|
127
|
+
|
128
|
+
private
|
129
|
+
|
130
|
+
def parse_loglevel(string)
|
131
|
+
if string =~ /debug/i
|
132
|
+
return Logger::DEBUG
|
133
|
+
end
|
134
|
+
if string =~ /info/i
|
135
|
+
return Logger::INFO
|
136
|
+
end
|
137
|
+
if string =~ /warn/i or string =~ /warning/i
|
138
|
+
return Logger::WARN
|
139
|
+
end
|
140
|
+
if string =~ /err/i or string =~ /error/i
|
141
|
+
return Logger::ERROR
|
142
|
+
end
|
143
|
+
if string =~ /fatal/i
|
144
|
+
return Logger::FATAL
|
145
|
+
end
|
146
|
+
if string =~ /all/i or string =~ /any/i
|
147
|
+
return Logger::DEBUG
|
148
|
+
end
|
149
|
+
if string =~ /unknown/i
|
150
|
+
return Logger::UNKNOWN
|
151
|
+
end
|
152
|
+
if string =~ /none/i
|
153
|
+
return :none
|
154
|
+
end
|
155
|
+
raise "Can't parse logging level from '#{string}'!"
|
156
|
+
end
|
157
|
+
|
158
|
+
def level_for_component(component)
|
159
|
+
return @logmap[component] if @logmap[component]
|
160
|
+
|
161
|
+
complist = component.split(/:/)
|
162
|
+
begin
|
163
|
+
complist = complist[0..-2]
|
164
|
+
this_comp = complist.join(":")
|
165
|
+
return @logmap[this_comp] if @logmap[this_comp]
|
166
|
+
end while not complist.empty?
|
167
|
+
|
168
|
+
@default_level
|
169
|
+
end
|
170
|
+
|
171
|
+
end # class HighLogger
|
data/log/debug.log
ADDED
File without changes
|
data/script/destroy
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
APP_ROOT = File.join(File.dirname(__FILE__), '..')
|
3
|
+
|
4
|
+
begin
|
5
|
+
require 'rubigen'
|
6
|
+
rescue LoadError
|
7
|
+
require 'rubygems'
|
8
|
+
require 'rubigen'
|
9
|
+
end
|
10
|
+
require 'rubigen/scripts/destroy'
|
11
|
+
|
12
|
+
ARGV.shift if ['--help', '-h'].include?(ARGV[0])
|
13
|
+
RubiGen::Base.use_component_sources! [:rubygems, :newgem, :newgem_theme]
|
14
|
+
RubiGen::Scripts::Destroy.new.run(ARGV)
|
data/script/generate
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
APP_ROOT = File.join(File.dirname(__FILE__), '..')
|
3
|
+
|
4
|
+
begin
|
5
|
+
require 'rubigen'
|
6
|
+
rescue LoadError
|
7
|
+
require 'rubygems'
|
8
|
+
require 'rubigen'
|
9
|
+
end
|
10
|
+
require 'rubigen/scripts/generate'
|
11
|
+
|
12
|
+
ARGV.shift if ['--help', '-h'].include?(ARGV[0])
|
13
|
+
RubiGen::Base.use_component_sources! [:rubygems, :newgem, :newgem_theme]
|
14
|
+
RubiGen::Scripts::Generate.new.run(ARGV)
|
data/script/txt2html
ADDED
@@ -0,0 +1,74 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require 'rubygems'
|
4
|
+
begin
|
5
|
+
require 'newgem'
|
6
|
+
rescue LoadError
|
7
|
+
puts "\n\nGenerating the website requires the newgem RubyGem"
|
8
|
+
puts "Install: gem install newgem\n\n"
|
9
|
+
exit(1)
|
10
|
+
end
|
11
|
+
require 'redcloth'
|
12
|
+
require 'syntax/convertors/html'
|
13
|
+
require 'erb'
|
14
|
+
require File.dirname(__FILE__) + '/../lib/highlogger/version.rb'
|
15
|
+
|
16
|
+
version = Highlogger::VERSION::STRING
|
17
|
+
download = 'http://rubyforge.org/projects/highlogger'
|
18
|
+
|
19
|
+
class Fixnum
|
20
|
+
def ordinal
|
21
|
+
# teens
|
22
|
+
return 'th' if (10..19).include?(self % 100)
|
23
|
+
# others
|
24
|
+
case self % 10
|
25
|
+
when 1: return 'st'
|
26
|
+
when 2: return 'nd'
|
27
|
+
when 3: return 'rd'
|
28
|
+
else return 'th'
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
class Time
|
34
|
+
def pretty
|
35
|
+
return "#{mday}#{mday.ordinal} #{strftime('%B')} #{year}"
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
def convert_syntax(syntax, source)
|
40
|
+
return Syntax::Convertors::HTML.for_syntax(syntax).convert(source).gsub(%r!^<pre>|</pre>$!,'')
|
41
|
+
end
|
42
|
+
|
43
|
+
if ARGV.length >= 1
|
44
|
+
src, template = ARGV
|
45
|
+
template ||= File.join(File.dirname(__FILE__), '/../website/template.rhtml')
|
46
|
+
|
47
|
+
else
|
48
|
+
puts("Usage: #{File.split($0).last} source.txt [template.rhtml] > output.html")
|
49
|
+
exit!
|
50
|
+
end
|
51
|
+
|
52
|
+
template = ERB.new(File.open(template).read)
|
53
|
+
|
54
|
+
title = nil
|
55
|
+
body = nil
|
56
|
+
File.open(src) do |fsrc|
|
57
|
+
title_text = fsrc.readline
|
58
|
+
body_text = fsrc.read
|
59
|
+
syntax_items = []
|
60
|
+
body_text.gsub!(%r!<(pre|code)[^>]*?syntax=['"]([^'"]+)[^>]*>(.*?)</\1>!m){
|
61
|
+
ident = syntax_items.length
|
62
|
+
element, syntax, source = $1, $2, $3
|
63
|
+
syntax_items << "<#{element} class='syntax'>#{convert_syntax(syntax, source)}</#{element}>"
|
64
|
+
"syntax-temp-#{ident}"
|
65
|
+
}
|
66
|
+
title = RedCloth.new(title_text).to_html.gsub(%r!<.*?>!,'').strip
|
67
|
+
body = RedCloth.new(body_text).to_html
|
68
|
+
body.gsub!(%r!(?:<pre><code>)?syntax-temp-(\d+)(?:</code></pre>)?!){ syntax_items[$1.to_i] }
|
69
|
+
end
|
70
|
+
stat = File.stat(src)
|
71
|
+
created = stat.ctime
|
72
|
+
modified = stat.mtime
|
73
|
+
|
74
|
+
$stdout << template.result(binding)
|