Class: NewRelic::Agent::AuditLogger
- Inherits:
-
Object
- Object
- NewRelic::Agent::AuditLogger
- Defined in:
- lib/new_relic/agent/audit_logger.rb
Instance Attribute Summary collapse
-
#enabled ⇒ Object
writeonly
Sets the attribute enabled.
Instance Method Summary collapse
- #enabled? ⇒ Boolean
- #ensure_log_path ⇒ Object
-
#initialize(config) ⇒ AuditLogger
constructor
A new instance of AuditLogger.
- #log_formatter ⇒ Object
- #log_request(uri, data, marshaller) ⇒ Object
- #setup? ⇒ Boolean
- #setup_logger ⇒ Object
Constructor Details
#initialize(config) ⇒ AuditLogger
Returns a new instance of AuditLogger.
7 8 9 10 11 |
# File 'lib/new_relic/agent/audit_logger.rb', line 7 def initialize(config) @config = config @enabled = @config[:'audit_log.enabled'] @encoder = NewRelic::Agent::NewRelicService::Encoders::Identity end |
Instance Attribute Details
#enabled=(value) ⇒ Object (writeonly)
Sets the attribute enabled
13 14 15 |
# File 'lib/new_relic/agent/audit_logger.rb', line 13 def enabled=(value) @enabled = value end |
Instance Method Details
#enabled? ⇒ Boolean
15 16 17 |
# File 'lib/new_relic/agent/audit_logger.rb', line 15 def enabled? @enabled end |
#ensure_log_path ⇒ Object
45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 |
# File 'lib/new_relic/agent/audit_logger.rb', line 45 def ensure_log_path path = File.(@config[:'audit_log.path']) log_dir = File.dirname(path) begin FileUtils.mkdir_p(log_dir) FileUtils.touch(path) rescue SystemCallError => e msg = "Audit log disabled, failed opening log at '#{path}': #{e}" ::NewRelic::Agent.logger.warn(msg) path = nil end path end |
#log_formatter ⇒ Object
61 62 63 64 65 66 67 68 69 |
# File 'lib/new_relic/agent/audit_logger.rb', line 61 def log_formatter if @formatter.nil? @formatter = Logger::Formatter.new def @formatter.call(severity, time, progname, msg) "[#{time} #{Socket.gethostname} (#{$$})] : #{msg}\n" end end @formatter end |
#log_request(uri, data, marshaller) ⇒ Object
23 24 25 26 27 28 29 30 31 32 33 34 35 36 |
# File 'lib/new_relic/agent/audit_logger.rb', line 23 def log_request(uri, data, marshaller) if enabled? setup_logger unless setup? request_body = if marshaller.class.human_readable? marshaller.dump(data, :encoder => @encoder) else marshaller.prepare(data, :encoder => @encoder).inspect end @log.info("REQUEST: #{uri}") @log.info("REQUEST BODY: #{request_body}") end rescue SystemCallError => e ::NewRelic::Agent.logger.warn("Failed writing to audit log: #{e}") end |
#setup? ⇒ Boolean
19 20 21 |
# File 'lib/new_relic/agent/audit_logger.rb', line 19 def setup? !@log.nil? end |