Class: Mildred::Logger
- Inherits:
-
Object
- Object
- Mildred::Logger
- Defined in:
- lib/mildred/logger.rb
Constant Summary collapse
- LOG_DIR =
File.join(Dir.home, ".mildred")
- LOG_PATH =
File.join(LOG_DIR, "mildred.log")
Instance Attribute Summary collapse
-
#entries ⇒ Object
readonly
Returns the value of attribute entries.
Instance Method Summary collapse
- #clear ⇒ Object
-
#initialize ⇒ Logger
constructor
A new instance of Logger.
- #log(command, stdout, stderr, exit_code) ⇒ Object
- #log_job_end(job_name, success:, error: nil) ⇒ Object
- #log_job_start(job_name) ⇒ Object
Constructor Details
#initialize ⇒ Logger
Returns a new instance of Logger.
12 13 14 |
# File 'lib/mildred/logger.rb', line 12 def initialize @entries = [] end |
Instance Attribute Details
#entries ⇒ Object (readonly)
Returns the value of attribute entries.
10 11 12 |
# File 'lib/mildred/logger.rb', line 10 def entries @entries end |
Instance Method Details
#clear ⇒ Object
41 42 43 |
# File 'lib/mildred/logger.rb', line 41 def clear @entries = [] end |
#log(command, stdout, stderr, exit_code) ⇒ Object
16 17 18 19 20 21 22 23 24 25 26 27 28 |
# File 'lib/mildred/logger.rb', line 16 def log(command, stdout, stderr, exit_code) @entries << { command: command, stdout: stdout, stderr: stderr, exit_code: exit_code } fields = { event: "exec", command: command, exit_code: exit_code } fields[:stdout] = truncate(stdout) unless stdout.empty? fields[:stderr] = truncate(stderr) unless stderr.empty? write(**fields) end |
#log_job_end(job_name, success:, error: nil) ⇒ Object
34 35 36 37 38 39 |
# File 'lib/mildred/logger.rb', line 34 def log_job_end(job_name, success:, error: nil) status = success ? "success" : "error" fields = { event: "completed", job: job_name, status: status } fields[:error] = error if error write(**fields) end |
#log_job_start(job_name) ⇒ Object
30 31 32 |
# File 'lib/mildred/logger.rb', line 30 def log_job_start(job_name) write(event: "started", job: job_name) end |