Class: Terraspace::Logger
- Inherits:
-
Logger
- Object
- Logger
- Terraspace::Logger
- Defined in:
- lib/terraspace/logger.rb,
lib/terraspace/logger/formatter.rb
Defined Under Namespace
Classes: Formatter
Constant Summary collapse
- @@stdin_capture =
''
- @@buffer =
[]
Class Method Summary collapse
- .buffer ⇒ Object
-
.clear ⇒ Object
for test framework.
- .logs ⇒ Object
- .stdin_capture ⇒ Object
Instance Method Summary collapse
- #format_message(severity, datetime, progname, msg) ⇒ Object
-
#initialize(*args) ⇒ Logger
constructor
A new instance of Logger.
- #stdin_capture(text) ⇒ Object
-
#stdout(msg, newline: true) ⇒ Object
Used to allow terraform output to always go to stdout Terraspace output goes to stderr by default See: terraspace/shell.rb.
Constructor Details
Class Method Details
.buffer ⇒ Object
43 44 45 |
# File 'lib/terraspace/logger.rb', line 43 def buffer @@buffer end |
.clear ⇒ Object
for test framework
53 54 55 56 |
# File 'lib/terraspace/logger.rb', line 53 def clear Terraspace::Command.reset_dispatch_command @@buffer = [] end |
.logs ⇒ Object
47 48 49 50 |
# File 'lib/terraspace/logger.rb', line 47 def logs # force_encoding https://jch.github.io/posts/2013-03-05-ruby-incompatible-encoding.html @@buffer.map { |s| s.force_encoding('UTF-8') }.join('') end |
.stdin_capture ⇒ Object
38 39 40 |
# File 'lib/terraspace/logger.rb', line 38 def stdin_capture @@stdin_capture end |
Instance Method Details
#format_message(severity, datetime, progname, msg) ⇒ Object
11 12 13 14 15 16 17 18 19 20 |
# File 'lib/terraspace/logger.rb', line 11 def (severity, datetime, progname, msg) line = if @logdev.dev == $stdout || @logdev.dev == $stderr msg # super simple format if stdout else super # use the configured formatter end out = line.force_encoding('UTF-8') =~ /\n$/ ? line : "#{line}\n" @@buffer << out out end |
#stdin_capture(text) ⇒ Object
31 32 33 34 |
# File 'lib/terraspace/logger.rb', line 31 def stdin_capture(text) @@buffer << "#{text}\n" @@stdin_capture = text end |
#stdout(msg, newline: true) ⇒ Object
Used to allow terraform output to always go to stdout Terraspace output goes to stderr by default See: terraspace/shell.rb
25 26 27 28 29 |
# File 'lib/terraspace/logger.rb', line 25 def stdout(msg, newline: true) out = newline ? "#{msg}\n" : msg @@buffer << out print out end |