logger-application 0.0.1
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.
- checksums.yaml +7 -0
- data/.gitignore +22 -0
- data/.travis.yml +8 -0
- data/BSDL +22 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +56 -0
- data/README.md +53 -0
- data/Rakefile +7 -0
- data/lib/logger-application.rb +1 -0
- data/lib/logger/application.rb +127 -0
- data/lib/logger/application/version.rb +5 -0
- data/logger-application.gemspec +24 -0
- data/test/test_application.rb +54 -0
- metadata +100 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 7b5318c8d1ae14ac5f406e3893bdb700f8793d24
|
4
|
+
data.tar.gz: 46662688e0c14845c0578d0802df89cd4a024eac
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: fe0bee8f6ae57d925e28b3aa4ef9665bcc2c832f4e5327fa89100af3e3940aa610372d2a300246283c4b882a8b04de6f5f027fac5b221237418678c2cc557ca3
|
7
|
+
data.tar.gz: 818a73bd5d68588ff3e3c2f052ba5d66ce0a70750ddc7f25ec85c08ec5a634db2a6b23c660de02cedca43d001d6a06a85fa5db12203e73feafd0015695e6cc07
|
data/.gitignore
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
*.gem
|
2
|
+
*.rbc
|
3
|
+
.bundle
|
4
|
+
.config
|
5
|
+
.yardoc
|
6
|
+
Gemfile.lock
|
7
|
+
InstalledFiles
|
8
|
+
_yardoc
|
9
|
+
coverage
|
10
|
+
doc/
|
11
|
+
lib/bundler/man
|
12
|
+
pkg
|
13
|
+
rdoc
|
14
|
+
spec/reports
|
15
|
+
test/tmp
|
16
|
+
test/version_tmp
|
17
|
+
tmp
|
18
|
+
*.bundle
|
19
|
+
*.so
|
20
|
+
*.o
|
21
|
+
*.a
|
22
|
+
mkmf.log
|
data/.travis.yml
ADDED
data/BSDL
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (C) 2014 Hiroshi SHIBATA, All rights reserved.
|
2
|
+
|
3
|
+
Redistribution and use in source and binary forms, with or without
|
4
|
+
modification, are permitted provided that the following conditions
|
5
|
+
are met:
|
6
|
+
1. Redistributions of source code must retain the above copyright
|
7
|
+
notice, this list of conditions and the following disclaimer.
|
8
|
+
2. Redistributions in binary form must reproduce the above copyright
|
9
|
+
notice, this list of conditions and the following disclaimer in the
|
10
|
+
documentation and/or other materials provided with the distribution.
|
11
|
+
|
12
|
+
THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
|
13
|
+
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
14
|
+
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
15
|
+
ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
|
16
|
+
FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
17
|
+
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
18
|
+
OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
19
|
+
HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
20
|
+
LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
21
|
+
OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
22
|
+
SUCH DAMAGE.
|
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,56 @@
|
|
1
|
+
Ruby is copyrighted free software by Yukihiro Matsumoto <matz@netlab.jp>.
|
2
|
+
You can redistribute it and/or modify it under either the terms of the
|
3
|
+
2-clause BSDL (see the file BSDL), or the conditions below:
|
4
|
+
|
5
|
+
1. You may make and give away verbatim copies of the source form of the
|
6
|
+
software without restriction, provided that you duplicate all of the
|
7
|
+
original copyright notices and associated disclaimers.
|
8
|
+
|
9
|
+
2. You may modify your copy of the software in any way, provided that
|
10
|
+
you do at least ONE of the following:
|
11
|
+
|
12
|
+
a) place your modifications in the Public Domain or otherwise
|
13
|
+
make them Freely Available, such as by posting said
|
14
|
+
modifications to Usenet or an equivalent medium, or by allowing
|
15
|
+
the author to include your modifications in the software.
|
16
|
+
|
17
|
+
b) use the modified software only within your corporation or
|
18
|
+
organization.
|
19
|
+
|
20
|
+
c) give non-standard binaries non-standard names, with
|
21
|
+
instructions on where to get the original software distribution.
|
22
|
+
|
23
|
+
d) make other distribution arrangements with the author.
|
24
|
+
|
25
|
+
3. You may distribute the software in object code or binary form,
|
26
|
+
provided that you do at least ONE of the following:
|
27
|
+
|
28
|
+
a) distribute the binaries and library files of the software,
|
29
|
+
together with instructions (in the manual page or equivalent)
|
30
|
+
on where to get the original distribution.
|
31
|
+
|
32
|
+
b) accompany the distribution with the machine-readable source of
|
33
|
+
the software.
|
34
|
+
|
35
|
+
c) give non-standard binaries non-standard names, with
|
36
|
+
instructions on where to get the original software distribution.
|
37
|
+
|
38
|
+
d) make other distribution arrangements with the author.
|
39
|
+
|
40
|
+
4. You may modify and include the part of the software into any other
|
41
|
+
software (possibly commercial). But some files in the distribution
|
42
|
+
are not written by the author, so that they are not under these terms.
|
43
|
+
|
44
|
+
For the list of those files and their copying conditions, see the
|
45
|
+
file LEGAL.
|
46
|
+
|
47
|
+
5. The scripts and library files supplied as input to or produced as
|
48
|
+
output from the software do not automatically fall under the
|
49
|
+
copyright of the software, but belong to whomever generated them,
|
50
|
+
and may be sold commercially, and may be aggregated with this
|
51
|
+
software.
|
52
|
+
|
53
|
+
6. THIS SOFTWARE IS PROVIDED "AS IS" AND WITHOUT ANY EXPRESS OR
|
54
|
+
IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
|
55
|
+
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
56
|
+
PURPOSE.
|
data/README.md
ADDED
@@ -0,0 +1,53 @@
|
|
1
|
+
# Logger::Application
|
2
|
+
|
3
|
+
## Description
|
4
|
+
|
5
|
+
Add logging support to your application.
|
6
|
+
|
7
|
+
## Installation
|
8
|
+
|
9
|
+
Add this line to your application's Gemfile:
|
10
|
+
|
11
|
+
gem 'logger-application'
|
12
|
+
|
13
|
+
And then execute:
|
14
|
+
|
15
|
+
$ bundle
|
16
|
+
|
17
|
+
Or install it yourself as:
|
18
|
+
|
19
|
+
$ gem install logger-application
|
20
|
+
|
21
|
+
## Usage
|
22
|
+
|
23
|
+
1. Define your application class as a sub-class of this class.
|
24
|
+
2. Override the +run+ method in your class to do many things.
|
25
|
+
3. Instantiate it and invoke #start.
|
26
|
+
|
27
|
+
## Example
|
28
|
+
|
29
|
+
```ruby
|
30
|
+
class FooApp < Logger::Application
|
31
|
+
def initialize(foo_app, application_specific, arguments)
|
32
|
+
super('FooApp') # Name of the application.
|
33
|
+
end
|
34
|
+
|
35
|
+
def run
|
36
|
+
...
|
37
|
+
log(WARN, 'warning', 'my_method1')
|
38
|
+
...
|
39
|
+
@log.error('my_method2') { 'Error!' }
|
40
|
+
...
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
44
|
+
status = FooApp.new(....).start
|
45
|
+
```
|
46
|
+
|
47
|
+
## Contributing
|
48
|
+
|
49
|
+
1. Fork it ( https://github.com/hsbt/logger-application/fork )
|
50
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
51
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
52
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
53
|
+
5. Create a new Pull Request
|
data/Rakefile
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require 'logger/application'
|
@@ -0,0 +1,127 @@
|
|
1
|
+
require 'logger'
|
2
|
+
require "logger/application/version"
|
3
|
+
|
4
|
+
module Logger
|
5
|
+
#
|
6
|
+
# == Description
|
7
|
+
#
|
8
|
+
# Logger::Application --- Add logging support to your application.
|
9
|
+
#
|
10
|
+
# == Usage
|
11
|
+
#
|
12
|
+
# 1. Define your application class as a sub-class of this class.
|
13
|
+
# 2. Override the +run+ method in your class to do many things.
|
14
|
+
# 3. Instantiate it and invoke #start.
|
15
|
+
#
|
16
|
+
# == Example
|
17
|
+
#
|
18
|
+
# class FooApp < Logger::Application
|
19
|
+
# def initialize(foo_app, application_specific, arguments)
|
20
|
+
# super('FooApp') # Name of the application.
|
21
|
+
# end
|
22
|
+
#
|
23
|
+
# def run
|
24
|
+
# ...
|
25
|
+
# log(WARN, 'warning', 'my_method1')
|
26
|
+
# ...
|
27
|
+
# @log.error('my_method2') { 'Error!' }
|
28
|
+
# ...
|
29
|
+
# end
|
30
|
+
# end
|
31
|
+
#
|
32
|
+
# status = FooApp.new(....).start
|
33
|
+
#
|
34
|
+
class Application
|
35
|
+
include Logger::Severity
|
36
|
+
|
37
|
+
# Name of the application given at initialize.
|
38
|
+
attr_reader :appname
|
39
|
+
|
40
|
+
#
|
41
|
+
# :call-seq:
|
42
|
+
# Logger::Application.new(appname = '')
|
43
|
+
#
|
44
|
+
# == Args
|
45
|
+
#
|
46
|
+
# +appname+:: Name of the application.
|
47
|
+
#
|
48
|
+
# == Description
|
49
|
+
#
|
50
|
+
# Create an instance. Log device is +STDERR+ by default. This can be
|
51
|
+
# changed with #set_log.
|
52
|
+
#
|
53
|
+
def initialize(appname = nil)
|
54
|
+
@appname = appname
|
55
|
+
@log = Logger.new(STDERR)
|
56
|
+
@log.progname = @appname
|
57
|
+
@level = @log.level
|
58
|
+
end
|
59
|
+
|
60
|
+
#
|
61
|
+
# Start the application. Return the status code.
|
62
|
+
#
|
63
|
+
def start
|
64
|
+
status = -1
|
65
|
+
begin
|
66
|
+
log(INFO, "Start of #{ @appname }.")
|
67
|
+
status = run
|
68
|
+
rescue
|
69
|
+
log(FATAL, "Detected an exception. Stopping ... #{$!} (#{$!.class})\n" << $@.join("\n"))
|
70
|
+
ensure
|
71
|
+
log(INFO, "End of #{ @appname }. (status: #{ status })")
|
72
|
+
end
|
73
|
+
status
|
74
|
+
end
|
75
|
+
|
76
|
+
# Logger for this application. See the class Logger for an explanation.
|
77
|
+
def logger
|
78
|
+
@log
|
79
|
+
end
|
80
|
+
|
81
|
+
#
|
82
|
+
# Sets the logger for this application. See the class Logger for an
|
83
|
+
# explanation.
|
84
|
+
#
|
85
|
+
def logger=(logger)
|
86
|
+
@log = logger
|
87
|
+
@log.progname = @appname
|
88
|
+
@log.level = @level
|
89
|
+
end
|
90
|
+
|
91
|
+
#
|
92
|
+
# Sets the log device for this application. See <tt>Logger.new</tt> for
|
93
|
+
# an explanation of the arguments.
|
94
|
+
#
|
95
|
+
def set_log(logdev, shift_age = 0, shift_size = 1024000)
|
96
|
+
@log = Logger.new(logdev, shift_age, shift_size)
|
97
|
+
@log.progname = @appname
|
98
|
+
@log.level = @level
|
99
|
+
end
|
100
|
+
|
101
|
+
def log=(logdev)
|
102
|
+
set_log(logdev)
|
103
|
+
end
|
104
|
+
|
105
|
+
#
|
106
|
+
# Set the logging threshold, just like <tt>Logger#level=</tt>.
|
107
|
+
#
|
108
|
+
def level=(level)
|
109
|
+
@level = level
|
110
|
+
@log.level = @level
|
111
|
+
end
|
112
|
+
|
113
|
+
#
|
114
|
+
# See Logger#add. This application's +appname+ is used.
|
115
|
+
#
|
116
|
+
def log(severity, message = nil, &block)
|
117
|
+
@log.add(severity, message, @appname, &block) if @log
|
118
|
+
end
|
119
|
+
|
120
|
+
private
|
121
|
+
|
122
|
+
def run
|
123
|
+
# TODO: should be an NotImplementedError
|
124
|
+
raise RuntimeError.new('Method run must be defined in the derived class.')
|
125
|
+
end
|
126
|
+
end
|
127
|
+
end
|
@@ -0,0 +1,24 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'logger/application/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "logger-application"
|
8
|
+
spec.version = Logger::Application::VERSION
|
9
|
+
spec.authors = ["SHIBATA Hiroshi"]
|
10
|
+
spec.email = ["hsbt@ruby-lang.org"]
|
11
|
+
spec.summary = %q{Add logging support to your application.}
|
12
|
+
spec.description = %q{Add logging support to your application.}
|
13
|
+
spec.homepage = ""
|
14
|
+
spec.license = "2-clause BSDL"
|
15
|
+
|
16
|
+
spec.files = `git ls-files -z`.split("\x0")
|
17
|
+
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
18
|
+
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
19
|
+
spec.require_paths = ["lib"]
|
20
|
+
|
21
|
+
spec.add_development_dependency "bundler", "~> 1.6"
|
22
|
+
spec.add_development_dependency "rake"
|
23
|
+
spec.add_development_dependency "test-unit"
|
24
|
+
end
|
@@ -0,0 +1,54 @@
|
|
1
|
+
# coding: US-ASCII
|
2
|
+
require 'test/unit'
|
3
|
+
require 'logger'
|
4
|
+
require 'tempfile'
|
5
|
+
|
6
|
+
class TestLoggerApplication < Test::Unit::TestCase
|
7
|
+
def setup
|
8
|
+
@app = Logger::Application.new('appname')
|
9
|
+
@tempfile = Tempfile.new("logger")
|
10
|
+
@tempfile.close
|
11
|
+
@filename = @tempfile.path
|
12
|
+
File.unlink(@filename)
|
13
|
+
end
|
14
|
+
|
15
|
+
def teardown
|
16
|
+
@tempfile.close(true)
|
17
|
+
end
|
18
|
+
|
19
|
+
def test_initialize
|
20
|
+
app = Logger::Application.new('appname')
|
21
|
+
assert_equal('appname', app.appname)
|
22
|
+
end
|
23
|
+
|
24
|
+
def test_start
|
25
|
+
@app.set_log(@filename)
|
26
|
+
begin
|
27
|
+
@app.level = Logger::UNKNOWN
|
28
|
+
@app.start # logs FATAL log
|
29
|
+
assert_equal(1, File.read(@filename).split(/\n/).size)
|
30
|
+
ensure
|
31
|
+
@app.logger.close
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
def test_logger
|
36
|
+
@app.level = Logger::WARN
|
37
|
+
@app.set_log(@filename)
|
38
|
+
begin
|
39
|
+
assert_equal(Logger::WARN, @app.logger.level)
|
40
|
+
ensure
|
41
|
+
@app.logger.close
|
42
|
+
end
|
43
|
+
@app.logger = logger = Logger.new(STDOUT)
|
44
|
+
assert_equal(logger, @app.logger)
|
45
|
+
assert_equal(Logger::WARN, @app.logger.level)
|
46
|
+
@app.log = @filename
|
47
|
+
begin
|
48
|
+
assert(logger != @app.logger)
|
49
|
+
assert_equal(Logger::WARN, @app.logger.level)
|
50
|
+
ensure
|
51
|
+
@app.logger.close
|
52
|
+
end
|
53
|
+
end
|
54
|
+
end
|
metadata
ADDED
@@ -0,0 +1,100 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: logger-application
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- SHIBATA Hiroshi
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2014-07-02 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: bundler
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '1.6'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.6'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rake
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ">="
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ">="
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: test-unit
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - ">="
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - ">="
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0'
|
55
|
+
description: Add logging support to your application.
|
56
|
+
email:
|
57
|
+
- hsbt@ruby-lang.org
|
58
|
+
executables: []
|
59
|
+
extensions: []
|
60
|
+
extra_rdoc_files: []
|
61
|
+
files:
|
62
|
+
- ".gitignore"
|
63
|
+
- ".travis.yml"
|
64
|
+
- BSDL
|
65
|
+
- Gemfile
|
66
|
+
- LICENSE.txt
|
67
|
+
- README.md
|
68
|
+
- Rakefile
|
69
|
+
- lib/logger-application.rb
|
70
|
+
- lib/logger/application.rb
|
71
|
+
- lib/logger/application/version.rb
|
72
|
+
- logger-application.gemspec
|
73
|
+
- test/test_application.rb
|
74
|
+
homepage: ''
|
75
|
+
licenses:
|
76
|
+
- 2-clause BSDL
|
77
|
+
metadata: {}
|
78
|
+
post_install_message:
|
79
|
+
rdoc_options: []
|
80
|
+
require_paths:
|
81
|
+
- lib
|
82
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
83
|
+
requirements:
|
84
|
+
- - ">="
|
85
|
+
- !ruby/object:Gem::Version
|
86
|
+
version: '0'
|
87
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
88
|
+
requirements:
|
89
|
+
- - ">="
|
90
|
+
- !ruby/object:Gem::Version
|
91
|
+
version: '0'
|
92
|
+
requirements: []
|
93
|
+
rubyforge_project:
|
94
|
+
rubygems_version: 2.3.0
|
95
|
+
signing_key:
|
96
|
+
specification_version: 4
|
97
|
+
summary: Add logging support to your application.
|
98
|
+
test_files:
|
99
|
+
- test/test_application.rb
|
100
|
+
has_rdoc:
|