Module: Autostager::Logger

Included in:
Autostager, CLI, PullRequest
Defined in:
lib/autostager/logger.rb

Overview

Interface to Posix syslog.

Class Method Summary collapse

Class Method Details

.log(msg, level = :info) ⇒ Object

Log a message to syslog at a specified priority level

priority level must be one of:

  • :crit

  • :emerg emergency

  • :alert

  • :err

  • :warning

  • :notice

  • :info (default if level is not specified)

  • :debug

Parameters:

  • msg (String)

    the message you want to send to syslog

  • level (Symbol) (defaults to: :info)

    the priority of the message



23
24
25
26
27
28
29
# File 'lib/autostager/logger.rb', line 23

def log(msg, level = :info)
  msg = safe(msg)
  warn "#{Time.now} #{msg}" if ENV.key?('debug')
  Syslog.open($PROGRAM_NAME, Syslog::LOG_PID | Syslog::LOG_CONS) do |s|
    s.send(level, '%s', msg)
  end
end

.safe(str) ⇒ String

Make a string safe for syslog.

Parameters:

  • A (String)

    string that could be unsafe.

Returns:

  • (String)

    A safe copy of the original string.

See Also:



37
38
39
# File 'lib/autostager/logger.rb', line 37

def safe(str)
  CGI.unescape(str)
end