Class: Splash::Logs::LogsRecords
- Inherits:
-
Object
- Object
- Splash::Logs::LogsRecords
- Defined in:
- lib/splash/logs.rb
Constant Summary
Constants included from Constants
Constants::AUTHOR, Constants::BACKENDS_STRUCT, Constants::CONFIG_FILE, Constants::COPYRIGHT, Constants::DAEMON_LOGMON_SCHEDULING, Constants::DAEMON_METRICS_SCHEDULING, Constants::DAEMON_PID_FILE, Constants::DAEMON_PROCESS_NAME, Constants::DAEMON_PROCMON_SCHEDULING, Constants::DAEMON_STDERR_TRACE, Constants::DAEMON_STDOUT_TRACE, Constants::DEFAULT_RETENTION, Constants::EMAIL, Constants::EXECUTION_TEMPLATE, Constants::EXECUTION_TEMPLATE_TOKENS_LIST, Constants::LICENSE, Constants::LOGGERS_STRUCT, Constants::PID_PATH, Constants::PROMETHEUS_ALERTMANAGER_URL, Constants::PROMETHEUS_PUSHGATEWAY_URL, Constants::PROMETHEUS_URL, Constants::TRACE_PATH, Constants::TRANSPORTS_STRUCT, Constants::VERSION, Constants::WEBADMIN_IP, Constants::WEBADMIN_PID_FILE, Constants::WEBADMIN_PID_PATH, Constants::WEBADMIN_PORT, Constants::WEBADMIN_PROCESS_NAME, Constants::WEBADMIN_PROXY, Constants::WEBADMIN_STDERR_TRACE, Constants::WEBADMIN_STDOUT_TRACE
Instance Method Summary collapse
- #add_record(record) ⇒ Object
- #clear ⇒ Object
- #get_all_records(options = {}) ⇒ Object
-
#initialize(name) ⇒ LogsRecords
constructor
A new instance of LogsRecords.
- #purge(retention) ⇒ Object
Methods included from Backends
Methods included from Config
Methods included from ConfigUtilities
#addservice, #checkconfig, #flush_backend, #setupsplash
Methods included from Helpers
#check_unicode_term, #daemonize, #format_by_extensions, #format_response, #get_processes, #group_root, #install_file, #is_root?, #make_folder, #make_link, #run_as_root, #search_file_in_gem, #user_root, #verify_file, #verify_folder, #verify_link, #verify_service
Constructor Details
#initialize(name) ⇒ LogsRecords
Returns a new instance of LogsRecords.
46 47 48 49 |
# File 'lib/splash/logs.rb', line 46 def initialize(name) @name = name @backend = get_backend :logs_trace end |
Instance Method Details
#add_record(record) ⇒ Object
72 73 74 75 76 |
# File 'lib/splash/logs.rb', line 72 def add_record(record) data = get_all_records data.push({ DateTime.now.to_s => record }) @backend.put key: @name, value: data.to_yaml end |
#clear ⇒ Object
51 52 53 |
# File 'lib/splash/logs.rb', line 51 def clear @backend.del({:key => @name}) if @backend.exist?({key: @name}) end |
#get_all_records(options = {}) ⇒ Object
78 79 80 |
# File 'lib/splash/logs.rb', line 78 def get_all_records(={}) return (@backend.exist?({key: @name}))? YAML::load(@backend.get({key: @name})) : [] end |
#purge(retention) ⇒ Object
55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 |
# File 'lib/splash/logs.rb', line 55 def purge(retention) retention = {} if retention.nil? if retention.include? :hours then adjusted_datetime = DateTime.now - retention[:hours].to_f / 24 elsif retention.include? :hours then adjusted_datetime = DateTime.now - retention[:days].to_i else adjusted_datetime = DateTime.now - DEFAULT_RETENTION end data = get_all_records data.delete_if { |item| DateTime.parse(item.keys.first) <= (adjusted_datetime)} @backend.put key: @name, value: data.to_yaml end |