Module: CWLLogger

Defined in:
lib/cwllogger.rb,
lib/cwllogger/version.rb,
lib/cwllogger/middleware.rb

Defined Under Namespace

Classes: Middleware

Constant Summary collapse

VERSION =
"0.1.0"

Class Method Summary collapse

Class Method Details

.app_nameObject

Returns the app name. Defaults to the value in ENV



12
13
14
# File 'lib/cwllogger.rb', line 12

def self.app_name
  @app_name || ENV["APP"] || "unset"
end

.app_name=(value) ⇒ Object

Sets the app name



7
8
9
# File 'lib/cwllogger.rb', line 7

def self.app_name=(value)
  @app_name = value
end

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

Writes a new log message. Takes args, a hash of keys and values that should be written



18
19
20
21
22
23
24
25
# File 'lib/cwllogger.rb', line 18

def self.log(event, args = {})
  data = {}
  data["app"] = app_name
  data["time"] = Time.now.utc.strftime("%FT%T")
  data["event"] = event

  puts JSON.dump(data.merge(args))
end