Skip to content

Commit

Permalink
Update Atmos logs. Update docs (#605)
Browse files Browse the repository at this point in the history
* updates

* updates

* updates

* updates

* updates

* updates

* Update website/docs/cli/configuration.mdx

Co-authored-by: Erik Osterman (CEO @ Cloud Posse) <[email protected]>

* Update website/docs/cli/configuration.mdx

Co-authored-by: Erik Osterman (CEO @ Cloud Posse) <[email protected]>

* updates

* updates

* updates

---------

Co-authored-by: Erik Osterman (CEO @ Cloud Posse) <[email protected]>
  • Loading branch information
aknysh and osterman authored May 23, 2024
1 parent f7aa382 commit df1c9bb
Show file tree
Hide file tree
Showing 31 changed files with 292 additions and 51 deletions.
2 changes: 1 addition & 1 deletion .github/settings.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,5 @@ _extends: .github
repository:
name: atmos
description: 👽 Terraform Orchestration Tool for DevOps. Keep environment configuration DRY with hierarchical imports of configurations, inheritance, and WAY more. Native support for Terraform and Helmfile.
homepage: https://cloudposse.com/accelerate
homepage: https://atmos.tools
topics: ""
4 changes: 3 additions & 1 deletion atmos.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,9 @@ workflows:

logs:
# Can also be set using 'ATMOS_LOGS_FILE' ENV var, or '--logs-file' command-line argument
file: "/dev/stdout"
# File or standard file descriptor to write logs to
# Logs can be written to any file or any standard file descriptor, including `/dev/stdout`, `/dev/stderr` and `/dev/null`
file: "/dev/stderr"
# Supported log levels: Trace, Debug, Info, Warning, Off
# Can also be set using 'ATMOS_LOGS_LEVEL' ENV var, or '--logs-level' command-line argument
level: Info
Expand Down
2 changes: 1 addition & 1 deletion examples/quick-start/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ ARG GEODESIC_OS=debian
# https://atmos.tools/
# https://github.com/cloudposse/atmos
# https://github.com/cloudposse/atmos/releases
ARG ATMOS_VERSION=1.73.0
ARG ATMOS_VERSION=1.74.0

# Terraform: https://github.com/hashicorp/terraform/releases
ARG TF_VERSION=1.8.1
Expand Down
4 changes: 3 additions & 1 deletion examples/quick-start/atmos.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,9 @@ workflows:

logs:
# Can also be set using 'ATMOS_LOGS_FILE' ENV var, or '--logs-file' command-line argument
file: "/dev/stdout"
# File or standard file descriptor to write logs to
# Logs can be written to any file or any standard file descriptor, including `/dev/stdout`, `/dev/stderr` and `/dev/null`
file: "/dev/stderr"
# Supported log levels: Trace, Debug, Info, Warning, Off
# Can also be set using 'ATMOS_LOGS_LEVEL' ENV var, or '--logs-level' command-line argument
level: Info
Expand Down
6 changes: 5 additions & 1 deletion examples/quick-start/rootfs/usr/local/etc/atmos/atmos.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -73,8 +73,12 @@ workflows:
base_path: "stacks/workflows"

logs:
file: "/dev/stdout"
# Can also be set using 'ATMOS_LOGS_FILE' ENV var, or '--logs-file' command-line argument
# File or standard file descriptor to write logs to
# Logs can be written to any file or any standard file descriptor, including `/dev/stdout`, `/dev/stderr` and `/dev/null`
file: "/dev/stderr"
# Supported log levels: Trace, Debug, Info, Warning, Off
# Can also be set using 'ATMOS_LOGS_LEVEL' ENV var, or '--logs-level' command-line argument
level: Info

# Custom CLI commands
Expand Down
4 changes: 3 additions & 1 deletion examples/tests/atmos.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,9 @@ workflows:

logs:
# Can also be set using 'ATMOS_LOGS_FILE' ENV var, or '--logs-file' command-line argument
file: "/dev/stdout"
# File or standard file descriptor to write logs to
# Logs can be written to any file or any standard file descriptor, including `/dev/stdout`, `/dev/stderr` and `/dev/null`
file: "/dev/stderr"
# Supported log levels: Trace, Debug, Info, Warning, Off
# Can also be set using 'ATMOS_LOGS_LEVEL' ENV var, or '--logs-level' command-line argument
level: Info
Expand Down
6 changes: 5 additions & 1 deletion examples/tests/rootfs/usr/local/etc/atmos/atmos.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -75,8 +75,12 @@ workflows:
base_path: "stacks/workflows"

logs:
file: "/dev/stdout"
# Can also be set using 'ATMOS_LOGS_FILE' ENV var, or '--logs-file' command-line argument
# File or standard file descriptor to write logs to
# Logs can be written to any file or any standard file descriptor, including `/dev/stdout`, `/dev/stderr` and `/dev/null`
file: "/dev/stderr"
# Supported log levels: Trace, Debug, Info, Warning, Off
# Can also be set using 'ATMOS_LOGS_LEVEL' ENV var, or '--logs-level' command-line argument
level: Info

# Custom CLI commands
Expand Down
2 changes: 0 additions & 2 deletions internal/exec/describe_affected_utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -514,8 +514,6 @@ func executeDescribeAffected(
return nil, err
}

u.LogTrace(cliConfig, "\nAffected components and stacks:\n")

return affected, nil
}

Expand Down
2 changes: 1 addition & 1 deletion internal/exec/helmfile.go
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ func ExecuteHelmfile(info schema.ConfigAndStacksInfo) error {
u.LogDebug(cliConfig, fmt.Sprintf("\nVariables for the component '%s' in the stack '%s':", info.ComponentFromArg, info.Stack))

if cliConfig.Logs.Level == u.LogLevelTrace || cliConfig.Logs.Level == u.LogLevelDebug {
err = u.PrintAsYAML(info.ComponentVarsSection)
err = u.PrintAsYAMLToFileDescriptor(cliConfig, info.ComponentVarsSection)
if err != nil {
return err
}
Expand Down
2 changes: 1 addition & 1 deletion internal/exec/helmfile_generate_varfile.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ func ExecuteHelmfileGenerateVarfileCmd(cmd *cobra.Command, args []string) error
u.LogDebug(cliConfig, fmt.Sprintf("\nVariables for the component '%s' in the stack '%s':", info.ComponentFromArg, info.Stack))

if cliConfig.Logs.Level == u.LogLevelTrace || cliConfig.Logs.Level == u.LogLevelDebug {
err = u.PrintAsYAML(info.ComponentVarsSection)
err = u.PrintAsYAMLToFileDescriptor(cliConfig, info.ComponentVarsSection)
if err != nil {
return err
}
Expand Down
2 changes: 1 addition & 1 deletion internal/exec/terraform.go
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ func ExecuteTerraform(info schema.ConfigAndStacksInfo) error {
u.LogDebug(cliConfig, fmt.Sprintf("\nVariables for the component '%s' in the stack '%s':", info.ComponentFromArg, info.Stack))

if cliConfig.Logs.Level == u.LogLevelTrace || cliConfig.Logs.Level == u.LogLevelDebug {
err = u.PrintAsYAML(info.ComponentVarsSection)
err = u.PrintAsYAMLToFileDescriptor(cliConfig, info.ComponentVarsSection)
if err != nil {
return err
}
Expand Down
2 changes: 1 addition & 1 deletion internal/exec/terraform_generate_backend.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ func ExecuteTerraformGenerateBackendCmd(cmd *cobra.Command, args []string) error
u.LogDebug(cliConfig, "Component backend config:\n\n")

if cliConfig.Logs.Level == u.LogLevelTrace || cliConfig.Logs.Level == u.LogLevelDebug {
err = u.PrintAsJSON(componentBackendConfig)
err = u.PrintAsJSONToFileDescriptor(cliConfig, componentBackendConfig)
if err != nil {
return err
}
Expand Down
2 changes: 1 addition & 1 deletion internal/exec/terraform_generate_varfile.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ func ExecuteTerraformGenerateVarfileCmd(cmd *cobra.Command, args []string) error
u.LogDebug(cliConfig, fmt.Sprintf("\nVariables for the component '%s' in the stack '%s':", info.ComponentFromArg, info.Stack))

if cliConfig.Logs.Level == u.LogLevelTrace || cliConfig.Logs.Level == u.LogLevelDebug {
err = u.PrintAsYAML(info.ComponentVarsSection)
err = u.PrintAsYAMLToFileDescriptor(cliConfig, info.ComponentVarsSection)
if err != nil {
return err
}
Expand Down
2 changes: 1 addition & 1 deletion internal/exec/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -296,7 +296,7 @@ func ProcessStacks(
msg = "\nFound stack manifests:"
}
u.LogTrace(cliConfig, msg)
err = u.PrintAsYAML(cliConfig.StackConfigFilesRelativePaths)
err = u.PrintAsYAMLToFileDescriptor(cliConfig, cliConfig.StackConfigFilesRelativePaths)
if err != nil {
return configAndStacksInfo, err
}
Expand Down
2 changes: 1 addition & 1 deletion internal/exec/worflow_utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ func ExecuteWorkflow(
logFunc(cliConfig, fmt.Sprintf("\nExecuting the workflow '%s' from '%s'\n", workflow, workflowPath))

if cliConfig.Logs.Level == u.LogLevelTrace || cliConfig.Logs.Level == u.LogLevelDebug {
err := u.PrintAsYAML(workflowDefinition)
err := u.PrintAsYAMLToFileDescriptor(cliConfig, workflowDefinition)
if err != nil {
return err
}
Expand Down
6 changes: 5 additions & 1 deletion pkg/atlantis/atmos.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -63,8 +63,12 @@ workflows:
base_path: "stacks/workflows"

logs:
file: "/dev/stdout"
# Can also be set using 'ATMOS_LOGS_FILE' ENV var, or '--logs-file' command-line argument
# File or standard file descriptor to write logs to
# Logs can be written to any file or any standard file descriptor, including `/dev/stdout`, `/dev/stderr` and `/dev/null`
file: "/dev/stderr"
# Supported log levels: Trace, Debug, Info, Warning, Off
# Can also be set using 'ATMOS_LOGS_LEVEL' ENV var, or '--logs-level' command-line argument
level: Info

# Custom CLI commands
Expand Down
6 changes: 5 additions & 1 deletion pkg/aws/atmos.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -63,8 +63,12 @@ workflows:
base_path: "stacks/workflows"

logs:
file: "/dev/stdout"
# Can also be set using 'ATMOS_LOGS_FILE' ENV var, or '--logs-file' command-line argument
# File or standard file descriptor to write logs to
# Logs can be written to any file or any standard file descriptor, including `/dev/stdout`, `/dev/stderr` and `/dev/null`
file: "/dev/stderr"
# Supported log levels: Trace, Debug, Info, Warning, Off
# Can also be set using 'ATMOS_LOGS_LEVEL' ENV var, or '--logs-level' command-line argument
level: Info

# Custom CLI commands
Expand Down
6 changes: 5 additions & 1 deletion pkg/component/atmos.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -63,8 +63,12 @@ workflows:
base_path: "stacks/workflows"

logs:
file: "/dev/stdout"
# Can also be set using 'ATMOS_LOGS_FILE' ENV var, or '--logs-file' command-line argument
# File or standard file descriptor to write logs to
# Logs can be written to any file or any standard file descriptor, including `/dev/stdout`, `/dev/stderr` and `/dev/null`
file: "/dev/stderr"
# Supported log levels: Trace, Debug, Info, Warning, Off
# Can also be set using 'ATMOS_LOGS_LEVEL' ENV var, or '--logs-level' command-line argument
level: Info

# Custom CLI commands
Expand Down
4 changes: 2 additions & 2 deletions pkg/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -194,12 +194,12 @@ func InitCliConfig(configAndStacksInfo schema.ConfigAndStacksInfo, processStacks
// If `atmos.yaml` not found, use the default config
// Set `ATMOS_LOGS_LEVEL` ENV var to "Debug" to see the message about Atmos using the default CLI config
logsLevelEnvVar := os.Getenv("ATMOS_LOGS_LEVEL")
if logsLevelEnvVar == "Debug" {
if logsLevelEnvVar == u.LogLevelDebug || logsLevelEnvVar == u.LogLevelTrace {
u.PrintMessageInColor("'atmos.yaml' CLI config was not found in any of the searched paths: system dir, home dir, current dir, ENV vars.\n"+
"Refer to https://atmos.tools/cli/configuration for details on how to configure 'atmos.yaml'.\n"+
"Using the default CLI config:\n\n", color.New(color.FgCyan))

err = u.PrintAsYAML(defaultCliConfig)
err = u.PrintAsYAMLToFileDescriptor(cliConfig, defaultCliConfig)
if err != nil {
return cliConfig, err
}
Expand Down
6 changes: 5 additions & 1 deletion pkg/describe/atmos.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -63,8 +63,12 @@ workflows:
base_path: "stacks/workflows"

logs:
file: "/dev/stdout"
# Can also be set using 'ATMOS_LOGS_FILE' ENV var, or '--logs-file' command-line argument
# File or standard file descriptor to write logs to
# Logs can be written to any file or any standard file descriptor, including `/dev/stdout`, `/dev/stderr` and `/dev/null`
file: "/dev/stderr"
# Supported log levels: Trace, Debug, Info, Warning, Off
# Can also be set using 'ATMOS_LOGS_LEVEL' ENV var, or '--logs-level' command-line argument
level: Info

# Custom CLI commands
Expand Down
6 changes: 5 additions & 1 deletion pkg/generate/atmos.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -63,8 +63,12 @@ workflows:
base_path: "stacks/workflows"

logs:
file: "/dev/stdout"
# Can also be set using 'ATMOS_LOGS_FILE' ENV var, or '--logs-file' command-line argument
# File or standard file descriptor to write logs to
# Logs can be written to any file or any standard file descriptor, including `/dev/stdout`, `/dev/stderr` and `/dev/null`
file: "/dev/stderr"
# Supported log levels: Trace, Debug, Info, Warning, Off
# Can also be set using 'ATMOS_LOGS_LEVEL' ENV var, or '--logs-level' command-line argument
level: Info

# Custom CLI commands
Expand Down
6 changes: 5 additions & 1 deletion pkg/spacelift/atmos.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -63,8 +63,12 @@ workflows:
base_path: "stacks/workflows"

logs:
file: "/dev/stdout"
# Can also be set using 'ATMOS_LOGS_FILE' ENV var, or '--logs-file' command-line argument
# File or standard file descriptor to write logs to
# Logs can be written to any file or any standard file descriptor, including `/dev/stdout`, `/dev/stderr` and `/dev/null`
file: "/dev/stderr"
# Supported log levels: Trace, Debug, Info, Warning, Off
# Can also be set using 'ATMOS_LOGS_LEVEL' ENV var, or '--logs-level' command-line argument
level: Info

# Custom CLI commands
Expand Down
15 changes: 13 additions & 2 deletions pkg/utils/json_utils.go
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
package utils

import (
"github.com/cloudposse/atmos/pkg/schema"
"os"
"strings"

jsoniter "github.com/json-iterator/go"
)

// PrintAsJSON prints the provided value as YAML document to the console
// PrintAsJSON prints the provided value as JSON document to the console
func PrintAsJSON(data any) error {
j, err := ConvertToJSON(data)
if err != nil {
Expand All @@ -17,7 +18,17 @@ func PrintAsJSON(data any) error {
return nil
}

// WriteToFileAsJSON converts the provided value to YAML and writes it to the specified file
// PrintAsJSONToFileDescriptor prints the provided value as JSON document to a file descriptor
func PrintAsJSONToFileDescriptor(cliConfig schema.CliConfiguration, data any) error {
j, err := ConvertToJSON(data)
if err != nil {
return err
}
LogInfo(cliConfig, j)
return nil
}

// WriteToFileAsJSON converts the provided value to JSON and writes it to the specified file
func WriteToFileAsJSON(filePath string, data any, fileMode os.FileMode) error {
j, err := ConvertToJSON(data)
if err != nil {
Expand Down
12 changes: 12 additions & 0 deletions pkg/utils/yaml_utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ import (
"os"

"gopkg.in/yaml.v2"

"github.com/cloudposse/atmos/pkg/schema"
)

// PrintAsYAML prints the provided value as YAML document to the console
Expand All @@ -16,6 +18,16 @@ func PrintAsYAML(data any) error {
return nil
}

// PrintAsYAMLToFileDescriptor prints the provided value as YAML document to a file descriptor
func PrintAsYAMLToFileDescriptor(cliConfig schema.CliConfiguration, data any) error {
y, err := ConvertToYAML(data)
if err != nil {
return err
}
LogInfo(cliConfig, y)
return nil
}

// WriteToFileAsYAML converts the provided value to YAML and writes it to the specified file
func WriteToFileAsYAML(filePath string, data any, fileMode os.FileMode) error {
y, err := ConvertToYAML(data)
Expand Down
6 changes: 5 additions & 1 deletion pkg/validate/atmos.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -63,8 +63,12 @@ workflows:
base_path: "stacks/workflows"

logs:
file: "/dev/stdout"
# Can also be set using 'ATMOS_LOGS_FILE' ENV var, or '--logs-file' command-line argument
# File or standard file descriptor to write logs to
# Logs can be written to any file or any standard file descriptor, including `/dev/stdout`, `/dev/stderr` and `/dev/null`
file: "/dev/stderr"
# Supported log levels: Trace, Debug, Info, Warning, Off
# Can also be set using 'ATMOS_LOGS_LEVEL' ENV var, or '--logs-level' command-line argument
level: Info

# Custom CLI commands
Expand Down
6 changes: 5 additions & 1 deletion pkg/vender/atmos.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -63,8 +63,12 @@ workflows:
base_path: "stacks/workflows"

logs:
file: "/dev/stdout"
# Can also be set using 'ATMOS_LOGS_FILE' ENV var, or '--logs-file' command-line argument
# File or standard file descriptor to write logs to
# Logs can be written to any file or any standard file descriptor, including `/dev/stdout`, `/dev/stderr` and `/dev/null`
file: "/dev/stderr"
# Supported log levels: Trace, Debug, Info, Warning, Off
# Can also be set using 'ATMOS_LOGS_LEVEL' ENV var, or '--logs-level' command-line argument
level: Info

# Custom CLI commands
Expand Down
6 changes: 5 additions & 1 deletion pkg/workflow/atmos.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -63,8 +63,12 @@ workflows:
base_path: "stacks/workflows"

logs:
file: "/dev/stdout"
# Can also be set using 'ATMOS_LOGS_FILE' ENV var, or '--logs-file' command-line argument
# File or standard file descriptor to write logs to
# Logs can be written to any file or any standard file descriptor, including `/dev/stdout`, `/dev/stderr` and `/dev/null`
file: "/dev/stderr"
# Supported log levels: Trace, Debug, Info, Warning, Off
# Can also be set using 'ATMOS_LOGS_LEVEL' ENV var, or '--logs-level' command-line argument
level: Info

# Custom CLI commands
Expand Down
Loading

0 comments on commit df1c9bb

Please sign in to comment.