Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Major refactor of internal Log module #54

Closed
wants to merge 5 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
67 changes: 33 additions & 34 deletions lib/scrolls.rb
Original file line number Diff line number Diff line change
@@ -1,11 +1,14 @@
require "thread"
require "scrolls/atomic"
require "scrolls/log"
require "scrolls/logger"
require "scrolls/version"

module Scrolls
extend self

def init(options)
@log = Log.new(options)
end

# Public: Set a context in a block for logs
#
# data - A hash of key/values to prepend to each log in a block
Expand All @@ -14,23 +17,13 @@ module Scrolls
# Examples:
#
def context(data, &blk)
Log.with_context(data, &blk)
@log.with_context(data, &blk)
end

# Public: Get or set a global context that prefixs all logs
# Public: Get the global context that prefixs all logs
#
# data - A hash of key/values to prepend to each log
#
def global_context(data=nil)
if data
Log.global_context = data
else
Log.global_context
end
end

def add_global_context(data)
Log.add_global_context(data)
def global_context
@log.global_context
end

# Public: Log data and/or wrap a block with start/finish
Expand All @@ -51,7 +44,7 @@ def add_global_context(data)
# => nil
#
def log(data, &blk)
Log.log(data, &blk)
@log.log(data, &blk)
end

# Public: Log an exception
Expand All @@ -70,7 +63,7 @@ def log(data, &blk)
# ...
#
def log_exception(data, e)
Log.log_exception(data, e)
@log.log_exception(data, e)
end

# Public: Setup a logging facility (default: Syslog::LOG_USER)
Expand All @@ -82,7 +75,7 @@ def log_exception(data, e)
# Scrolls.facility = Syslog::LOG_LOCAL7
#
def facility=(f)
Log.facility=(f)
@log.facility=(f)
end

# Public: Return the Syslog facility
Expand All @@ -93,7 +86,7 @@ def facility=(f)
# => 8
#
def facility
Log.facility
@log.facility
end

# Public: Setup a new output (default: STDOUT)
Expand All @@ -109,7 +102,7 @@ def facility
# Scrolls.stream = StringIO.new
#
def stream=(out)
Log.stream=(out)
@log.stream=(out)
end

# Public: Return the stream
Expand All @@ -120,7 +113,7 @@ def stream=(out)
# => #<IO:<STDOUT>>
#
def stream
Log.stream
@log.stream
end

# Public: Set the time unit we use for 'elapsed' (default: "seconds")
Expand All @@ -132,7 +125,7 @@ def stream
# Scrolls.time_unit = "milliseconds"
#
def time_unit=(unit)
Log.time_unit=(unit)
@log.time_unit = unit
end

# Public: Return the time unit currently configured
Expand All @@ -143,7 +136,7 @@ def time_unit=(unit)
# => "seconds"
#
def time_unit
Log.time_unit
@log.time_unit
end

# Public: Set whether to include a timestamp (now=<ISO8601>) field in the log
Expand All @@ -154,7 +147,7 @@ def time_unit
# Scrolls.add_timestamp = true
#
def add_timestamp=(boolean)
Log.add_timestamp = boolean
@log.timestamp = boolean
end

# Public: Return whether the timestamp field will be included in the log
Expand All @@ -166,7 +159,7 @@ def add_timestamp=(boolean)
# => true
#
def add_timestamp
Log.add_timestamp
@log.add_timestamp
end

# Public: Set whether exceptions should generate a single log
Expand All @@ -177,7 +170,7 @@ def add_timestamp
# Scrolls.single_line_exceptions = true
#
def single_line_exceptions=(boolean)
Log.single_line_exceptions = boolean
@log.exceptions = boolean
end

# Public: Return whether exceptions generate a single log message.
Expand All @@ -188,7 +181,7 @@ def single_line_exceptions=(boolean)
# => true
#
def single_line_exceptions?
Log.single_line_exceptions
@log.single_line_exceptions?
end

# Public: Convience method for Logger replacement
Expand All @@ -204,7 +197,7 @@ def single_line_exceptions?
#
def debug(data, &blk)
data = data.merge(:level => "debug")
Log.log(data, &blk)
@log.log(data, &blk)
end

# Public: Convience method for Logger replacement
Expand All @@ -222,7 +215,7 @@ def debug(data, &blk)
#
def error(data, &blk)
data = data.merge(:level => "warning")
Log.log(data, &blk)
@log.log(data, &blk)
end

# Public: Convience method for Logger replacement
Expand All @@ -240,7 +233,7 @@ def error(data, &blk)
#
def fatal(data, &blk)
data = data.merge(:level => "error")
Log.log(data, &blk)
@log.log(data, &blk)
end

# Public: Convience method for Logger replacement
Expand All @@ -258,7 +251,7 @@ def fatal(data, &blk)
#
def info(data, &blk)
data = data.merge(:level => "info")
Log.log(data, &blk)
@log.log(data, &blk)
end

# Public: Convience method for Logger replacement
Expand All @@ -276,7 +269,7 @@ def info(data, &blk)
#
def warn(data, &blk)
data = data.merge(:level => "notice")
Log.log(data, &blk)
@log.log(data, &blk)
end

# Public: Convience method for Logger replacement
Expand All @@ -294,7 +287,13 @@ def warn(data, &blk)
#
def unknown(data, &blk)
data = data.merge(:level => "alert")
Log.log(data, &blk)
@log.log(data, &blk)
end

# Internal: The Logger initialized by #init
#
def internal
@log
end

end
59 changes: 0 additions & 59 deletions lib/scrolls/atomic.rb

This file was deleted.

Loading