Class: CertificateDepot::Log
- Inherits:
-
Object
- Object
- CertificateDepot::Log
- Defined in:
- lib/certificate_depot/log.rb
Overview
Constant Summary collapse
- DEBUG =
0
- INFO =
1
- WARN =
2
- ERROR =
3
- FATAL =
4
- UNKNOWN =
5
- SILENT =
Used to stop logging altogether
9
Instance Attribute Summary collapse
-
#file ⇒ Object
Holds the current log file.
-
#level ⇒ Object
Holds the current log level.
Class Method Summary collapse
-
.format(*args) ⇒ Object
Format the log message.
Instance Method Summary collapse
-
#close ⇒ Object
Close the logger.
-
#debug(*args) ⇒ Object
Log if the error level is debug or lower.
-
#error(*args) ⇒ Object
Log if the error level is error or lower.
-
#fatal(*args) ⇒ Object
Log if the error level is fatal or lower.
-
#info(*args) ⇒ Object
Log if the error level is info or lower.
-
#initialize(file, options = {}) ⇒ Log
constructor
Creates a new Log instance.
-
#log(message_level, *args) ⇒ Object
Writes a message to the log is the current loglevel is equal or greater than the message_level.
-
#unknown(*args) ⇒ Object
Log if the error level is unknown or lower.
-
#warn(*args) ⇒ Object
Log if the error level is warn or lower.
Constructor Details
Instance Attribute Details
#file ⇒ Object
Holds the current log file
18 19 20 |
# File 'lib/certificate_depot/log.rb', line 18 def file @file end |
#level ⇒ Object
Holds the current log level
20 21 22 |
# File 'lib/certificate_depot/log.rb', line 20 def level @level end |
Class Method Details
.format(*args) ⇒ Object
Format the log message
57 58 59 |
# File 'lib/certificate_depot/log.rb', line 57 def self.format(*args) ["[#{Process.pid.to_s.rjust(5)}] ", Time.now.strftime("%Y-%m-%d %H:%M:%S"), '| ', args.first, "\n"].join end |
Instance Method Details
#close ⇒ Object
Close the logger
52 53 54 |
# File 'lib/certificate_depot/log.rb', line 52 def close @file.close end |
#debug(*args) ⇒ Object
Log if the error level is debug or lower.
29 |
# File 'lib/certificate_depot/log.rb', line 29 def debug(*args); log(DEBUG, *args); end |
#error(*args) ⇒ Object
Log if the error level is error or lower.
35 |
# File 'lib/certificate_depot/log.rb', line 35 def error(*args); log(ERROR, *args); end |
#fatal(*args) ⇒ Object
Log if the error level is fatal or lower.
37 |
# File 'lib/certificate_depot/log.rb', line 37 def fatal(*args); log(FATAL, *args); end |
#info(*args) ⇒ Object
Log if the error level is info or lower.
31 |
# File 'lib/certificate_depot/log.rb', line 31 def info(*args); log(INFO, *args); end |
#log(message_level, *args) ⇒ Object
44 45 46 47 48 49 |
# File 'lib/certificate_depot/log.rb', line 44 def log(, *args) @file.flock(File::LOCK_EX) @file.write(self.class.format(*args)) if >= level @file.flock(File::LOCK_UN) rescue IOError end |
#unknown(*args) ⇒ Object
Log if the error level is unknown or lower.
39 |
# File 'lib/certificate_depot/log.rb', line 39 def unknown(*args); log(UNKNOWN, *args); end |
#warn(*args) ⇒ Object
Log if the error level is warn or lower.
33 |
# File 'lib/certificate_depot/log.rb', line 33 def warn(*args); log(WARN, *args); end |