Module: Modsvaskr::Logger
- Included in:
- Game, InGameTestsRunner, TestsRunner, TestsSuite, Ui, Xedit
- Defined in:
- lib/modsvaskr/logger.rb
Overview
Mixin adding logging functionality, both on screen and in file
Class Attribute Summary collapse
-
.log_file ⇒ Object
Returns the value of attribute log_file.
-
.stdout_io ⇒ Object
Returns the value of attribute stdout_io.
Instance Method Summary collapse
-
#log(msg) ⇒ Object
Log on screen and in log file.
-
#out(msg) ⇒ Object
Display an output to the user.
-
#wait_for_user_enter ⇒ Object
Wait for the user to enter a line and hit Enter.
Class Attribute Details
.log_file ⇒ Object
Returns the value of attribute log_file.
8 9 10 |
# File 'lib/modsvaskr/logger.rb', line 8 def log_file @log_file end |
.stdout_io ⇒ Object
Returns the value of attribute stdout_io.
8 9 10 |
# File 'lib/modsvaskr/logger.rb', line 8 def stdout_io @stdout_io end |
Instance Method Details
#log(msg) ⇒ Object
Log on screen and in log file
- Parameters
-
msg (String): Message to log
18 19 20 21 22 23 24 |
# File 'lib/modsvaskr/logger.rb', line 18 def log(msg) complete_msg = "[ #{Time.now.strftime('%F %T')} ] - [ #{self.class.name.split('::').last} ] - #{msg}" Logger.stdout_io << "#{complete_msg}\n" File.open(Logger.log_file, 'a') do |f| f.puts complete_msg end end |
#out(msg) ⇒ Object
Display an output to the user. This is not a log.
- Parameters
-
msg (String): Message to output
31 32 33 |
# File 'lib/modsvaskr/logger.rb', line 31 def out(msg) Logger.stdout_io << "#{msg}\n" end |
#wait_for_user_enter ⇒ Object
Wait for the user to enter a line and hit Enter
- Result
-
String: The line entered by the user
39 40 41 |
# File 'lib/modsvaskr/logger.rb', line 39 def wait_for_user_enter @config.no_prompt ? "\n" : $stdin.gets end |