Class: SyslogTls::Logger
- Inherits:
-
Object
- Object
- SyslogTls::Logger
- Defined in:
- lib/syslog_tls/logger.rb
Instance Attribute Summary collapse
-
#token ⇒ Object
readonly
Returns the value of attribute token.
-
#transport ⇒ Object
Returns the value of attribute transport.
Instance Method Summary collapse
-
#app_name(val) ⇒ Object
Sets default app_name for each message.
- #close ⇒ Object
-
#closed? ⇒ Boolean
Check if IO is closed.
-
#facility(val) ⇒ Object
Sets default facility for each message.
-
#hostname(val) ⇒ Object
Sets default hostname for each message.
-
#initialize(transport, token = nil) ⇒ Logger
constructor
Logger accepts transport which should implement IO methods close, closed? and write.
-
#log(severity, message, time: nil) {|m.header| ... } ⇒ Object
Send log message with severity to syslog.
-
#procid(val) ⇒ Object
Sets default procid for message.
Constructor Details
#initialize(transport, token = nil) ⇒ Logger
Logger accepts transport which should implement IO methods close, closed? and write
26 27 28 29 30 |
# File 'lib/syslog_tls/logger.rb', line 26 def initialize(transport, token=nil) @transport = transport @default_header = SyslogTls::Header.new @default_structured_data = SyslogTls::StructuredData.new(token) end |
Instance Attribute Details
#token ⇒ Object (readonly)
Returns the value of attribute token.
21 22 23 |
# File 'lib/syslog_tls/logger.rb', line 21 def token @token end |
#transport ⇒ Object
Returns the value of attribute transport.
22 23 24 |
# File 'lib/syslog_tls/logger.rb', line 22 def transport @transport end |
Instance Method Details
#app_name(val) ⇒ Object
Sets default app_name for each message
43 44 45 |
# File 'lib/syslog_tls/logger.rb', line 43 def app_name(val) @default_header.app_name = val end |
#close ⇒ Object
57 58 59 |
# File 'lib/syslog_tls/logger.rb', line 57 def close transport.close end |
#closed? ⇒ Boolean
Check if IO is closed
53 54 55 |
# File 'lib/syslog_tls/logger.rb', line 53 def closed? transport && transport.closed? end |
#facility(val) ⇒ Object
Sets default facility for each message
33 34 35 |
# File 'lib/syslog_tls/logger.rb', line 33 def facility(val) @default_header.facility = val end |
#hostname(val) ⇒ Object
Sets default hostname for each message
38 39 40 |
# File 'lib/syslog_tls/logger.rb', line 38 def hostname(val) @default_header.hostname = val end |
#log(severity, message, time: nil) {|m.header| ... } ⇒ Object
Send log message with severity to syslog
62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 |
# File 'lib/syslog_tls/logger.rb', line 62 def log(severity, , time: nil) time ||= Time.now m = SyslogTls::Message.new # Include authentication header m.structured_data << @default_structured_data # Adjust header with current timestamp and severity m.header = @default_header.dup m.header.severity = severity m.header. = time yield m.header if block_given? m.msg = transport.write(m.to_s) end |
#procid(val) ⇒ Object
Sets default procid for message
48 49 50 |
# File 'lib/syslog_tls/logger.rb', line 48 def procid(val) @default_header.procid = val end |