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
27 28 29 30 31 |
# File 'lib/syslog_tls/logger.rb', line 27 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.
22 23 24 |
# File 'lib/syslog_tls/logger.rb', line 22 def token @token end |
#transport ⇒ Object
Returns the value of attribute transport.
23 24 25 |
# File 'lib/syslog_tls/logger.rb', line 23 def transport @transport end |
Instance Method Details
#app_name(val) ⇒ Object
Sets default app_name for each message
44 45 46 |
# File 'lib/syslog_tls/logger.rb', line 44 def app_name(val) @default_header.app_name = val end |
#close ⇒ Object
58 59 60 |
# File 'lib/syslog_tls/logger.rb', line 58 def close transport.close end |
#closed? ⇒ Boolean
Check if IO is closed
54 55 56 |
# File 'lib/syslog_tls/logger.rb', line 54 def closed? transport && transport.closed? end |
#facility(val) ⇒ Object
Sets default facility for each message
34 35 36 |
# File 'lib/syslog_tls/logger.rb', line 34 def facility(val) @default_header.facility = val end |
#hostname(val) ⇒ Object
Sets default hostname for each message
39 40 41 |
# File 'lib/syslog_tls/logger.rb', line 39 def hostname(val) @default_header.hostname = val end |
#log(severity, message, time: nil) {|m.header| ... } ⇒ Object
Send log message with severity to syslog
63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 |
# File 'lib/syslog_tls/logger.rb', line 63 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
49 50 51 |
# File 'lib/syslog_tls/logger.rb', line 49 def procid(val) @default_header.procid = val end |