Class: Percy::PercyLogger
- Inherits:
-
Object
- Object
- Percy::PercyLogger
- Defined in:
- lib/percy/percylogger.rb
Constant Summary collapse
- DEBUG =
0- INFO =
1- WARN =
2- ERROR =
3- FATAL =
4- UNKNOWN =
5- LEVEL =
['DEBUG', 'INFO', 'WARN', 'ERROR', 'FATAL', 'UNKNOWN']
Instance Attribute Summary collapse
-
#file ⇒ Object
Returns the value of attribute file.
-
#level ⇒ Object
Returns the value of attribute level.
-
#time_format ⇒ Object
Returns the value of attribute time_format.
Instance Method Summary collapse
- #debug(message) ⇒ Object
- #error(message) ⇒ Object
- #fatal(message) ⇒ Object
- #info(message) ⇒ Object
-
#initialize(dirpath = Pathname.new($0).dirname.join('logs').expand_path, filename = 'log.log', level = DEBUG, time_format = '%d.%m.%Y %H:%M:%S') ⇒ PercyLogger
constructor
A new instance of PercyLogger.
- #unknown(message) ⇒ Object
- #warn(message) ⇒ Object
- #write(severity, message) ⇒ Object
Constructor Details
#initialize(dirpath = Pathname.new($0).dirname.join('logs').expand_path, filename = 'log.log', level = DEBUG, time_format = '%d.%m.%Y %H:%M:%S') ⇒ PercyLogger
Returns a new instance of PercyLogger.
16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 |
# File 'lib/percy/percylogger.rb', line 16 def initialize(dirpath = Pathname.new($0).dirname.join('logs')., filename = 'log.log', level = DEBUG, time_format = '%d.%m.%Y %H:%M:%S') @dirpath = dirpath @pathname = dirpath.join(filename) @level = level @time_format = time_format @mutex = Mutex.new unless @pathname.exist? unless @dirpath.directory? FileUtils.mkdir_p @dirpath end File.new(@pathname, 'w+') end @file = File.open(@pathname, 'a+') @file.sync = true end |
Instance Attribute Details
#file ⇒ Object
Returns the value of attribute file.
14 15 16 |
# File 'lib/percy/percylogger.rb', line 14 def file @file end |
#level ⇒ Object
Returns the value of attribute level.
14 15 16 |
# File 'lib/percy/percylogger.rb', line 14 def level @level end |
#time_format ⇒ Object
Returns the value of attribute time_format.
14 15 16 |
# File 'lib/percy/percylogger.rb', line 14 def time_format @time_format end |
Instance Method Details
#debug(message) ⇒ Object
48 49 50 |
# File 'lib/percy/percylogger.rb', line 48 def debug() write DEBUG, end |
#error(message) ⇒ Object
60 61 62 |
# File 'lib/percy/percylogger.rb', line 60 def error() write ERROR, end |
#fatal(message) ⇒ Object
64 65 66 |
# File 'lib/percy/percylogger.rb', line 64 def fatal() write FATAL, end |
#info(message) ⇒ Object
52 53 54 |
# File 'lib/percy/percylogger.rb', line 52 def info() write INFO, end |
#unknown(message) ⇒ Object
68 69 70 |
# File 'lib/percy/percylogger.rb', line 68 def unknown() write UNKNOWN, end |
#warn(message) ⇒ Object
56 57 58 |
# File 'lib/percy/percylogger.rb', line 56 def warn() write WARN, end |
#write(severity, message) ⇒ Object
35 36 37 38 39 40 41 42 43 44 45 46 |
# File 'lib/percy/percylogger.rb', line 35 def write(severity, ) begin if severity >= @level @mutex.synchronize do @file.puts "#{LEVEL[severity]} #{Time.now.strftime(@time_format)} #{message}" end end rescue => e puts e. puts e.backtrace.join('\n') end end |