Skip to content

Commit 519dfbb

Browse files
EmyrkSarahFrench
authored andcommitted
fix: Make terraform init JSON log timestamps include millisecond precision (#37818)
* fix: terraform init log timestamps include millisecond precision * docs: add changelog entry
1 parent 27e0fd6 commit 519dfbb

File tree

2 files changed

+19
-15
lines changed

2 files changed

+19
-15
lines changed
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
kind: ENHANCEMENTS
2+
body: terraform init log timestamps include millisecond precision
3+
time: 2025-10-27T13:22:38.714891768-05:00
4+
custom:
5+
Issue: "37818"

internal/command/views/init.go

Lines changed: 14 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,10 @@
44
package views
55

66
import (
7+
"encoding/json"
78
"fmt"
89
"strings"
10+
"time"
911

1012
"github.com/hashicorp/terraform/internal/command/arguments"
1113
"github.com/hashicorp/terraform/internal/tfdiags"
@@ -95,21 +97,18 @@ func (v *InitJSON) Output(messageCode InitMessageCode, params ...any) {
9597
return
9698
}
9799

98-
// Logged data includes by default:
99-
// @level as "info"
100-
// @module as "terraform.ui" (See NewJSONView)
101-
// @timestamp formatted in the default way
102-
//
103-
// In the method below we:
104-
// * Set @message as the first argument value
105-
// * Annotate with extra data:
106-
// "type":"init_output"
107-
// "message_code":"<value>"
108-
v.view.log.Info(
109-
preppedMessage,
110-
"type", "init_output",
111-
"message_code", string(messageCode),
112-
)
100+
current_timestamp := time.Now().UTC().Format(hclog.TimeFormat)
101+
json_data := map[string]string{
102+
"@level": "info",
103+
"@message": preppedMessage,
104+
"@module": "terraform.ui",
105+
"@timestamp": current_timestamp,
106+
"type": "init_output",
107+
"message_code": string(messageCode),
108+
}
109+
110+
init_output, _ := json.Marshal(json_data)
111+
v.view.view.streams.Println(string(init_output))
113112
}
114113

115114
func (v *InitJSON) LogInitMessage(messageCode InitMessageCode, params ...any) {

0 commit comments

Comments
 (0)