Class: Logger
Overview
backtick_javascript: true
Defined Under Namespace
Modules: Severity
Classes: Formatter
Constant Summary
collapse
- SEVERITY_LABELS =
Severity.constants.map { |s| [(Severity.const_get s), s.to_s] }.to_h
Constants included
from Severity
Severity::DEBUG, Severity::ERROR, Severity::FATAL, Severity::INFO, Severity::UNKNOWN, Severity::WARN
Instance Attribute Summary collapse
Instance Method Summary
collapse
Constructor Details
#initialize(pipe) ⇒ Logger
Returns a new instance of Logger.
[View source]
40
41
42
43
44
|
# File 'opal/stdlib/logger.rb', line 40
def initialize(pipe)
@pipe = pipe
@level = DEBUG
@formatter = Formatter.new
end
|
Instance Attribute Details
Returns the value of attribute formatter.
38
39
40
|
# File 'opal/stdlib/logger.rb', line 38
def formatter
@formatter
end
|
Returns the value of attribute level.
36
37
38
|
# File 'opal/stdlib/logger.rb', line 36
def level
@level
end
|
Returns the value of attribute progname.
37
38
39
|
# File 'opal/stdlib/logger.rb', line 37
def progname
@progname
end
|
Instance Method Details
#add(severity, message = nil, progname = nil, &block) ⇒ Object
[View source]
100
101
102
103
104
105
106
107
108
109
110
111
112
113
|
# File 'opal/stdlib/logger.rb', line 100
def add(severity, message = nil, progname = nil, &block)
return true if (severity ||= UNKNOWN) < @level
progname ||= @progname
unless message
if block_given?
message = yield
else
message = progname
progname = @progname
end
end
@pipe.write(@formatter.call(SEVERITY_LABELS[severity] || 'ANY', ::Time.now, progname, message))
true
end
|
#debug(progname = nil, &block) ⇒ Object
[View source]
60
61
62
|
# File 'opal/stdlib/logger.rb', line 60
def debug(progname = nil, &block)
add DEBUG, nil, progname, &block
end
|
[View source]
84
85
86
|
# File 'opal/stdlib/logger.rb', line 84
def debug?
@level <= DEBUG
end
|
#error(progname = nil, &block) ⇒ Object
[View source]
68
69
70
|
# File 'opal/stdlib/logger.rb', line 68
def error(progname = nil, &block)
add ERROR, nil, progname, &block
end
|
[View source]
92
93
94
|
# File 'opal/stdlib/logger.rb', line 92
def error?
@level <= ERROR
end
|
#fatal(progname = nil, &block) ⇒ Object
[View source]
72
73
74
|
# File 'opal/stdlib/logger.rb', line 72
def fatal(progname = nil, &block)
add FATAL, nil, progname, &block
end
|
[View source]
96
97
98
|
# File 'opal/stdlib/logger.rb', line 96
def fatal?
@level <= FATAL
end
|
#info(progname = nil, &block) ⇒ Object
[View source]
56
57
58
|
# File 'opal/stdlib/logger.rb', line 56
def info(progname = nil, &block)
add INFO, nil, progname, &block
end
|
[View source]
80
81
82
|
# File 'opal/stdlib/logger.rb', line 80
def info?
@level <= INFO
end
|
#unknown(progname = nil, &block) ⇒ Object
[View source]
76
77
78
|
# File 'opal/stdlib/logger.rb', line 76
def unknown(progname = nil, &block)
add UNKNOWN, nil, progname, &block
end
|
#warn(progname = nil, &block) ⇒ Object
[View source]
64
65
66
|
# File 'opal/stdlib/logger.rb', line 64
def warn(progname = nil, &block)
add WARN, nil, progname, &block
end
|
[View source]
88
89
90
|
# File 'opal/stdlib/logger.rb', line 88
def warn?
@level <= WARN
end
|