trinidad_daemon_extension 0.1.0 → 0.1.2

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,3 +1,7 @@
1
+ 0.1.2 (2010-04-19)
2
+
3
+ * logging enabled
4
+
1
5
  0.1.0 (2010-04-17)
2
6
 
3
- * First release
7
+ * First release
data/README CHANGED
@@ -18,12 +18,12 @@ It uses a temporal directory to write the pid file but its route can be override
18
18
 
19
19
  * To enable it from the configuration file you have to add a section "extensions" to the root of the file and the section "daemon" to this one. The pid file can be specified there:
20
20
 
21
- --
21
+ ---
22
22
  extensions:
23
23
  daemon:
24
24
  pid_file: ./trinidad.pid # this is optional by default the extension writes the pid file into a temporal directory.
25
25
 
26
- * To enable it from the command line you have to load the extension first and the add one of these options:
26
+ * To enable it from the command line you have to load the extension first and then add one of these options:
27
27
 
28
28
  -d, --daemonize [PID_FILE]
29
29
 
@@ -31,11 +31,17 @@ It uses a temporal directory to write the pid file but its route can be override
31
31
 
32
32
  $ jruby -S trinidad --load daemon --daemonize ./trinidad.pid
33
33
 
34
- # TODO
34
+ The log file where the daemon writes its logs is also configurable from the trinidad's configuration file.
35
+ By default it writes the logs into the file log/trinidad.log with the level INFO, to modify this behaviour you just need to add these lines under the daemon configuration:
35
36
 
36
- * enable logging. Right now the Tomcat's log is not written anywhere.
37
+ ---
38
+ extensions:
39
+ daemon:
40
+ log:
41
+ file: trinidad.log # where the daemon writes its output
42
+ level: ALL # severity level, it cn be one of these: ALL, CONFIG, FINE, FINER, FINEST, INFO, OFF, SEVERE, WARNING
37
43
 
38
- You can find further information on how to write your onw extension in the wiki: http://wiki.github.com/calavera/trinidad/extensions
44
+ You can find further information on how to write your own extension in the wiki: http://wiki.github.com/calavera/trinidad/extensions
39
45
 
40
46
  # Copyright
41
47
 
@@ -9,15 +9,29 @@ require File.expand_path('../../trinidad-libs/trinidad-daemon-extension', __FILE
9
9
  module Trinidad
10
10
  module Extensions
11
11
  module Daemon
12
- VERSION = '0.1.0'
12
+ VERSION = '0.1.2'
13
13
  end
14
14
 
15
15
  class DaemonServerExtension < ServerExtension
16
16
  def configure(tomcat)
17
- org.jruby.trinidad.TrinidadDaemon.new(tomcat, @options[:pid_file])
17
+ org.jruby.trinidad.TrinidadDaemon.new(tomcat, @options[:pid_file], logger_options)
18
18
  end
19
19
 
20
20
  def override_tomcat?; true; end
21
+
22
+ def logger_options
23
+ log = @options[:log] || {}
24
+ log[:file] ||= 'log/trinidad.log'
25
+
26
+ level = log[:level] || 'INFO'
27
+ unless %w{ALL CONFIG FINE FINER FINEST INFO OFF SEVERE WARNING}.include?(level)
28
+ puts "Invalid log level #{level}, using default: INFO"
29
+ end
30
+ log[:level] = level
31
+ log = Hash[log.map{|k, v| [k.to_s, v]}]
32
+
33
+ Java::java.util.HashMap.new(log)
34
+ end
21
35
  end
22
36
 
23
37
  class DaemonOptionsExtension < OptionsExtension
@@ -18,7 +18,7 @@ namespace :ant do
18
18
  opts = {
19
19
  :fork => 'true',
20
20
  :failonerror => 'true',
21
- :srcdir => 'src/main',
21
+ :srcdir => 'src/main/java',
22
22
  :destdir => TARGET_DIR,
23
23
  :classpath => Dir.glob('trinidad-libs/*.jar').join(':')
24
24
  }
@@ -25,12 +25,44 @@ describe Trinidad::Extensions::DaemonServerExtension do
25
25
  daemon.pid_file.should =~ /trinidad_pid.txt$/
26
26
  end
27
27
 
28
+ it "creates a default log info when it's not present" do
29
+ log = subject.logger_options
30
+ log['file'].should == 'log/trinidad.log'
31
+ log['level'].should == 'INFO'
32
+ end
33
+
34
+ it "uses the log configuration provided when it's present" do
35
+ extension = Trinidad::Extensions::DaemonServerExtension.new({
36
+ :log => {
37
+ :file => 'custom.log',
38
+ :level => 'ALL'
39
+ }
40
+ })
41
+
42
+ log = extension.logger_options
43
+ log['file'].should == 'custom.log'
44
+ log['level'].should == 'ALL'
45
+ end
46
+
47
+ it "uses the default level when it's not recognized" do
48
+ extension = Trinidad::Extensions::DaemonServerExtension.new({
49
+ :log => {
50
+ :level => 'LEVEL'
51
+ }
52
+ })
53
+
54
+ log = extension.logger_options
55
+ log['file'].should == 'log/trinidad.log'
56
+ log['level'].should == 'LEVEL'
57
+ end
58
+ end
59
+
60
+ describe Trinidad::Extensions::DaemonOptionsExtension do
28
61
  it "allows to specify a command line option to run the daemon" do
29
- extension = Trinidad::Extensions::DaemonOptionsExtension.new
30
62
  parser = OptionParser.new
31
63
  options = {}
32
-
33
- extension.configure(parser, options)
64
+
65
+ subject.configure(parser, options)
34
66
  parser.parse! '-d /tmp/trinidad.pid'.split
35
67
 
36
68
  options[:extensions].keys.should include(:daemon)
@@ -13,8 +13,8 @@ Gem::Specification.new do |s|
13
13
  ## If your rubyforge_project name is different, then edit it and comment out
14
14
  ## the sub! line in the Rakefile
15
15
  s.name = 'trinidad_daemon_extension'
16
- s.version = '0.1.0'
17
- s.date = '2010-04-17'
16
+ s.version = '0.1.2'
17
+ s.date = '2010-04-19'
18
18
  s.rubyforge_project = 'trinidad_daemon_extension'
19
19
 
20
20
  ## Make sure your summary is short. The description may be as long
metadata CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
5
5
  segments:
6
6
  - 0
7
7
  - 1
8
- - 0
9
- version: 0.1.0
8
+ - 2
9
+ version: 0.1.2
10
10
  platform: ruby
11
11
  authors:
12
12
  - David Calavera
@@ -14,7 +14,7 @@ autorequire:
14
14
  bindir: bin
15
15
  cert_chain: []
16
16
 
17
- date: 2010-04-17 00:00:00 +02:00
17
+ date: 2010-04-19 00:00:00 +02:00
18
18
  default_executable:
19
19
  dependencies:
20
20
  - !ruby/object:Gem::Dependency