class Console::Serialized::Logger

Attributes

format[R]
io[R]
start[R]

Public Class Methods

new(io = $stderr, format: JSON, verbose: false, **options) click to toggle source
# File lib/console/serialized/logger.rb, line 30
def initialize(io = $stderr, format: JSON, verbose: false, **options)
        @io = io
        @start = Time.now
        @format = format
        @verbose = verbose
end

Public Instance Methods

call(subject = nil, *arguments, severity: UNKNOWN, **options) { || ... } click to toggle source
# File lib/console/serialized/logger.rb, line 49
def call(subject = nil, *arguments, severity: UNKNOWN, **options, &block)
        record = {
                time: Time.now.iso8601,
                severity: severity,
                class: subject.class,
                oid: subject.object_id,
                pid: Process.pid,
        }
        
        if subject
                record[:subject] = subject
        end
        
        if arguments.any?
                record[:arguments] = arguments
        end
        
        if options.any?
                record[:options] = options
        end
        
        if block_given?
                if block.arity.zero?
                        record[:message] = yield
                else
                        buffer = StringIO.new
                        yield buffer
                        record[:message] = buffer.string
                end
        end
        
        @io.puts(self.dump(record))
end
dump(record) click to toggle source
# File lib/console/serialized/logger.rb, line 45
def dump(record)
        @format.dump(record)
end
verbose!(value = true) click to toggle source
# File lib/console/serialized/logger.rb, line 41
def verbose!(value = true)
        @verbose = true
end