Class: Log

Inherits:
Object
  • Object
show all
Defined in:
common/log.rb

Overview

This is a class used for logging in sinatra applications ( backend, indexer ). Rails provides its own logging functionality, so its not needed in the Frontend or PUI

Constant Summary collapse

@@logger =

By default start with STDERR, but allow people to change it.

ASpaceLogger.new($stderr)

Class Method Summary collapse

Class Method Details

.backlogObject

this gets the backlog and starts the recording timer



42
43
44
# File 'common/log.rb', line 42

def self.backlog
  @@logger.backlog_and_flush
end

.debug(s) ⇒ Object



33
# File 'common/log.rb', line 33

def self.debug(s) @@logger.debug(prepare(s)) end

.error(s) ⇒ Object



39
# File 'common/log.rb', line 39

def self.error(s) @@logger.error(prepare(s)) end

.exception(e) ⇒ Object



23
24
25
26
# File 'common/log.rb', line 23

def self.exception(e)
  backtrace = e.backtrace.join("\n")
  @@logger.error("\n#{e}\n#{backtrace}")
end

.filter_passwords(params) ⇒ Object



46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
# File 'common/log.rb', line 46

def self.filter_passwords(params)
  if params.is_a? String
    params.gsub(/password=(.*?)(&|$)/, "password=[FILTERED]")
  else
    params = params.clone

    ["password", :password].each do |param|
      if params[param]
        params[param] = "[FILTERED]"
      end
    end

    params
  end
end

.info(s) ⇒ Object



35
# File 'common/log.rb', line 35

def self.info(s) @@logger.info(prepare(s)) end

.logger(log) ⇒ Object



11
12
13
# File 'common/log.rb', line 11

def self.logger(log)
  @@logger = ASpaceLogger.new(log)
end

.noisiness(log_level) ⇒ Object



15
16
17
# File 'common/log.rb', line 15

def self.noisiness(log_level)
  @@logger.sev_threshold = log_level
end

.prepare(s) ⇒ Object



28
29
30
31
# File 'common/log.rb', line 28

def self.prepare(s)
  my_id = "Thread-#{Thread.current.object_id}"
  "#{my_id}: #{s}"
end

.quiet_pleaseObject



19
20
21
# File 'common/log.rb', line 19

def self.quiet_please
  @@logger.sev_threshold = Logger::FATAL
end

.warn(s) ⇒ Object



37
# File 'common/log.rb', line 37

def self.warn(s) @@logger.warn(prepare(s)) end