Class: Scribe
- Inherits:
-
Object
- Object
- Scribe
- Defined in:
- lib/scribe/scribe.rb
Constant Summary collapse
- PROTOCOL_OPTIONS =
{ :protocol_extra_params => [false] }
Instance Method Summary collapse
-
#batch ⇒ Object
Batch several calls to Scribe#log together.
-
#initialize(servers = "127.0.0.1:1463", category = "Ruby", add_newlines = true, options = {}) ⇒ Scribe
constructor
Created a new client instance.
-
#log(message, category = @category) ⇒ Object
(also: #debug, #error, #fatal, #info, #warn)
Log a message.
Constructor Details
#initialize(servers = "127.0.0.1:1463", category = "Ruby", add_newlines = true, options = {}) ⇒ Scribe
Created a new client instance. Accepts an optional host and port, default category, flag to control whether newlines are added to each line, and additional settings to be passed to ThriftClient.
8 9 10 11 12 13 |
# File 'lib/scribe/scribe.rb', line 8 def initialize(servers = "127.0.0.1:1463", category = "Ruby", add_newlines = true, = {}) @servers = servers @category = category @add_newlines = add_newlines @client = ThriftClient.new(ScribeThrift::Client, @servers, .merge(PROTOCOL_OPTIONS)) end |
Instance Method Details
#batch ⇒ Object
Batch several calls to Scribe#log together. Yields to a block.
26 27 28 29 30 31 32 |
# File 'lib/scribe/scribe.rb', line 26 def batch @batch = [] yield @client.Log(@batch) ensure @batch = nil end |
#log(message, category = @category) ⇒ Object Also known as: debug, error, fatal, info, warn
Log a message. Accepts a string and an optional category.
16 17 18 19 20 21 22 23 |
# File 'lib/scribe/scribe.rb', line 16 def log(, category = @category) raise ArgumentError, "Message must be a string" unless .is_a?(String) raise ArgumentError, "Category must be a string" unless category.is_a?(String) << "\n" if @add_newlines entry = ScribeThrift::LogEntry.new(:message => , :category => category) @batch ? @batch << entry : @client.Log(Array(entry)) end |