Module: Scrolls

Extended by:
Scrolls
Included in:
Scrolls
Defined in:
lib/scrolls.rb,
lib/scrolls/log.rb,
lib/scrolls/utils.rb,
lib/scrolls/atomic.rb,
lib/scrolls/parser.rb,
lib/scrolls/syslog.rb,
lib/scrolls/version.rb

Defined Under Namespace

Modules: Log, Parser, Utils Classes: Atomic, AtomicObject, SyslogLogger, TimeUnitError

Constant Summary collapse

LOG_FACILITY =
ENV['LOG_FACILITY'] || Syslog::LOG_USER
LOG_FACILITY_MAP =
{
  "auth"     => Syslog::LOG_AUTH,
  "authpriv" => Syslog::LOG_AUTHPRIV,
  "cron"     => Syslog::LOG_CRON,
  "daemon"   => Syslog::LOG_DAEMON,
  "ftp"      => Syslog::LOG_FTP,
  "kern"     => Syslog::LOG_KERN,
  "mail"     => Syslog::LOG_MAIL,
  "news"     => Syslog::LOG_NEWS,
  "syslog"   => Syslog::LOG_SYSLOG,
  "user"     => Syslog::LOG_USER,
  "uucp"     => Syslog::LOG_UUCP,
  "local0"   => Syslog::LOG_LOCAL0,
  "local1"   => Syslog::LOG_LOCAL1,
  "local2"   => Syslog::LOG_LOCAL2,
  "local3"   => Syslog::LOG_LOCAL3,
  "local4"   => Syslog::LOG_LOCAL4,
  "local5"   => Syslog::LOG_LOCAL5,
  "local6"   => Syslog::LOG_LOCAL6,
  "local7"   => Syslog::LOG_LOCAL7,
}
VERSION =
"0.3.3"

Instance Method Summary collapse

Instance Method Details

#add_global_context(data) ⇒ Object



32
33
34
# File 'lib/scrolls.rb', line 32

def add_global_context(data)
  Log.add_global_context(data)
end

#add_timestampObject

Public: Return whether the timestamp field will be included in the log output.

Examples

Scrolls.add_timestamp
=> true


168
169
170
# File 'lib/scrolls.rb', line 168

def add_timestamp
  Log.add_timestamp
end

#add_timestamp=(boolean) ⇒ Object

Public: Set whether to include a timestamp (now=<ISO8601>) field in the log output (default: false)

Examples

Scrolls.add_timestamp = true


156
157
158
# File 'lib/scrolls.rb', line 156

def add_timestamp=(boolean)
  Log.add_timestamp = boolean
end

#context(data, &blk) ⇒ Object

Public: Set a context in a block for logs

data - A hash of key/values to prepend to each log in a block blk - The block that our context wraps

Examples:



16
17
18
# File 'lib/scrolls.rb', line 16

def context(data, &blk)
  Log.with_context(data, &blk)
end

#facilityObject

Public: Return the Syslog facility

Examples

Scrolls.facility
=> 8


95
96
97
# File 'lib/scrolls.rb', line 95

def facility
  Log.facility
end

#facility=(f) ⇒ Object

Public: Setup a logging facility (default: Syslog::LOG_USER)

facility - Syslog facility

Examples

Scrolls.facility = Syslog::LOG_LOCAL7


84
85
86
# File 'lib/scrolls.rb', line 84

def facility=(f)
  Log.facility=(f)
end

#global_context(data = nil) ⇒ Object

Public: Get or set a global context that prefixs all logs

data - A hash of key/values to prepend to each log



24
25
26
27
28
29
30
# File 'lib/scrolls.rb', line 24

def global_context(data=nil)
  if data
    Log.global_context = data
  else
    Log.global_context
  end
end

#log(data, &blk) ⇒ Object

Public: Log data and/or wrap a block with start/finish

data - A hash of key/values to log blk - A block to be wrapped by log lines

Examples:

Scrolls.log(test: "test")
test=test
=> nil

Scrolls.log(test: "test") { puts "inner block" }
at=start
inner block
at=finish elapsed=0.000
=> nil


53
54
55
# File 'lib/scrolls.rb', line 53

def log(data, &blk)
  Log.log(data, &blk)
end

#log_exception(data, e) ⇒ Object

Public: Log an exception

data - A hash of key/values to log e - An exception to pass to the logger

Examples:

begin
  raise Exception
rescue Exception => e
  Scrolls.log_exception({test: "test"}, e)
end
test=test at=exception class=Exception message=Exception exception_id=70321999017240
...


72
73
74
# File 'lib/scrolls.rb', line 72

def log_exception(data, e)
  Log.log_exception(data, e)
end

#streamObject

Public: Return the stream

Examples

Scrolls.stream
=> #<IO:<STDOUT>>


122
123
124
# File 'lib/scrolls.rb', line 122

def stream
  Log.stream
end

#stream=(out) ⇒ Object

Public: Setup a new output (default: STDOUT)

out - New output

Options

syslog - Load 'Scrolls::SyslogLogger'

Examples

Scrolls.stream = StringIO.new


111
112
113
# File 'lib/scrolls.rb', line 111

def stream=(out)
  Log.stream=(out)
end

#time_unitObject

Public: Return the time unit currently configured

Examples

Scrolls.time_unit
=> "seconds"


145
146
147
# File 'lib/scrolls.rb', line 145

def time_unit
  Log.time_unit
end

#time_unit=(unit) ⇒ Object

Public: Set the time unit we use for ‘elapsed’ (default: “seconds”)

unit - The time unit (“milliseconds” currently supported)

Examples

Scrolls.time_unit = "milliseconds"


134
135
136
# File 'lib/scrolls.rb', line 134

def time_unit=(unit)
  Log.time_unit=(unit)
end