timequiz 0.1.5 → 0.1.6
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +152 -0
- data/doc/license.txt +9 -670
- data/lib/adder.rb +25 -34
- data/lib/argparser.rb +7 -17
- data/lib/basic_logging.rb +167 -0
- data/lib/busy_indicator.rb +12 -19
- data/lib/color_output.rb +12 -19
- data/lib/console.rb +4 -12
- data/lib/constants.rb +6 -15
- data/lib/event.rb +12 -19
- data/lib/events.rb +12 -19
- data/lib/extstring.rb +12 -19
- data/lib/file_checking.rb +4 -10
- data/lib/timequiz.rb +28 -40
- data/lib/user_input.rb +4 -10
- data/lib/version.rb +16 -21
- data/timequiz.gemspec +2 -2
- metadata +9 -9
- data/lib/log.conf +0 -55
- data/lib/logging.rb +0 -204
data/lib/timequiz.rb
CHANGED
@@ -1,25 +1,18 @@
|
|
1
1
|
#!/usr/bin/env ruby
|
2
2
|
#encoding: UTF-8
|
3
|
-
|
4
3
|
=begin
|
5
|
-
|
6
|
-
*
|
7
|
-
*
|
8
|
-
* This program is free software; you can redistribute it and/or modify
|
9
|
-
* it under the terms of the
|
10
|
-
*
|
11
|
-
*
|
12
|
-
*
|
13
|
-
*
|
14
|
-
*
|
15
|
-
*
|
16
|
-
|
17
|
-
* *
|
18
|
-
* You should have received a copy of the GNU General Public License *
|
19
|
-
* along with this program; if not, write to the *
|
20
|
-
* Free Software Foundation, Inc., *
|
21
|
-
* 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
|
22
|
-
******************************************************************************/
|
4
|
+
/***************************************************************************
|
5
|
+
* ©2017-2024, Michael Uplawski <michael.uplawski@uplawski.eu> *
|
6
|
+
* *
|
7
|
+
* This program is free software; you can redistribute it and/or modify *
|
8
|
+
* it under the terms of the WTFPL 2.0 or later, see *
|
9
|
+
* http://www.wtfpl.net/about/ *
|
10
|
+
* *
|
11
|
+
* This program is distributed in the hope that it will be useful, *
|
12
|
+
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
|
13
|
+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. *
|
14
|
+
* *
|
15
|
+
***************************************************************************/
|
23
16
|
=end
|
24
17
|
|
25
18
|
require_relative 'argparser'
|
@@ -29,7 +22,7 @@ require_relative 'extstring'
|
|
29
22
|
require_relative 'user_input'
|
30
23
|
require_relative 'busy_indicator'
|
31
24
|
require_relative 'event'
|
32
|
-
require_relative '
|
25
|
+
require_relative 'basic_logging'
|
33
26
|
|
34
27
|
require 'date'
|
35
28
|
|
@@ -37,8 +30,7 @@ require 'date'
|
|
37
30
|
# precisely in the start_game() method which has to be defined by an
|
38
31
|
# interface-module.
|
39
32
|
class Timequiz
|
40
|
-
|
41
|
-
@@log = self::init_logger()
|
33
|
+
include BasicLogging
|
42
34
|
|
43
35
|
# Find out, how the program has been called.
|
44
36
|
# In juin 2017 this can be 'timequiz' or 'timequizGtk'.
|
@@ -60,7 +52,7 @@ class Timequiz
|
|
60
52
|
when 'timequizGtk'
|
61
53
|
# require_relative 'gtk/timequizGtk'
|
62
54
|
# include TimequizGtk
|
63
|
-
|
55
|
+
info('I am sorry. But there is not Gtk-interface, for the time.')
|
64
56
|
# Text only
|
65
57
|
when 'timequiz'
|
66
58
|
require_relative 'console'
|
@@ -74,7 +66,7 @@ class Timequiz
|
|
74
66
|
# puts "How did you do that?"
|
75
67
|
# ... HEY! I guess: You created a link to the executable but forgot
|
76
68
|
# something else. Read the comment to the 'called_as?' method, above.
|
77
|
-
|
69
|
+
error(": A user-interface \"" << called_as? << "\" has not (yet) been defined (read the code, my friend)! Aborting.")
|
78
70
|
exit false
|
79
71
|
end
|
80
72
|
|
@@ -85,14 +77,14 @@ class Timequiz
|
|
85
77
|
begin
|
86
78
|
ofl = File.open(file, 'a')
|
87
79
|
if !File.readable?(file)
|
88
|
-
|
80
|
+
error('The file ' << file << ' cannot be read! Aborting')
|
89
81
|
exit false
|
90
82
|
end
|
91
83
|
if(File.empty?(file) )
|
92
|
-
|
84
|
+
info("The file " << file << " is empty. You must add some events to it.")
|
93
85
|
if(File.writable?(file) )
|
94
86
|
orig_file = File.dirname(__FILE__) << File::Separator << 'events.rb'
|
95
|
-
|
87
|
+
debug('orig_file is ' << orig_file)
|
96
88
|
File.open(orig_file, 'r') do |ifl|
|
97
89
|
ofl.puts("# Events defined for the Timequiz game")
|
98
90
|
ofl.puts("# Lines starting with '#' are comments.\n\n# EXAMPLES:")
|
@@ -114,25 +106,21 @@ class Timequiz
|
|
114
106
|
end
|
115
107
|
rescue IOError => ex
|
116
108
|
ofl.close
|
117
|
-
|
109
|
+
error('Cannot work with the given file: ' << ex.message)
|
118
110
|
exit false
|
119
111
|
end
|
120
112
|
end
|
121
113
|
|
122
114
|
def initialize(*args)
|
123
|
-
@log = @@log
|
124
115
|
# adjust log-level, if given.
|
125
116
|
# Else use what you know.
|
126
117
|
options = ArgParser.parse(*args)
|
127
|
-
|
128
|
-
@log.level = $LOG_LEVEL if $LOG_LEVEL
|
129
|
-
@log.debug('log_level is ' << $LOG_LEVEL.to_s)
|
130
|
-
@log.debug('options are ' << options.to_s)
|
118
|
+
set_level (BasicLogging::DEBUG if options.debug)
|
131
119
|
# should we add only a new event to the list
|
132
|
-
|
120
|
+
debug('options are : ' << options.to_s)
|
133
121
|
add_ok = game_ok = false
|
134
122
|
if(options.file)
|
135
|
-
|
123
|
+
debug('shall use non-standard events file')
|
136
124
|
add_ok, game_ok = verify_prepare(options.file)
|
137
125
|
else
|
138
126
|
game_ok = require_relative 'events'
|
@@ -142,10 +130,10 @@ class Timequiz
|
|
142
130
|
Adder::add(options)
|
143
131
|
exit true
|
144
132
|
elsif(options.file)
|
145
|
-
|
133
|
+
error('cannot add events to ' << options.file)
|
146
134
|
exit false
|
147
135
|
else
|
148
|
-
|
136
|
+
error('PSE start the program with -h or --help to see an option-overview')
|
149
137
|
exit false
|
150
138
|
end
|
151
139
|
end
|
@@ -154,8 +142,8 @@ class Timequiz
|
|
154
142
|
if(game_ok)
|
155
143
|
start_game
|
156
144
|
else
|
157
|
-
|
158
|
-
|
145
|
+
error("Cannot play with the events in " << options.file)
|
146
|
+
error("PSE verify that there are at least 3 events defined!")
|
159
147
|
exit false
|
160
148
|
end
|
161
149
|
end
|
@@ -186,7 +174,7 @@ class Timequiz
|
|
186
174
|
response_years = []
|
187
175
|
# response.each_with_index {|r, i| response_years[r-1] = @m_events[i].year}
|
188
176
|
response.each_with_index {|r, i| response_years[i] = @m_events[r-1].year}
|
189
|
-
|
177
|
+
debug('response is ' << response.join(', ') << "\nresponse_years is : " << response_years.join(', ') )
|
190
178
|
puts 'response is ' << response.join(', ') << "\nresponse_years is : " << response_years.join(', ')
|
191
179
|
|
192
180
|
# do not change the displayed index
|
data/lib/user_input.rb
CHANGED
@@ -2,22 +2,16 @@
|
|
2
2
|
|
3
3
|
=begin
|
4
4
|
/***************************************************************************
|
5
|
-
*
|
5
|
+
* ©2017-2024, Michael Uplawski <michael.uplawski@uplawski.eu> *
|
6
6
|
* *
|
7
7
|
* This program is free software; you can redistribute it and/or modify *
|
8
|
-
* it under the terms of the
|
9
|
-
*
|
10
|
-
* (at your option) any later version. *
|
8
|
+
* it under the terms of the WTFPL 2.0 or later, see *
|
9
|
+
* http://www.wtfpl.net/about/ *
|
11
10
|
* *
|
12
11
|
* This program is distributed in the hope that it will be useful, *
|
13
12
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
|
14
|
-
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
|
15
|
-
* GNU General Public License for more details. *
|
13
|
+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. *
|
16
14
|
* *
|
17
|
-
* You should have received a copy of the GNU General Public License *
|
18
|
-
* along with this program; if not, write to the *
|
19
|
-
* Free Software Foundation, Inc., *
|
20
|
-
* 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
|
21
15
|
***************************************************************************/
|
22
16
|
=end
|
23
17
|
|
data/lib/version.rb
CHANGED
@@ -1,27 +1,22 @@
|
|
1
|
-
#!/usr/bin/env ruby
|
2
1
|
#encoding: UTF-8
|
3
2
|
|
4
3
|
=begin
|
5
|
-
|
6
|
-
*
|
7
|
-
*
|
8
|
-
* This program is free software; you can redistribute it and/or modify
|
9
|
-
* it under the terms of the
|
10
|
-
*
|
11
|
-
*
|
12
|
-
*
|
13
|
-
*
|
14
|
-
*
|
15
|
-
*
|
16
|
-
|
17
|
-
* *
|
18
|
-
* You should have received a copy of the GNU General Public License *
|
19
|
-
* along with this program; if not, write to the *
|
20
|
-
* Free Software Foundation, Inc., *
|
21
|
-
* 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
|
22
|
-
******************************************************************************/
|
4
|
+
/***************************************************************************
|
5
|
+
* ©2017-2024, Michael Uplawski <michael.uplawski@uplawski.eu> *
|
6
|
+
* *
|
7
|
+
* This program is free software; you can redistribute it and/or modify *
|
8
|
+
* it under the terms of the WTFPL 2.0 or later, see *
|
9
|
+
* http://www.wtfpl.net/about/ *
|
10
|
+
* *
|
11
|
+
* This program is distributed in the hope that it will be useful, *
|
12
|
+
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
|
13
|
+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. *
|
14
|
+
* *
|
15
|
+
***************************************************************************/
|
23
16
|
=end
|
24
17
|
|
25
|
-
VERSION = '0.1.
|
18
|
+
VERSION = '0.1.6'
|
26
19
|
SUMMARY = 'Some new events added. Fixed a bug in the logging-configuration.'
|
27
|
-
|
20
|
+
AUTHOR = 'Michael Uplawski'
|
21
|
+
AUTHOR_MAIL = '<michael.uplawski@uplawski.eu>'
|
22
|
+
YEARS = 2017 - 2024
|
data/timequiz.gemspec
CHANGED
@@ -9,11 +9,11 @@ Gem::Specification.new do |s|
|
|
9
9
|
s.description = "Play a history game"
|
10
10
|
s.authors = ["Michael Uplawski"]
|
11
11
|
s.email = 'michael.uplawski@uplawski.eu'
|
12
|
-
s.files = %w~timequiz~.collect{|f| 'bin/' << f} + %w~
|
12
|
+
s.files = %w~timequiz~.collect{|f| 'bin/' << f} + %w~basic_logging.rb version.rb file_checking.rb adder.rb argparser.rb busy_indicator.rb color_output.rb console.rb constants.rb event.rb events.rb extstring.rb user_input.rb timequiz.rb~.collect{|f| 'lib/' << f} + %w~timequiz.gemspec~.collect{|f|f} + %w~man/timequiz.6.gz html/timequiz.html pdf/timequiz.pdf rst/timequiz.rst license.txt~.collect{|f| 'doc/' << f} + ["README.md"]
|
13
13
|
s.homepage = ''
|
14
14
|
#s.requirements = ''
|
15
15
|
#s.add_runtime_dependency ''
|
16
16
|
s.executables = 'timequiz'
|
17
|
-
s.license = '
|
17
|
+
s.license = 'Nonstandard'
|
18
18
|
s.required_ruby_version = '>= 2.7'
|
19
19
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: timequiz
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.6
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Michael Uplawski
|
8
|
-
autorequire:
|
8
|
+
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2024-01-06 00:00:00.000000000 Z
|
12
12
|
dependencies: []
|
13
13
|
description: Play a history game
|
14
14
|
email: michael.uplawski@uplawski.eu
|
@@ -17,6 +17,7 @@ executables:
|
|
17
17
|
extensions: []
|
18
18
|
extra_rdoc_files: []
|
19
19
|
files:
|
20
|
+
- README.md
|
20
21
|
- bin/timequiz
|
21
22
|
- doc/html/timequiz.html
|
22
23
|
- doc/license.txt
|
@@ -25,6 +26,7 @@ files:
|
|
25
26
|
- doc/rst/timequiz.rst
|
26
27
|
- lib/adder.rb
|
27
28
|
- lib/argparser.rb
|
29
|
+
- lib/basic_logging.rb
|
28
30
|
- lib/busy_indicator.rb
|
29
31
|
- lib/color_output.rb
|
30
32
|
- lib/console.rb
|
@@ -33,17 +35,15 @@ files:
|
|
33
35
|
- lib/events.rb
|
34
36
|
- lib/extstring.rb
|
35
37
|
- lib/file_checking.rb
|
36
|
-
- lib/log.conf
|
37
|
-
- lib/logging.rb
|
38
38
|
- lib/timequiz.rb
|
39
39
|
- lib/user_input.rb
|
40
40
|
- lib/version.rb
|
41
41
|
- timequiz.gemspec
|
42
42
|
homepage: ''
|
43
43
|
licenses:
|
44
|
-
-
|
44
|
+
- Nonstandard
|
45
45
|
metadata: {}
|
46
|
-
post_install_message:
|
46
|
+
post_install_message:
|
47
47
|
rdoc_options: []
|
48
48
|
require_paths:
|
49
49
|
- lib
|
@@ -58,8 +58,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
58
58
|
- !ruby/object:Gem::Version
|
59
59
|
version: '0'
|
60
60
|
requirements: []
|
61
|
-
rubygems_version: 3.
|
62
|
-
signing_key:
|
61
|
+
rubygems_version: 3.4.20
|
62
|
+
signing_key:
|
63
63
|
specification_version: 4
|
64
64
|
summary: Some new events added. Fixed a bug in the logging-configuration.
|
65
65
|
test_files: []
|
data/lib/log.conf
DELETED
@@ -1,55 +0,0 @@
|
|
1
|
-
#encoding: UTF-8
|
2
|
-
=begin
|
3
|
-
/***************************************************************************
|
4
|
-
* ©2013 - 2021 Michael Uplawski <michael.uplawski@uplawski.eu> *
|
5
|
-
* *
|
6
|
-
* This program is free software; you can redistribute it and/or modify *
|
7
|
-
* it under the terms of the GNU General Public License as published by *
|
8
|
-
* the Free Software Foundation; either version 3 of the License, or *
|
9
|
-
* (at your option) any later version. *
|
10
|
-
* *
|
11
|
-
* This program is distributed in the hope that it will be useful, *
|
12
|
-
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
|
13
|
-
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
|
14
|
-
* GNU General Public License for more details. *
|
15
|
-
* *
|
16
|
-
* You should have received a copy of the GNU General Public License *
|
17
|
-
* along with this program; if not, write to the *
|
18
|
-
* Free Software Foundation, Inc., *
|
19
|
-
* 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
|
20
|
-
***************************************************************************/
|
21
|
-
|
22
|
-
A simplified logger configuration. Set the level for each individual logger
|
23
|
-
below. Choose a different log-device or log-file if you like. Keep the
|
24
|
-
formatting intact. Do not change other sections of this file.
|
25
|
-
=end
|
26
|
-
|
27
|
-
# Do not touch from here ----->
|
28
|
-
require 'logger'
|
29
|
-
|
30
|
-
debug = Logger::DEBUG
|
31
|
-
info = Logger::INFO
|
32
|
-
error = Logger::ERROR
|
33
|
-
fatal = Logger::FATAL
|
34
|
-
warn = Logger::WARN
|
35
|
-
unknown = Logger::UNKNOWN
|
36
|
-
{
|
37
|
-
# <---------------- to here !
|
38
|
-
|
39
|
-
# Enter your settings here, but take into consideration that not all
|
40
|
-
# the named classes will really produce readable output. Well, you can
|
41
|
-
# always try... Either name just the log-level or make the log-level
|
42
|
-
# precede the output-device or output-file like in the examples.
|
43
|
-
|
44
|
-
# Example: naming a log-file
|
45
|
-
#
|
46
|
-
# :HtmlBuilder => [info, 'C:\temp\htmlbuilder.log'],
|
47
|
-
#
|
48
|
-
# :HtmlBuilder => [debug, '/tmp/htmlbuilder.log'],
|
49
|
-
|
50
|
-
:Timequiz => info,
|
51
|
-
:Console => info,
|
52
|
-
|
53
|
-
# And ignore the remainder, too.
|
54
|
-
}
|
55
|
-
#eof
|
data/lib/logging.rb
DELETED
@@ -1,204 +0,0 @@
|
|
1
|
-
#encoding: UTF-8
|
2
|
-
=begin
|
3
|
-
/***************************************************************************
|
4
|
-
* ©2011-2016 Michael Uplawski <michael.uplawski@uplawski.eu> *
|
5
|
-
* *
|
6
|
-
* This program is free software; you can redistribute it and/or modify *
|
7
|
-
* it under the terms of the GNU General Public License as published by *
|
8
|
-
* the Free Software Foundation; either version 3 of the License, or *
|
9
|
-
* (at your option) any later version. *
|
10
|
-
* *
|
11
|
-
* This program is distributed in the hope that it will be useful, *
|
12
|
-
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
|
13
|
-
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
|
14
|
-
* GNU General Public License for more details. *
|
15
|
-
* *
|
16
|
-
* You should have received a copy of the GNU General Public License *
|
17
|
-
* along with this program; if not, write to the *
|
18
|
-
* Free Software Foundation, Inc., *
|
19
|
-
* 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
|
20
|
-
***************************************************************************/
|
21
|
-
=end
|
22
|
-
require 'logger'
|
23
|
-
require_relative 'file_checking'
|
24
|
-
|
25
|
-
=begin Creates a member @log and precede its output with the name of the class
|
26
|
-
of the object.
|
27
|
-
Example for a class-level logger:
|
28
|
-
# --------------------
|
29
|
-
class TClass
|
30
|
-
self.extend(Logging)
|
31
|
-
@@log = init_logger(STDOUT)
|
32
|
-
def test_log
|
33
|
-
@@log.info('class-level logger called from instance: ' << @@log.to_s)
|
34
|
-
@log = @@log
|
35
|
-
@log.info('AGAIN: class-level logger called from instance: ' << @log.to_s)
|
36
|
-
end
|
37
|
-
def self::test_log
|
38
|
-
@log.info('class-level logger called from class: ' << @log.to_s)
|
39
|
-
@@log.info('AGAIN: class-level logger called from class: ' << @@log.to_s)
|
40
|
-
end
|
41
|
-
end
|
42
|
-
#---------------------
|
43
|
-
Example for a object-level logger:
|
44
|
-
ATTN! This means 1 logger per object.
|
45
|
-
# --------------------
|
46
|
-
class TClass
|
47
|
-
include Logging
|
48
|
-
def initialize
|
49
|
-
init_logger(STDOUT, Logger::DEBUG)
|
50
|
-
end
|
51
|
-
def test_log
|
52
|
-
@log.debug('called test_log() ')
|
53
|
-
end
|
54
|
-
end
|
55
|
-
=end
|
56
|
-
module Logging
|
57
|
-
include File_Checking
|
58
|
-
|
59
|
-
@@have_log = false
|
60
|
-
@@LOG_CONF = File.dirname(File.absolute_path(__FILE__)) << File::Separator << 'log.conf'
|
61
|
-
|
62
|
-
# Call this method in an instance-method (e.g. initialize() ) to define the
|
63
|
-
# object-level logger; i.e. an object-specific member @log.
|
64
|
-
# Call this method within the class-definition for a class-level logger; i.e.
|
65
|
-
# a member @log for class-level acces.
|
66
|
-
# The method returns the logger, so you can actually do what you want with it.
|
67
|
-
def init_logger(target = STDOUT, level = Logger::INFO)
|
68
|
-
# Prepare for a class-level logger. This is actually quite cool.
|
69
|
-
|
70
|
-
# ---> Ingeniuous code starts here
|
71
|
-
cn = (self.class == Class ? name : self.class.name)
|
72
|
-
# <--- Ingeniuous code ends here
|
73
|
-
|
74
|
-
# allow to override the set log-levels with an
|
75
|
-
# external configuration (log.conf).
|
76
|
-
log_conf(cn)
|
77
|
-
# Or use the defaults as set here or elsewhere...
|
78
|
-
|
79
|
-
@level ||= level
|
80
|
-
@target ||= target
|
81
|
-
|
82
|
-
@log = Logger.new(@target)
|
83
|
-
@log.level = @level
|
84
|
-
|
85
|
-
@log.formatter = proc do |severity, datetime, progname, msg|
|
86
|
-
t = Time.now
|
87
|
-
"#{cn}: #{severity} #{t.hour}-#{t.min}-#{t.sec}: #{msg}\n"
|
88
|
-
end
|
89
|
-
if ! @@have_log
|
90
|
-
@log.debug cn.dup << ' reading logging-configuration from ' << @@LOG_CONF
|
91
|
-
@@have_log = true
|
92
|
-
@log.debug('level is ' << level.to_s)
|
93
|
-
end
|
94
|
-
return @log
|
95
|
-
end
|
96
|
-
|
97
|
-
def log_label=(label)
|
98
|
-
@log.formatter = proc do |severity, datetime, progname, msg|
|
99
|
-
t = Time.now
|
100
|
-
if(label && !label.empty?)
|
101
|
-
"#{label}: #{severity} #{t.hour}-#{t.min}-#{t.sec}: #{msg}\n"
|
102
|
-
else
|
103
|
-
"#{$0}: #{severity} #{t.hour}-#{t.min}-#{t.sec}: #{msg}\n"
|
104
|
-
end
|
105
|
-
end
|
106
|
-
end
|
107
|
-
|
108
|
-
# Set the log-target to an IO object.
|
109
|
-
def log_target=(target)
|
110
|
-
@target = target
|
111
|
-
@log = Logger.new(@@target)
|
112
|
-
@log.level = @level
|
113
|
-
end
|
114
|
-
|
115
|
-
# set the log-level
|
116
|
-
def log_level=(level)
|
117
|
-
@level = level
|
118
|
-
@log.level = @level
|
119
|
-
end
|
120
|
-
|
121
|
-
private
|
122
|
-
|
123
|
-
# Override or set the log-level and target-device, as set in a file 'log.conf'.
|
124
|
-
# I do not like the look of this, but it works just the way I want it to.
|
125
|
-
# "HEAVANS! Isn't there a standard way to do this in Ruby, for Christ's sake?", you say.
|
126
|
-
# Heck, I don't care. <= Read that again, I say.
|
127
|
-
def log_conf(cn = nil)
|
128
|
-
config = level = target = nil
|
129
|
-
# puts 'log-config is in ' << @@LOG_CONF
|
130
|
-
if(File::exist?(@@LOG_CONF) )
|
131
|
-
begin
|
132
|
-
conf = File.read(@@LOG_CONF)
|
133
|
-
config = instance_eval(conf)
|
134
|
-
rescue Exception => ex
|
135
|
-
STDERR.puts "WARNING! Cannot evaluate the logger-configuration!" << ' ' << ex.message
|
136
|
-
STDERR.puts "Default log-levels apply."
|
137
|
-
end
|
138
|
-
# else
|
139
|
-
# puts "Default log-levels apply."
|
140
|
-
end
|
141
|
-
|
142
|
-
if(config && config.respond_to?(:to_hash) )
|
143
|
-
config.default = nil
|
144
|
-
if cn
|
145
|
-
config = config[cn.to_sym]
|
146
|
-
else
|
147
|
-
config = config[self.class.name.to_sym]
|
148
|
-
end
|
149
|
-
|
150
|
-
if(config )
|
151
|
-
if(config.respond_to?(:to_ary) && config.size == 2)
|
152
|
-
@level, @target = config
|
153
|
-
@target.downcase!
|
154
|
-
logdir = File.dirname(@target)
|
155
|
-
msg = file_check(logdir, :exist?, :directory?, :writable?)
|
156
|
-
if(msg)
|
157
|
-
STDERR.puts "WARNING! A logfile for '%s' cannot be written to %s (%s)!" %[self.class.name, logdir, msg]
|
158
|
-
@target = nil
|
159
|
-
end
|
160
|
-
else
|
161
|
-
@level = config
|
162
|
-
end
|
163
|
-
end
|
164
|
-
end
|
165
|
-
end
|
166
|
-
end
|
167
|
-
|
168
|
-
######### test
|
169
|
-
if __FILE__ == $0
|
170
|
-
class TClass
|
171
|
-
# class level ---->
|
172
|
-
self.extend(Logging)
|
173
|
-
@@log = init_logger(STDOUT, Logger::INFO)
|
174
|
-
# <------
|
175
|
-
# object-level ---->
|
176
|
-
include Logging
|
177
|
-
# <---------
|
178
|
-
|
179
|
-
def test_log
|
180
|
-
@@log.info('class-level logger called from instance: ' << @@log.to_s)
|
181
|
-
#@log = @@log # works too
|
182
|
-
@log = TClass.class_eval{@log}
|
183
|
-
@log.info('AGAIN: class-level logger called from instance: ' << @log.to_s)
|
184
|
-
@log.debug("you won't see this on log-level INFO")
|
185
|
-
|
186
|
-
# object-level ---->
|
187
|
-
init_logger
|
188
|
-
# <-----------
|
189
|
-
@log.info("That's a different thing: " << @log.to_s << " - object-level logger!")
|
190
|
-
|
191
|
-
end
|
192
|
-
def self::test_log
|
193
|
-
@log.info('class-level logger called from class: ' << @log.to_s)
|
194
|
-
@@log.info('AGAIN: class-level logger called from class: ' << @log.to_s)
|
195
|
-
end
|
196
|
-
end
|
197
|
-
|
198
|
-
TClass.new.test_log # class-logger + 1st object-logger
|
199
|
-
TClass.new.test_log # same class-logger + 2nd object-logger
|
200
|
-
|
201
|
-
TClass::test_log # same class-logger
|
202
|
-
puts 'And just say it once clearly: THIS IS COOOL!!'
|
203
|
-
end
|
204
|
-
#EOF
|