arrow 1.0.7
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.
- data/ChangeLog +1590 -0
- data/LICENSE +28 -0
- data/README +75 -0
- data/Rakefile +366 -0
- data/Rakefile.local +63 -0
- data/data/arrow/applets/TEMPLATE.rb.tpl +53 -0
- data/data/arrow/applets/args.rb +50 -0
- data/data/arrow/applets/config.rb +55 -0
- data/data/arrow/applets/error.rb +63 -0
- data/data/arrow/applets/files.rb +46 -0
- data/data/arrow/applets/inspect.rb +46 -0
- data/data/arrow/applets/nosuchapplet.rb +31 -0
- data/data/arrow/applets/status.rb +92 -0
- data/data/arrow/applets/test.rb +133 -0
- data/data/arrow/applets/tutorial/counter.rb +96 -0
- data/data/arrow/applets/tutorial/dingus.rb +67 -0
- data/data/arrow/applets/tutorial/hello.rb +34 -0
- data/data/arrow/applets/tutorial/hello2.rb +73 -0
- data/data/arrow/applets/tutorial/imgtext.rb +90 -0
- data/data/arrow/applets/tutorial/imgtext2.rb +286 -0
- data/data/arrow/applets/tutorial/index.rb +36 -0
- data/data/arrow/applets/tutorial/logo.rb +98 -0
- data/data/arrow/applets/tutorial/memcache.rb +61 -0
- data/data/arrow/applets/tutorial/missing.rb +37 -0
- data/data/arrow/applets/tutorial/protected.rb +100 -0
- data/data/arrow/applets/tutorial/redirector.rb +52 -0
- data/data/arrow/applets/tutorial/rndimages.rb +159 -0
- data/data/arrow/applets/tutorial/sharenotes.rb +83 -0
- data/data/arrow/applets/tutorial/subclassed-hello.rb +32 -0
- data/data/arrow/applets/tutorial/superhello.rb +72 -0
- data/data/arrow/applets/tutorial/timeclock.rb +78 -0
- data/data/arrow/applets/view-applet.rb +123 -0
- data/data/arrow/applets/view-template.rb +85 -0
- data/data/arrow/applets/wiki.rb +274 -0
- data/data/arrow/templates/TEMPLATE.tmpl.tpl +36 -0
- data/data/arrow/templates/applet-status.tmpl +153 -0
- data/data/arrow/templates/args-display.tmpl +120 -0
- data/data/arrow/templates/config/display-table.tmpl +36 -0
- data/data/arrow/templates/config/display.tmpl +36 -0
- data/data/arrow/templates/counter-deleted.tmpl +33 -0
- data/data/arrow/templates/counter.tmpl +59 -0
- data/data/arrow/templates/dingus.tmpl +55 -0
- data/data/arrow/templates/enumtable.tmpl +8 -0
- data/data/arrow/templates/error-display.tmpl +92 -0
- data/data/arrow/templates/filemap.tmpl +89 -0
- data/data/arrow/templates/hello-world-src.tmpl +34 -0
- data/data/arrow/templates/hello-world.tmpl +60 -0
- data/data/arrow/templates/imgtext/fontlist.tmpl +46 -0
- data/data/arrow/templates/imgtext/form.tmpl +70 -0
- data/data/arrow/templates/imgtext/reload-error.tmpl +40 -0
- data/data/arrow/templates/imgtext/reload.tmpl +55 -0
- data/data/arrow/templates/inspect/display.tmpl +80 -0
- data/data/arrow/templates/loginform.tmpl +64 -0
- data/data/arrow/templates/logout.tmpl +32 -0
- data/data/arrow/templates/memcache/display.tmpl +41 -0
- data/data/arrow/templates/navbar.incl +27 -0
- data/data/arrow/templates/nosuchapplet.tmpl +32 -0
- data/data/arrow/templates/printsource.tmpl +35 -0
- data/data/arrow/templates/protected.tmpl +36 -0
- data/data/arrow/templates/rndimages.tmpl +38 -0
- data/data/arrow/templates/service-response.tmpl +13 -0
- data/data/arrow/templates/sharenotes/display.tmpl +38 -0
- data/data/arrow/templates/status.tmpl +120 -0
- data/data/arrow/templates/templateviewer.tmpl +43 -0
- data/data/arrow/templates/test/harness.tmpl +57 -0
- data/data/arrow/templates/test/list.tmpl +48 -0
- data/data/arrow/templates/test/problem.tmpl +42 -0
- data/data/arrow/templates/tutorial/index.tmpl +37 -0
- data/data/arrow/templates/tutorial/missingapplet.tmpl +29 -0
- data/data/arrow/templates/view-applet-nosuch.tmpl +32 -0
- data/data/arrow/templates/view-applet.tmpl +40 -0
- data/data/arrow/templates/view-template.tmpl +83 -0
- data/data/arrow/templates/wiki/formerror.tmpl +47 -0
- data/data/arrow/templates/wiki/markup_help.incl +6 -0
- data/data/arrow/templates/wiki/new.tmpl +56 -0
- data/data/arrow/templates/wiki/new_system.tmpl +122 -0
- data/data/arrow/templates/wiki/sectionlist.tmpl +43 -0
- data/data/arrow/templates/wiki/show.tmpl +34 -0
- data/docs/manual/layouts/default.page +43 -0
- data/docs/manual/lib/api-filter.rb +81 -0
- data/docs/manual/lib/editorial-filter.rb +64 -0
- data/docs/manual/lib/examples-filter.rb +244 -0
- data/docs/manual/lib/links-filter.rb +117 -0
- data/lib/apache/fakerequest.rb +448 -0
- data/lib/apache/logger.rb +33 -0
- data/lib/arrow.rb +51 -0
- data/lib/arrow/acceptparam.rb +207 -0
- data/lib/arrow/applet.rb +725 -0
- data/lib/arrow/appletmixins.rb +218 -0
- data/lib/arrow/appletregistry.rb +590 -0
- data/lib/arrow/applettestcase.rb +503 -0
- data/lib/arrow/broker.rb +255 -0
- data/lib/arrow/cache.rb +176 -0
- data/lib/arrow/config-loaders/yaml.rb +75 -0
- data/lib/arrow/config.rb +615 -0
- data/lib/arrow/constants.rb +24 -0
- data/lib/arrow/cookie.rb +359 -0
- data/lib/arrow/cookieset.rb +108 -0
- data/lib/arrow/dispatcher.rb +368 -0
- data/lib/arrow/dispatcherloader.rb +50 -0
- data/lib/arrow/exceptions.rb +61 -0
- data/lib/arrow/fallbackhandler.rb +48 -0
- data/lib/arrow/formvalidator.rb +631 -0
- data/lib/arrow/htmltokenizer.rb +343 -0
- data/lib/arrow/logger.rb +488 -0
- data/lib/arrow/logger/apacheoutputter.rb +69 -0
- data/lib/arrow/logger/arrayoutputter.rb +63 -0
- data/lib/arrow/logger/coloroutputter.rb +111 -0
- data/lib/arrow/logger/fileoutputter.rb +96 -0
- data/lib/arrow/logger/htmloutputter.rb +54 -0
- data/lib/arrow/logger/outputter.rb +123 -0
- data/lib/arrow/mixins.rb +425 -0
- data/lib/arrow/monkeypatches.rb +94 -0
- data/lib/arrow/object.rb +117 -0
- data/lib/arrow/path.rb +196 -0
- data/lib/arrow/service.rb +447 -0
- data/lib/arrow/session.rb +289 -0
- data/lib/arrow/session/dbstore.rb +100 -0
- data/lib/arrow/session/filelock.rb +160 -0
- data/lib/arrow/session/filestore.rb +132 -0
- data/lib/arrow/session/id.rb +98 -0
- data/lib/arrow/session/lock.rb +253 -0
- data/lib/arrow/session/md5id.rb +42 -0
- data/lib/arrow/session/nulllock.rb +42 -0
- data/lib/arrow/session/posixlock.rb +166 -0
- data/lib/arrow/session/sha1id.rb +54 -0
- data/lib/arrow/session/store.rb +366 -0
- data/lib/arrow/session/usertrackid.rb +52 -0
- data/lib/arrow/spechelpers.rb +73 -0
- data/lib/arrow/template.rb +713 -0
- data/lib/arrow/template/attr.rb +31 -0
- data/lib/arrow/template/call.rb +31 -0
- data/lib/arrow/template/comment.rb +33 -0
- data/lib/arrow/template/container.rb +118 -0
- data/lib/arrow/template/else.rb +41 -0
- data/lib/arrow/template/elsif.rb +44 -0
- data/lib/arrow/template/escape.rb +53 -0
- data/lib/arrow/template/export.rb +87 -0
- data/lib/arrow/template/for.rb +145 -0
- data/lib/arrow/template/if.rb +78 -0
- data/lib/arrow/template/import.rb +119 -0
- data/lib/arrow/template/include.rb +206 -0
- data/lib/arrow/template/iterator.rb +208 -0
- data/lib/arrow/template/nodes.rb +734 -0
- data/lib/arrow/template/parser.rb +571 -0
- data/lib/arrow/template/prettyprint.rb +53 -0
- data/lib/arrow/template/render.rb +191 -0
- data/lib/arrow/template/selectlist.rb +94 -0
- data/lib/arrow/template/set.rb +87 -0
- data/lib/arrow/template/timedelta.rb +81 -0
- data/lib/arrow/template/unless.rb +78 -0
- data/lib/arrow/template/urlencode.rb +51 -0
- data/lib/arrow/template/yield.rb +139 -0
- data/lib/arrow/templatefactory.rb +125 -0
- data/lib/arrow/testcase.rb +567 -0
- data/lib/arrow/transaction.rb +608 -0
- data/rake/191_compat.rb +26 -0
- data/rake/dependencies.rb +76 -0
- data/rake/documentation.rb +114 -0
- data/rake/helpers.rb +502 -0
- data/rake/hg.rb +282 -0
- data/rake/manual.rb +787 -0
- data/rake/packaging.rb +129 -0
- data/rake/publishing.rb +278 -0
- data/rake/style.rb +62 -0
- data/rake/svn.rb +668 -0
- data/rake/testing.rb +187 -0
- data/rake/verifytask.rb +64 -0
- data/spec/arrow/acceptparam_spec.rb +157 -0
- data/spec/arrow/applet_spec.rb +575 -0
- data/spec/arrow/appletmixins_spec.rb +409 -0
- data/spec/arrow/appletregistry_spec.rb +294 -0
- data/spec/arrow/broker_spec.rb +153 -0
- data/spec/arrow/config_spec.rb +224 -0
- data/spec/arrow/cookieset_spec.rb +164 -0
- data/spec/arrow/dispatcher_spec.rb +137 -0
- data/spec/arrow/dispatcherloader_spec.rb +65 -0
- data/spec/arrow/formvalidator_spec.rb +781 -0
- data/spec/arrow/logger_spec.rb +346 -0
- data/spec/arrow/mixins_spec.rb +120 -0
- data/spec/arrow/service_spec.rb +645 -0
- data/spec/arrow/session_spec.rb +121 -0
- data/spec/arrow/template/iterator_spec.rb +222 -0
- data/spec/arrow/templatefactory_spec.rb +185 -0
- data/spec/arrow/transaction_spec.rb +319 -0
- data/spec/arrow_spec.rb +37 -0
- data/spec/lib/appletmatchers.rb +281 -0
- data/spec/lib/constants.rb +77 -0
- data/spec/lib/helpers.rb +41 -0
- data/spec/lib/matchers.rb +44 -0
- data/tests/cookie.tests.rb +310 -0
- data/tests/path.tests.rb +157 -0
- data/tests/session.tests.rb +111 -0
- data/tests/session_id.tests.rb +82 -0
- data/tests/session_lock.tests.rb +191 -0
- data/tests/session_store.tests.rb +53 -0
- data/tests/template.tests.rb +1360 -0
- metadata +339 -0
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
#!/usr/bin/env ruby
|
|
2
|
+
|
|
3
|
+
require 'arrow/mixins'
|
|
4
|
+
require 'arrow/logger'
|
|
5
|
+
require 'arrow/logger/outputter'
|
|
6
|
+
|
|
7
|
+
# The Arrow::Logger::ApacheOutputter class, a derivative of
|
|
8
|
+
# Apache::Logger::Outputter. Instances of this class write log messages of the
|
|
9
|
+
# corresponding error level to the Apache log
|
|
10
|
+
#
|
|
11
|
+
# == Authors
|
|
12
|
+
#
|
|
13
|
+
# * Michael Granger <ged@FaerieMUD.org>
|
|
14
|
+
#
|
|
15
|
+
# Please see the file LICENSE in the top-level directory for licensing details.
|
|
16
|
+
#
|
|
17
|
+
class Arrow::Logger::ApacheOutputter < Arrow::Logger::Outputter
|
|
18
|
+
|
|
19
|
+
# The default description
|
|
20
|
+
DefaultDescription = "Apache Log Outputter"
|
|
21
|
+
|
|
22
|
+
# The default interpolatable string that's used to build the message to
|
|
23
|
+
# output
|
|
24
|
+
DefaultFormat =
|
|
25
|
+
%q{#{name}#{frame ? '('+frame+')' : ''}: #{msg[0,2048]}}
|
|
26
|
+
|
|
27
|
+
# The Logger log levels (copied for easy access)
|
|
28
|
+
LEVELS = Arrow::Logger::LEVELS
|
|
29
|
+
|
|
30
|
+
|
|
31
|
+
#############################################################
|
|
32
|
+
### I N S T A N C E M E T H O D S
|
|
33
|
+
#############################################################
|
|
34
|
+
|
|
35
|
+
### Create a new Arrow::Logger::ApacheOutputter object that will write
|
|
36
|
+
### to the apache log, and use the given +description+ and +format+.
|
|
37
|
+
def initialize( uri, description=DefaultDescription, format=DefaultFormat )
|
|
38
|
+
super
|
|
39
|
+
end
|
|
40
|
+
|
|
41
|
+
|
|
42
|
+
######
|
|
43
|
+
public
|
|
44
|
+
######
|
|
45
|
+
|
|
46
|
+
### Write the given +level+, +name+, +frame+, and +msg+ to the target
|
|
47
|
+
### output mechanism.
|
|
48
|
+
def write( time, level, name, frame, msg )
|
|
49
|
+
return unless defined?( ::Apache )
|
|
50
|
+
srvr = ::Apache.request.server
|
|
51
|
+
return unless srvr.loglevel >= LEVELS[ level ]
|
|
52
|
+
|
|
53
|
+
# Translate calls to log.warning into Apache::Server#log_warn
|
|
54
|
+
level = :warn if level == :warning
|
|
55
|
+
|
|
56
|
+
logMethod = srvr.method( "log_#{level}" )
|
|
57
|
+
super {|msg|
|
|
58
|
+
# Escape any unexpanded sprintf format patterns
|
|
59
|
+
msg.gsub!( /%/, '%%' )
|
|
60
|
+
logMethod.call( msg )
|
|
61
|
+
}
|
|
62
|
+
end
|
|
63
|
+
|
|
64
|
+
|
|
65
|
+
end # class Arrow::Logger::ApacheOutputter
|
|
66
|
+
|
|
67
|
+
|
|
68
|
+
|
|
69
|
+
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
#!/usr/bin/env ruby
|
|
2
|
+
|
|
3
|
+
require 'arrow/mixins'
|
|
4
|
+
require 'arrow/logger/outputter'
|
|
5
|
+
require 'arrow/logger/htmloutputter'
|
|
6
|
+
|
|
7
|
+
# Accumulate logging messages in HTML fragments into an Array which can later be fetched.
|
|
8
|
+
#
|
|
9
|
+
# == Authors
|
|
10
|
+
#
|
|
11
|
+
# * Michael Granger <ged@FaerieMUD.org>
|
|
12
|
+
#
|
|
13
|
+
# Please see the file LICENSE in the top-level directory for licensing details.
|
|
14
|
+
#
|
|
15
|
+
class Arrow::Logger::ArrayOutputter < Arrow::Logger::Outputter
|
|
16
|
+
include Arrow::HTMLUtilities
|
|
17
|
+
|
|
18
|
+
# Default decription used when creating instances
|
|
19
|
+
DEFAULT_DESCRIPTION = "Array Outputter"
|
|
20
|
+
|
|
21
|
+
# The default logging output format
|
|
22
|
+
HTML_FORMAT = %q{
|
|
23
|
+
<div class="log-message #{level}">
|
|
24
|
+
<span class="log-time">#{time.strftime('%Y/%m/%d %H:%M:%S')}</span>
|
|
25
|
+
<span class="log-level">#{level}</span>
|
|
26
|
+
:
|
|
27
|
+
<span class="log-name">#{escaped_name}</span>
|
|
28
|
+
<span class="log-frame">#{frame ? '('+frame+'): ' : ''}</span>
|
|
29
|
+
<span class="log-message-text">#{escaped_msg}</span>
|
|
30
|
+
</div>
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
### Override the default to intitialize the Array.
|
|
34
|
+
def initialize( uri, description=DEFAULT_DESCRIPTION, format=HTML_FORMAT ) # :notnew:
|
|
35
|
+
@array = []
|
|
36
|
+
super
|
|
37
|
+
end
|
|
38
|
+
|
|
39
|
+
|
|
40
|
+
######
|
|
41
|
+
public
|
|
42
|
+
######
|
|
43
|
+
|
|
44
|
+
# The Array any output log messages get appended to
|
|
45
|
+
attr_reader :array
|
|
46
|
+
|
|
47
|
+
|
|
48
|
+
### Write the given +level+, +name+, +frame+, and +msg+ to the target
|
|
49
|
+
### output mechanism. Subclasses can call this with a block which will
|
|
50
|
+
### be passed the formatted message. If no block is supplied by the
|
|
51
|
+
### child, this method will check to see if $DEBUG is set, and if it is,
|
|
52
|
+
### write the log message to $deferr.
|
|
53
|
+
def write( time, level, name, frame, msg )
|
|
54
|
+
escaped_msg = escape_html( msg )
|
|
55
|
+
escaped_name = escape_html( name )
|
|
56
|
+
html = self.format.interpolate( binding )
|
|
57
|
+
|
|
58
|
+
@array << html
|
|
59
|
+
end
|
|
60
|
+
|
|
61
|
+
|
|
62
|
+
end # class Arrow::Logger::ArrayOutputter
|
|
63
|
+
|
|
@@ -0,0 +1,111 @@
|
|
|
1
|
+
#!/usr/bin/env ruby
|
|
2
|
+
|
|
3
|
+
require 'arrow/logger/fileoutputter'
|
|
4
|
+
|
|
5
|
+
# A derivative of Arrow::Logger::FileOutputter that outputs logging messages
|
|
6
|
+
# in ANSI colors according to their level.
|
|
7
|
+
#
|
|
8
|
+
# == Authors
|
|
9
|
+
#
|
|
10
|
+
# * Michael Granger <ged@FaerieMUD.org>
|
|
11
|
+
#
|
|
12
|
+
# Please see the file LICENSE in the top-level directory for licensing details.
|
|
13
|
+
#
|
|
14
|
+
class Arrow::Logger::ColorOutputter < Arrow::Logger::FileOutputter
|
|
15
|
+
|
|
16
|
+
# Set some ANSI escape code constants (Shamelessly stolen from Perl's
|
|
17
|
+
# Term::ANSIColor by Russ Allbery <rra@stanford.edu> and Zenin <zenin@best.com>
|
|
18
|
+
AnsiAttributes = {
|
|
19
|
+
'clear' => 0,
|
|
20
|
+
'reset' => 0,
|
|
21
|
+
'bold' => 1,
|
|
22
|
+
'dark' => 2,
|
|
23
|
+
'underline' => 4,
|
|
24
|
+
'underscore' => 4,
|
|
25
|
+
'blink' => 5,
|
|
26
|
+
'reverse' => 7,
|
|
27
|
+
'concealed' => 8,
|
|
28
|
+
|
|
29
|
+
'black' => 30, 'on_black' => 40,
|
|
30
|
+
'red' => 31, 'on_red' => 41,
|
|
31
|
+
'green' => 32, 'on_green' => 42,
|
|
32
|
+
'yellow' => 33, 'on_yellow' => 43,
|
|
33
|
+
'blue' => 34, 'on_blue' => 44,
|
|
34
|
+
'magenta' => 35, 'on_magenta' => 45,
|
|
35
|
+
'cyan' => 36, 'on_cyan' => 46,
|
|
36
|
+
'white' => 37, 'on_white' => 47
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
|
|
40
|
+
# Default color map: :level => %w{color scheme}
|
|
41
|
+
DEFAULT_COLOR_SCHEME = {
|
|
42
|
+
:debug => %w{dark white},
|
|
43
|
+
:info => %w{cyan},
|
|
44
|
+
:notice => %w{bold cyan},
|
|
45
|
+
:warning => %w{bold yellow},
|
|
46
|
+
:error => %w{bold red},
|
|
47
|
+
:crit => %w{bold white on_red},
|
|
48
|
+
:alert => %w{bold blink white on_red},
|
|
49
|
+
:emerg => %w{bold blink yellow on_red},
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
# Default decription used when creating instances
|
|
53
|
+
DEFAULT_DESCRIPTION = "Logging Outputter"
|
|
54
|
+
|
|
55
|
+
# The default logging output format
|
|
56
|
+
DEFAULT_FORMAT =
|
|
57
|
+
%q{#{time.strftime('%Y/%m/%d %H:%M:%S')} [#{level}]: #{name} } +
|
|
58
|
+
%q{#{frame ? '('+frame+')' : ''}: #{msg}}
|
|
59
|
+
|
|
60
|
+
|
|
61
|
+
|
|
62
|
+
### Override the default to add color scheme instance variable
|
|
63
|
+
def initialize( uri, description=DEFAULT_DESCRIPTION, format=DEFAULT_FORMAT ) # :notnew:
|
|
64
|
+
super
|
|
65
|
+
@color_scheme = DEFAULT_COLOR_SCHEME.dup
|
|
66
|
+
end
|
|
67
|
+
|
|
68
|
+
|
|
69
|
+
######
|
|
70
|
+
public
|
|
71
|
+
######
|
|
72
|
+
|
|
73
|
+
# The color scheme hash for this logger
|
|
74
|
+
attr_reader :color_scheme
|
|
75
|
+
|
|
76
|
+
|
|
77
|
+
### Write the given +level+, +name+, +frame+, and +msg+ to the logfile.
|
|
78
|
+
def write( time, level, name, frame, msg )
|
|
79
|
+
colors = @color_scheme[level]
|
|
80
|
+
super do |msg|
|
|
81
|
+
color_msg = colorize( msg, colors )
|
|
82
|
+
@io.puts( color_msg )
|
|
83
|
+
end
|
|
84
|
+
end
|
|
85
|
+
|
|
86
|
+
|
|
87
|
+
#######
|
|
88
|
+
private
|
|
89
|
+
#######
|
|
90
|
+
|
|
91
|
+
### Create a string that contains the ANSI codes specified and return it
|
|
92
|
+
def ansi_code( *attributes )
|
|
93
|
+
attr = attributes.flatten.collect {|a| AnsiAttributes[a] }.compact.join(';')
|
|
94
|
+
if attr.empty?
|
|
95
|
+
return ''
|
|
96
|
+
else
|
|
97
|
+
return "\e[%sm" % attr
|
|
98
|
+
end
|
|
99
|
+
end
|
|
100
|
+
|
|
101
|
+
|
|
102
|
+
### Colorize the given +string+ with the specified +attributes+ and return
|
|
103
|
+
### it, handling line-endings, etc.
|
|
104
|
+
def colorize( string, *attributes )
|
|
105
|
+
ending = string[/(\s)$/] || ''
|
|
106
|
+
string = string.rstrip
|
|
107
|
+
return ansi_code( *attributes ) + string + ansi_code( 'reset' ) + ending
|
|
108
|
+
end
|
|
109
|
+
|
|
110
|
+
end # class Arrow::Logger::ColorOutputter
|
|
111
|
+
|
|
@@ -0,0 +1,96 @@
|
|
|
1
|
+
#!/usr/bin/env ruby
|
|
2
|
+
|
|
3
|
+
require 'stringio'
|
|
4
|
+
require 'arrow/logger'
|
|
5
|
+
require 'arrow/logger/outputter'
|
|
6
|
+
|
|
7
|
+
# The Arrow::Logger::FileOutputter class, a derivative of
|
|
8
|
+
# Apache::Logger::Outputter. This is an outputter that writes to a
|
|
9
|
+
# file or other filehandle.
|
|
10
|
+
#
|
|
11
|
+
# == Authors
|
|
12
|
+
#
|
|
13
|
+
# * Michael Granger <ged@FaerieMUD.org>
|
|
14
|
+
#
|
|
15
|
+
# Please see the file LICENSE in the top-level directory for licensing details.
|
|
16
|
+
#
|
|
17
|
+
class Arrow::Logger::FileOutputter < Arrow::Logger::Outputter
|
|
18
|
+
|
|
19
|
+
# The default description
|
|
20
|
+
DEFAULT_DESCRIPTION = "File Outputter"
|
|
21
|
+
|
|
22
|
+
# The default format (copied from the superclass)
|
|
23
|
+
DEFAULT_FORMAT = Arrow::Logger::Outputter::DEFAULT_FORMAT
|
|
24
|
+
|
|
25
|
+
|
|
26
|
+
#############################################################
|
|
27
|
+
### I N S T A N C E M E T H O D S
|
|
28
|
+
#############################################################
|
|
29
|
+
|
|
30
|
+
### Create a new Arrow::Logger::FileOutputter object. The +io+ argument
|
|
31
|
+
### can be an IO or StringIO object, in which case output is sent to it
|
|
32
|
+
### directly, a String, in which case it is used as the first argument
|
|
33
|
+
### to File.open, or an Integer file descriptor, in which case a new IO
|
|
34
|
+
### object is created which appends to the file handle matching that
|
|
35
|
+
### descriptor.
|
|
36
|
+
def initialize( uri, description=DEFAULT_DESCRIPTION, format=DEFAULT_FORMAT )
|
|
37
|
+
if uri.hierarchical?
|
|
38
|
+
@io = File.open( uri.path, File::WRONLY|File::CREAT )
|
|
39
|
+
else
|
|
40
|
+
case uri.opaque
|
|
41
|
+
when /(std|def)err/i
|
|
42
|
+
@io = $stderr
|
|
43
|
+
when /(std|def)out/i
|
|
44
|
+
@io = $defout
|
|
45
|
+
when /^(\d+)$/
|
|
46
|
+
@io = IO.for_fd( Integer($1), "w" )
|
|
47
|
+
else
|
|
48
|
+
raise "Unrecognized log URI '#{uri}'"
|
|
49
|
+
end
|
|
50
|
+
end
|
|
51
|
+
|
|
52
|
+
super
|
|
53
|
+
end
|
|
54
|
+
|
|
55
|
+
|
|
56
|
+
######
|
|
57
|
+
public
|
|
58
|
+
######
|
|
59
|
+
|
|
60
|
+
# The filehandle open to the logfile
|
|
61
|
+
attr_accessor :io
|
|
62
|
+
|
|
63
|
+
|
|
64
|
+
### Write the given +level+, +name+, +frame+, and +msg+ to the logfile.
|
|
65
|
+
def write( time, level, name, frame, msg )
|
|
66
|
+
if block_given?
|
|
67
|
+
super
|
|
68
|
+
else
|
|
69
|
+
super {|msg| @io.puts(msg) }
|
|
70
|
+
end
|
|
71
|
+
end
|
|
72
|
+
|
|
73
|
+
|
|
74
|
+
#########
|
|
75
|
+
protected
|
|
76
|
+
#########
|
|
77
|
+
|
|
78
|
+
### Returns a String which should be included in the implementation-specific part
|
|
79
|
+
### of the object's inspection String.
|
|
80
|
+
def inspection_details
|
|
81
|
+
io_desc =
|
|
82
|
+
case @io
|
|
83
|
+
when $stderr
|
|
84
|
+
'STDERR'
|
|
85
|
+
when $stdout
|
|
86
|
+
'STDOUT'
|
|
87
|
+
when StringIO
|
|
88
|
+
'(StringIO 0x%0x)' % [ @io.object_id * 2 ]
|
|
89
|
+
else
|
|
90
|
+
'(IO: fd %d)' % [ @io.fileno ]
|
|
91
|
+
end
|
|
92
|
+
|
|
93
|
+
return [ super, io_desc ].join(', ')
|
|
94
|
+
end
|
|
95
|
+
|
|
96
|
+
end # class Arrow::Logger::FileOutputter
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
#!/usr/bin/env ruby
|
|
2
|
+
|
|
3
|
+
require 'arrow/mixins'
|
|
4
|
+
require 'arrow/logger/fileoutputter'
|
|
5
|
+
|
|
6
|
+
# Output logging messages in HTML fragments with classes that match their level.
|
|
7
|
+
#
|
|
8
|
+
# == Authors
|
|
9
|
+
#
|
|
10
|
+
# * Michael Granger <ged@FaerieMUD.org>
|
|
11
|
+
#
|
|
12
|
+
# Please see the file LICENSE in the top-level directory for licensing details.
|
|
13
|
+
#
|
|
14
|
+
class Arrow::Logger::HtmlOutputter < Arrow::Logger::FileOutputter
|
|
15
|
+
include Arrow::HTMLUtilities
|
|
16
|
+
|
|
17
|
+
# Default decription used when creating instances
|
|
18
|
+
DEFAULT_DESCRIPTION = "HTML Fragment Logging Outputter"
|
|
19
|
+
|
|
20
|
+
# The default logging output format
|
|
21
|
+
HTML_FORMAT = %q{
|
|
22
|
+
<div class="log-message #{level}">
|
|
23
|
+
<span class="log-time">#{time.strftime('%Y/%m/%d %H:%M:%S')}</span>
|
|
24
|
+
<span class="log-level">#{level}</span>
|
|
25
|
+
:
|
|
26
|
+
<span class="log-name">#{escaped_name}</span>
|
|
27
|
+
<span class="log-frame">#{frame ? '('+frame+'): ' : ''}</span>
|
|
28
|
+
<span class="log-message-text">#{escaped_msg}</span>
|
|
29
|
+
</div>
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
|
|
33
|
+
### Override the default argument values.
|
|
34
|
+
def initialize( uri, description=DEFAULT_DESCRIPTION, format=HTML_FORMAT ) # :notnew:
|
|
35
|
+
super
|
|
36
|
+
end
|
|
37
|
+
|
|
38
|
+
|
|
39
|
+
### Write the given +level+, +name+, +frame+, and +msg+ to the target
|
|
40
|
+
### output mechanism. Subclasses can call this with a block which will
|
|
41
|
+
### be passed the formatted message. If no block is supplied by the
|
|
42
|
+
### child, this method will check to see if $DEBUG is set, and if it is,
|
|
43
|
+
### write the log message to $stderr.
|
|
44
|
+
def write( time, level, name, frame, msg )
|
|
45
|
+
escaped_msg = escape_html( msg )
|
|
46
|
+
escaped_name = escape_html( name )
|
|
47
|
+
html = @format.interpolate( binding )
|
|
48
|
+
|
|
49
|
+
@io.puts( html )
|
|
50
|
+
end
|
|
51
|
+
|
|
52
|
+
|
|
53
|
+
end # class Arrow::Logger::HtmlOutputter
|
|
54
|
+
|
|
@@ -0,0 +1,123 @@
|
|
|
1
|
+
#!/usr/bin/env ruby
|
|
2
|
+
|
|
3
|
+
require 'arrow/monkeypatches'
|
|
4
|
+
require 'pluginfactory'
|
|
5
|
+
require 'uri'
|
|
6
|
+
|
|
7
|
+
#
|
|
8
|
+
# The Arrow::Logger::Outputter class, which is the abstract base class for
|
|
9
|
+
# objects that control where logging output is sent in an Arrow::Logger object.
|
|
10
|
+
#
|
|
11
|
+
# == Authors
|
|
12
|
+
#
|
|
13
|
+
# * Michael Granger <ged@FaerieMUD.org>
|
|
14
|
+
#
|
|
15
|
+
# Please see the file LICENSE in the top-level directory for licensing details.
|
|
16
|
+
#
|
|
17
|
+
class Arrow::Logger::Outputter
|
|
18
|
+
include PluginFactory
|
|
19
|
+
|
|
20
|
+
|
|
21
|
+
# The default description
|
|
22
|
+
DEFAULT_DESCRIPTION = "Logging Outputter"
|
|
23
|
+
|
|
24
|
+
# The default interpolatable string that's used to build the message to
|
|
25
|
+
# output
|
|
26
|
+
DEFAULT_FORMAT =
|
|
27
|
+
%q{#{time.strftime('%Y/%m/%d %H:%M:%S')} [#{level}]: #{name} } +
|
|
28
|
+
%q{#{frame ? '('+frame+')' : ''}: #{msg[0,1024]}}
|
|
29
|
+
|
|
30
|
+
|
|
31
|
+
#############################################################
|
|
32
|
+
### C L A S S M E T H O D S
|
|
33
|
+
#############################################################
|
|
34
|
+
|
|
35
|
+
### Specify the directory to look for the derivatives of this class in.
|
|
36
|
+
def self::derivativeDirs
|
|
37
|
+
["arrow/logger"]
|
|
38
|
+
end
|
|
39
|
+
|
|
40
|
+
|
|
41
|
+
### Parse the given string into a URI object, appending the path part if
|
|
42
|
+
### it doesn't exist.
|
|
43
|
+
def self::parse_uri( str )
|
|
44
|
+
return str if str.is_a?( URI::Generic )
|
|
45
|
+
str += ":." if str.match( /^\w+$/ )
|
|
46
|
+
URI.parse( str )
|
|
47
|
+
end
|
|
48
|
+
|
|
49
|
+
|
|
50
|
+
### Create a new Arrow::Logger::Outputter object of the type specified
|
|
51
|
+
### by +uri+.
|
|
52
|
+
def self::create( uri, *args )
|
|
53
|
+
uri = self.parse_uri( uri ) if uri.is_a?( String )
|
|
54
|
+
super( uri.scheme.dup, uri, *args )
|
|
55
|
+
end
|
|
56
|
+
|
|
57
|
+
|
|
58
|
+
|
|
59
|
+
#############################################################
|
|
60
|
+
### I N S T A N C E M E T H O D S
|
|
61
|
+
#############################################################
|
|
62
|
+
|
|
63
|
+
### Create a new Arrow::Logger::Outputter object with the given +uri+,
|
|
64
|
+
### +description+ and sprintf-style +format+.
|
|
65
|
+
def initialize( uri, description=DEFAULT_DESCRIPTION, format=DEFAULT_FORMAT )
|
|
66
|
+
@description = description
|
|
67
|
+
@format = format
|
|
68
|
+
end
|
|
69
|
+
|
|
70
|
+
|
|
71
|
+
######
|
|
72
|
+
public
|
|
73
|
+
######
|
|
74
|
+
|
|
75
|
+
# The outputter's description, for introspection utilities.
|
|
76
|
+
attr_accessor :description
|
|
77
|
+
|
|
78
|
+
# The uninterpolated string format for this outputter. This message
|
|
79
|
+
# written will be formed by interpolating this string in the #write
|
|
80
|
+
# method's context immediately before outputting.
|
|
81
|
+
attr_accessor :format
|
|
82
|
+
|
|
83
|
+
|
|
84
|
+
### Write the given +level+, +name+, +frame+, and +msg+ to the target
|
|
85
|
+
### output mechanism. Subclasses can call this with a block which will
|
|
86
|
+
### be passed the formatted message. If no block is supplied by the
|
|
87
|
+
### child, this method will check to see if $DEBUG is set, and if it is,
|
|
88
|
+
### write the log message to $stderr.
|
|
89
|
+
def write( time, level, name, frame, msg )
|
|
90
|
+
msg = @format.interpolate( binding )
|
|
91
|
+
|
|
92
|
+
if block_given?
|
|
93
|
+
yield( msg )
|
|
94
|
+
else
|
|
95
|
+
$stderr.puts( msg ) if $DEBUG
|
|
96
|
+
end
|
|
97
|
+
end
|
|
98
|
+
|
|
99
|
+
|
|
100
|
+
### Returns a human-readable description of the object as a String
|
|
101
|
+
def inspect
|
|
102
|
+
"#<%s:0x%0x %s>" % [
|
|
103
|
+
self.class.name,
|
|
104
|
+
self.object_id * 2,
|
|
105
|
+
self.inspection_details,
|
|
106
|
+
]
|
|
107
|
+
end
|
|
108
|
+
|
|
109
|
+
|
|
110
|
+
#########
|
|
111
|
+
protected
|
|
112
|
+
#########
|
|
113
|
+
|
|
114
|
+
### Returns a String which should be included in the implementation-specific part
|
|
115
|
+
### of the object's inspection String.
|
|
116
|
+
def inspection_details
|
|
117
|
+
return "%s (%s)" % [ self.description, self.format ]
|
|
118
|
+
end
|
|
119
|
+
|
|
120
|
+
|
|
121
|
+
end # class Arrow::Logger::Outputter
|
|
122
|
+
|
|
123
|
+
|