Module: RgssDb::Debug
- Defined in:
- lib/rgss_db/model/debug.rb
Overview
Debug module
Constant Summary collapse
- DEBUG_FILE_NAME =
Debug log file name
"rgss-db.log"
- DEBUG_MODE_DISABLE =
Debug mode disabled
0
- DEBUG_MODE_ERROR =
Debug mode errors and below
1
- DEBUG_MODE_WARNING =
Debug mode warnings and below
2
- DEBUG_MODE_INFO =
Debug mode info and below
3
Class Method Summary collapse
-
.debug_mode ⇒ Integer
Gets the debug mode.
-
.disabled? ⇒ Boolean
Checks whether the debug module is disabled or not.
-
.error? ⇒ Boolean
Checks whether the debug mode is error or not.
-
.info? ⇒ Boolean
Checks whether the debug mode is info or not.
-
.log(string) ⇒ Object
Logs the string.
-
.log_error(string) ⇒ Object
Logs the string as an error.
-
.log_exception(exception, app_options = nil) ⇒ Object
Logs the given exception as an error.
-
.log_info(string) ⇒ Object
Logs the string as information.
-
.log_warning(string) ⇒ Object
Logs the string as a warning.
-
.start(debug_file_path, debug_mode = nil) ⇒ Object
Starts the debug module with the given information.
-
.update_debug_mode(debug_mode) ⇒ Object
Sets the debug mode.
-
.update_extra_info(*extra_info) ⇒ Object
Sets the debug extra information.
-
.warning? ⇒ Boolean
Checks whether the debug mode is warning or not.
-
.write_debug_header ⇒ Object
Writes the debug header to the log file.
Class Method Details
.debug_mode ⇒ Integer
Gets the debug mode
66 67 68 |
# File 'lib/rgss_db/model/debug.rb', line 66 def self.debug_mode @debug_mode end |
.disabled? ⇒ Boolean
Checks whether the debug module is disabled or not
168 169 170 |
# File 'lib/rgss_db/model/debug.rb', line 168 def self.disabled? @debug_mode == DEBUG_MODE_DISABLE end |
.error? ⇒ Boolean
Checks whether the debug mode is error or not
186 187 188 |
# File 'lib/rgss_db/model/debug.rb', line 186 def self.error? @debug_mode >= DEBUG_MODE_ERROR end |
.info? ⇒ Boolean
Checks whether the debug mode is info or not
177 178 179 |
# File 'lib/rgss_db/model/debug.rb', line 177 def self.info? @debug_mode >= DEBUG_MODE_INFO end |
.log(string) ⇒ Object
Logs the string
106 107 108 |
# File 'lib/rgss_db/model/debug.rb', line 106 def self.log(string) File.write(@debug_file_path, "#{string}\n", mode: "a") unless disabled? end |
.log_error(string) ⇒ Object
Logs the string as an error
124 125 126 |
# File 'lib/rgss_db/model/debug.rb', line 124 def self.log_error(string) log("error: #{string}") if error? end |
.log_exception(exception, app_options = nil) ⇒ Object
Logs the given exception as an error
Optionally logs the application options if given
146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 |
# File 'lib/rgss_db/model/debug.rb', line 146 def self.log_exception(exception, = nil) # Logs the exception log_error("Application Exception:") log_error("\t#{exception.} (#{exception.class})") exception.backtrace.each do |str| log_error("\t\tfrom #{str}") end return unless .is_a?(Hash) # Logs the application options log_error("Application options:") .each_pair do |opt_id, opt_value| log_error("\t- #{opt_id} => #{opt_value}") end end |
.log_info(string) ⇒ Object
Logs the string as information
115 116 117 |
# File 'lib/rgss_db/model/debug.rb', line 115 def self.log_info(string) log("info: #{string}") if info? end |
.log_warning(string) ⇒ Object
Logs the string as a warning
133 134 135 |
# File 'lib/rgss_db/model/debug.rb', line 133 def self.log_warning(string) log("warning: #{string}") if warning? end |
.start(debug_file_path, debug_mode = nil) ⇒ Object
Starts the debug module with the given information
Optionally sets the debug mode
50 51 52 53 54 55 56 57 58 59 |
# File 'lib/rgss_db/model/debug.rb', line 50 def self.start(debug_file_path, debug_mode = nil) @debug_file_path = File.join(debug_file_path, DEBUG_FILE_NAME) @debug_mode = debug_mode unless debug_mode.nil? # Creates the directory (recursively) FileUtils.mkdir_p(debug_file_path) # Overwrites file if it exists already File.truncate(@debug_file_path, 0) if File.exist?(@debug_file_path) end |
.update_debug_mode(debug_mode) ⇒ Object
Sets the debug mode
Set to 0 to disable
77 78 79 |
# File 'lib/rgss_db/model/debug.rb', line 77 def self.update_debug_mode(debug_mode) @debug_mode = debug_mode end |
.update_extra_info(*extra_info) ⇒ Object
Sets the debug extra information
86 87 88 |
# File 'lib/rgss_db/model/debug.rb', line 86 def self.update_extra_info(*extra_info) @debug_extra_info = extra_info end |
.warning? ⇒ Boolean
Checks whether the debug mode is warning or not
195 196 197 |
# File 'lib/rgss_db/model/debug.rb', line 195 def self.warning? @debug_mode >= DEBUG_MODE_WARNING end |
.write_debug_header ⇒ Object
Writes the debug header to the log file
93 94 95 96 97 98 99 |
# File 'lib/rgss_db/model/debug.rb', line 93 def self.write_debug_header log("<--- debug module started --->") log("debug mode: #{Debug.debug_mode}") log("debug extra:") @debug_extra_info.each { |str| log("\t- #{str}") } log("<---------------------------->") end |