Class: RightScale::AuditLogger
- Defined in:
- lib/instance/cook/audit_logger.rb
Overview
Provides logger interface but forwards some logging to audit entry. Used in combination with Chef to audit recipe execution output.
Instance Attribute Summary collapse
-
#audit_id ⇒ Object
readonly
Underlying audit id.
Instance Method Summary collapse
-
#<<(msg) ⇒ Object
Raw output.
-
#add(severity, message = nil, progname = nil, &block) ⇒ Object
Override Logger::add to audit instead of writing to log file.
-
#create_new_section(title, options = {}) ⇒ Object
Start new audit section Note: This is a special ‘log’ method which allows us to create audit sections before running RightScripts.
-
#initialize ⇒ AuditLogger
constructor
Initialize audit logger, override Logger initialize since there is no need to initialize @logdev.
- #level ⇒ Object
-
#level_orig ⇒ Object
Return level as a symbol.
Constructor Details
#initialize ⇒ AuditLogger
Initialize audit logger, override Logger initialize since there is no need to initialize @logdev
Parameters
- audit_id(Integer)
-
Audit id used to audit logs
48 49 50 51 52 53 54 |
# File 'lib/instance/cook/audit_logger.rb', line 48 def initialize @progname = nil @level = INFO @default_formatter = AuditLogFormatter.new @formatter = nil @logdev = nil end |
Instance Attribute Details
#audit_id ⇒ Object (readonly)
Underlying audit id
42 43 44 |
# File 'lib/instance/cook/audit_logger.rb', line 42 def audit_id @audit_id end |
Instance Method Details
#<<(msg) ⇒ Object
Raw output
Parameters
- msg(String)
-
Raw string to be appended to audit
73 74 75 |
# File 'lib/instance/cook/audit_logger.rb', line 73 def <<(msg) AuditStub.instance.append_output(msg) end |
#add(severity, message = nil, progname = nil, &block) ⇒ Object
Override Logger::add to audit instead of writing to log file
Parameters
- severity(Constant)
-
One of Logger::DEBUG, Logger::INFO, Logger::WARN, Logger::ERROR or Logger::FATAL
- message(String)
-
Message to be audited
- progname(String)
-
Override default program name for that audit
Block
Call given Block if any to build message if message
is nil
Return
- true
-
Always return true
89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 |
# File 'lib/instance/cook/audit_logger.rb', line 89 def add(severity, =nil, progname=nil, &block) severity ||= UNKNOWN # We don't want to audit logs that are less than our level return true if severity < @level progname ||= @progname if .nil? if block_given? = yield else = progname progname = @progname end end return true if is_filtered?(severity, ) msg = (format_severity(severity), Time.now, progname, ) case severity when Logger::DEBUG Log.debug() when Logger::INFO, Logger::WARN, Logger::UNKNOWN AuditStub.instance.append_output(msg) when Logger::ERROR AuditStub.instance.append_error(msg) when Logger::FATAL AuditStub.instance.append_error(msg, :category => RightScale::EventCategories::CATEGORY_ERROR) end true end |
#create_new_section(title, options = {}) ⇒ Object
Start new audit section Note: This is a special ‘log’ method which allows us to create audit sections before running RightScripts
Parameters
- title(String)
-
Title of new audit section, will replace audit status as well
- options(String)
-
Optional, must be one of RightScale::EventCategories::CATEGORIES
Return
- true
-
Always return true
127 128 129 |
# File 'lib/instance/cook/audit_logger.rb', line 127 def create_new_section(title, ={}) AuditStub.instance.create_new_section(title, ) end |
#level ⇒ Object
61 62 63 64 65 66 67 |
# File 'lib/instance/cook/audit_logger.rb', line 61 def level level = { Logger::DEBUG => :debug, Logger::INFO => :info, Logger::WARN => :warn, Logger::ERROR => :error, Logger::FATAL => :fatal }[level_orig] end |
#level_orig ⇒ Object
Return level as a symbol
Return
- level(Symbol)
-
One of :debug, :info, :warn, :error or :fatal
60 |
# File 'lib/instance/cook/audit_logger.rb', line 60 alias :level_orig :level |