wordnet 1.0.0.pre.127 → 1.0.0.pre.134

Sign up to get free protection for your applications and to get access to all the features.
metadata.gz.sig CHANGED
Binary file
@@ -1,62 +0,0 @@
1
- #!/usr/bin/env ruby
2
-
3
- require 'wordnet' unless defined?( WordNet )
4
-
5
- module WordNet
6
-
7
- # Add logging to a WordNet class. Including classes get #log and #log_debug methods.
8
- module Loggable
9
-
10
- # Level names to levels
11
- LEVEL = {
12
- :debug => Logger::DEBUG,
13
- :info => Logger::INFO,
14
- :warn => Logger::WARN,
15
- :error => Logger::ERROR,
16
- :fatal => Logger::FATAL,
17
- }
18
-
19
- ### A logging proxy class that wraps calls to the logger into calls that include
20
- ### the name of the calling class.
21
- ### @private
22
- class ClassNameProxy
23
-
24
- ### Create a new proxy for the given +klass+.
25
- def initialize( klass, force_debug=false )
26
- @classname = klass.name
27
- @force_debug = force_debug
28
- end
29
-
30
- ### Delegate calls the global logger with the class name as the 'progname'
31
- ### argument.
32
- def method_missing( sym, msg=nil, &block )
33
- return super unless LEVEL.key?( sym )
34
- sym = :debug if @force_debug
35
- WordNet.logger.add( LEVEL[sym], msg, @classname, &block )
36
- end
37
- end # ClassNameProxy
38
-
39
- #########
40
- protected
41
- #########
42
-
43
- ### Copy constructor -- clear the original's log proxy.
44
- def initialize_copy( original )
45
- @log_proxy = @log_debug_proxy = nil
46
- super
47
- end
48
-
49
- ### Return the proxied logger.
50
- def log
51
- @log_proxy ||= ClassNameProxy.new( self.class )
52
- end
53
-
54
- ### Return a proxied "debug" logger that ignores other level specification.
55
- def log_debug
56
- @log_debug_proxy ||= ClassNameProxy.new( self.class, true )
57
- end
58
- end # module Loggable
59
-
60
-
61
- end # module WordNet
62
-
data/lib/wordnet/utils.rb DELETED
@@ -1,126 +0,0 @@
1
- #!/usr/bin/ruby
2
-
3
- require 'logger'
4
- require 'erb'
5
-
6
- require 'wordnet' unless defined?( WordNet )
7
-
8
-
9
- module WordNet
10
-
11
- # A alternate formatter for Logger instances.
12
- # @private
13
- class LogFormatter < Logger::Formatter
14
-
15
- # The format to output unless debugging is turned on
16
- DEFAULT_FORMAT = "[%1$s.%2$06d %3$d/%4$s] %5$5s -- %7$s\n"
17
-
18
- # The format to output if debugging is turned on
19
- DEFAULT_DEBUG_FORMAT = "[%1$s.%2$06d %3$d/%4$s] %5$5s {%6$s} -- %7$s\n"
20
-
21
-
22
- ### Initialize the formatter with a reference to the logger so it can check for log level.
23
- def initialize( logger, format=DEFAULT_FORMAT, debug=DEFAULT_DEBUG_FORMAT ) # :notnew:
24
- @logger = logger
25
- @format = format
26
- @debug_format = debug
27
-
28
- super()
29
- end
30
-
31
- ######
32
- public
33
- ######
34
-
35
- # The Logger object associated with the formatter
36
- attr_accessor :logger
37
-
38
- # The logging format string
39
- attr_accessor :format
40
-
41
- # The logging format string that's used when outputting in debug mode
42
- attr_accessor :debug_format
43
-
44
-
45
- ### Log using either the DEBUG_FORMAT if the associated logger is at ::DEBUG level or
46
- ### using FORMAT if it's anything less verbose.
47
- def call( severity, time, progname, msg )
48
- args = [
49
- time.strftime( '%Y-%m-%d %H:%M:%S' ), # %1$s
50
- time.usec, # %2$d
51
- Process.pid, # %3$d
52
- Thread.current == Thread.main ? 'main' : Thread.object_id, # %4$s
53
- severity, # %5$s
54
- progname, # %6$s
55
- msg # %7$s
56
- ]
57
-
58
- if @logger.level == Logger::DEBUG
59
- return self.debug_format % args
60
- else
61
- return self.format % args
62
- end
63
- end
64
- end # class LogFormatter
65
-
66
-
67
- # An alternate formatter for Logger instances that outputs +div+ HTML
68
- # fragments.
69
- # @private
70
- class HtmlLogFormatter < Logger::Formatter
71
- include ERB::Util # for html_escape()
72
-
73
- # The default HTML fragment that'll be used as the template for each log message.
74
- HTML_LOG_FORMAT = %q{
75
- <div class="log-message %5$s">
76
- <span class="log-time">%1$s.%2$06d</span>
77
- [
78
- <span class="log-pid">%3$d</span>
79
- /
80
- <span class="log-tid">%4$s</span>
81
- ]
82
- <span class="log-level">%5$s</span>
83
- :
84
- <span class="log-name">%6$s</span>
85
- <span class="log-message-text">%7$s</span>
86
- </div>
87
- }
88
-
89
- ### Override the logging formats with ones that generate HTML fragments
90
- def initialize( logger, format=HTML_LOG_FORMAT ) # :notnew:
91
- @logger = logger
92
- @format = format
93
- super()
94
- end
95
-
96
-
97
- ######
98
- public
99
- ######
100
-
101
- # The HTML fragment that will be used as a format() string for the log
102
- attr_accessor :format
103
-
104
-
105
- ### Return a log message composed out of the arguments formatted using the
106
- ### formatter's format string
107
- def call( severity, time, progname, msg )
108
- args = [
109
- time.strftime( '%Y-%m-%d %H:%M:%S' ), # %1$s
110
- time.usec, # %2$d
111
- Process.pid, # %3$d
112
- Thread.current == Thread.main ? 'main' : Thread.object_id, # %4$s
113
- severity.downcase, # %5$s
114
- progname, # %6$s
115
- html_escape( msg ).gsub(/\n/, '<br />') # %7$s
116
- ]
117
-
118
- return self.format % args
119
- end
120
-
121
- end # class HtmlLogFormatter
122
-
123
- end # module WordNet
124
-
125
- # vim: set nosta noet ts=4 sw=4:
126
-