refactor: Make the JSON view for `init` commands use defaults from the hclog package (#37840)

* refactor: Change `(v *InitJSON) Output` to use logic from the hclog package to take advantage of default settings

* docs: Add code comments
pull/37936/head
Sarah French 3 months ago committed by GitHub
parent 3df28c3101
commit 1a547775ff
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

@ -4,12 +4,9 @@
package views
import (
"encoding/json"
"fmt"
"strings"
"time"
"github.com/hashicorp/go-hclog"
"github.com/hashicorp/terraform/internal/command/arguments"
"github.com/hashicorp/terraform/internal/tfdiags"
)
@ -98,18 +95,21 @@ func (v *InitJSON) Output(messageCode InitMessageCode, params ...any) {
return
}
current_timestamp := time.Now().UTC().Format(hclog.TimeFormat)
json_data := map[string]string{
"@level": "info",
"@message": preppedMessage,
"@module": "terraform.ui",
"@timestamp": current_timestamp,
"type": "init_output",
"message_code": string(messageCode),
}
init_output, _ := json.Marshal(json_data)
v.view.view.streams.Println(string(init_output))
// Logged data includes by default:
// @level as "info"
// @module as "terraform.ui" (See NewJSONView)
// @timestamp formatted in the default way
//
// In the method below we:
// * Set @message as the first argument value
// * Annotate with extra data:
// "type":"init_output"
// "message_code":"<value>"
v.view.log.Info(
preppedMessage,
"type", "init_output",
"message_code", string(messageCode),
)
}
func (v *InitJSON) LogInitMessage(messageCode InitMessageCode, params ...any) {

Loading…
Cancel
Save