Sha256: 454a4b7d95d070854bdc3476d4723db98e4ae61a99b6e81159d05d69cb6dac7f
Contents?: true
Size: 1 KB
Versions: 1
Compression:
Stored size: 1 KB
Contents
module Logster class Message attr_accessor :timestamp, :severity, :progname, :message, :key, :backtrace def initialize(severity, progname, message, timestamp = nil, key = nil) @timestamp = timestamp || get_timestamp @severity = severity @progname = progname @message = message @key = key || SecureRandom.hex @backtrace = nil end def to_h { message: @message, progname: @progname, severity: @severity, timestamp: @timestamp, key: @key, backtrace: @backtrace } end def to_json(opts=nil) JSON.fast_generate(to_h,opts) end def self.from_json(json) parsed = ::JSON.parse(json) msg = new( parsed["severity"], parsed["progname"], parsed["message"], parsed["timestamp"], parsed["key"] ) msg.backtrace = parsed["backtrace"] msg end protected def get_timestamp (Time.new.to_f * 1000).to_i end end end
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
logster-0.0.4 | lib/logster/message.rb |