Module: Lines

Extended by:
UniqueIDs
Defined in:
lib/lines.rb,
lib/lines/loader.rb,
lib/lines/logger.rb,
lib/lines/version.rb,
lib/lines/rack_logger.rb,
lib/lines/active_record.rb

Overview

Defined Under Namespace

Modules: Error, Loader, ParseError, UniqueIDs Classes: ActiveRecordSubscriber, Context, Dumper, Logger, Parser, RackLogger, StreamOutputter, SyslogOutputter, Transformer

Constant Summary collapse

NL =

New lines in Lines

"\n".freeze
VERSION =
"0.1.26"

Class Attribute Summary collapse

Class Method Summary collapse

Methods included from UniqueIDs

id

Class Attribute Details

.globalObject (readonly)

Returns the value of attribute global.



40
41
42
# File 'lib/lines.rb', line 40

def global
  @global
end

.outputtersObject (readonly)

Returns the value of attribute outputters.



41
42
43
# File 'lib/lines.rb', line 41

def outputters
  @outputters
end

Class Method Details

.context(data = {}) {|new_context| ... } ⇒ Object

Add data to the logs

data - a ruby hash

return a Context instance

Yields:

  • (new_context)


69
70
71
72
73
# File 'lib/lines.rb', line 69

def context(data={})
  new_context = Context.new ensure_hash!(data)
  yield new_context if block_given?
  new_context
end

.dumperObject



39
# File 'lib/lines.rb', line 39

def dumper; @dumper ||= Dumper.new end

.ensure_hash!(obj) ⇒ Object

:nodoc:



83
84
85
86
87
88
# File 'lib/lines.rb', line 83

def ensure_hash!(obj) # :nodoc:
  return {} unless obj
  return obj if obj.kind_of?(Hash)
  return obj.to_h if obj.respond_to?(:to_h)
  obj = {msg: obj}
end

.log(obj, args = {}) ⇒ Object

The main function. Used to record objects in the logs as lines.

obj - a ruby hash args -



58
59
60
61
62
# File 'lib/lines.rb', line 58

def log(obj, args={})
  obj = prepare_obj(obj, args)
  outputters.each{|out| out.output(dumper, obj) }
  obj
end

.loggerObject

Returns a backward-compatibile logger



76
77
78
79
80
81
# File 'lib/lines.rb', line 76

def logger
  @logger ||= (
    require 'lines/logger'
    Logger.new(self)
  )
end

.use(*outputs) ⇒ Object

Used to select what output the lines will be put on.

outputs - allows any kind of IO or Syslog

Usage:

Lines.use(Syslog, $stderr)


50
51
52
# File 'lib/lines.rb', line 50

def use(*outputs)
  outputters.replace(outputs.flatten.map{|o| to_outputter o})
end