feat(logger) Change others logs
This commit is contained in:
@@ -2,7 +2,6 @@ package generator
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"log"
|
||||
"maps"
|
||||
"os"
|
||||
"path/filepath"
|
||||
@@ -336,7 +335,7 @@ func (chart *HelmChart) setSharedConf(service types.ServiceConfig, deployments m
|
||||
// find the configmap in the chart templates
|
||||
for _, fromservice := range fromservices {
|
||||
if _, ok := chart.Templates[fromservice+".configmap.yaml"]; !ok {
|
||||
log.Printf("configmap %s not found in chart templates", fromservice)
|
||||
logger.Warnf("configmap %s not found in chart templates", fromservice)
|
||||
continue
|
||||
}
|
||||
// find the corresponding target deployment
|
||||
|
||||
@@ -2,7 +2,6 @@ package generator
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"log"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"regexp"
|
||||
@@ -311,7 +310,7 @@ func (d *Deployment) SetEnvFrom(service types.ServiceConfig, appName string, sam
|
||||
defer func() {
|
||||
c, index := d.BindMapFilesToContainer(service, secrets, appName)
|
||||
if c == nil || index == -1 {
|
||||
log.Println("Container not found for service ", service.Name)
|
||||
logger.Warn("Container not found for service ", service.Name)
|
||||
return
|
||||
}
|
||||
d.Spec.Template.Spec.Containers[index] = *c
|
||||
@@ -384,8 +383,8 @@ func (d *Deployment) BindMapFilesToContainer(service types.ServiceConfig, secret
|
||||
|
||||
if envSize > 0 {
|
||||
if service.Name == "db" {
|
||||
log.Println("Service ", service.Name, " has environment variables")
|
||||
log.Println(service.Environment)
|
||||
logger.Info("Service ", service.Name, " has environment variables")
|
||||
logger.Info(service.Environment)
|
||||
}
|
||||
fromSources = append(fromSources, corev1.EnvFromSource{
|
||||
ConfigMapRef: &corev1.ConfigMapEnvSource{
|
||||
|
||||
@@ -4,12 +4,12 @@ import (
|
||||
"bytes"
|
||||
_ "embed"
|
||||
"fmt"
|
||||
"log"
|
||||
"sort"
|
||||
"strings"
|
||||
"text/template"
|
||||
|
||||
"gopkg.in/yaml.v3"
|
||||
"katenary.io/internal/logger"
|
||||
)
|
||||
|
||||
//go:embed readme.tpl
|
||||
@@ -50,7 +50,7 @@ func ReadMeFile(charname, description string, values map[string]any) string {
|
||||
vv := map[string]any{}
|
||||
out, _ := yaml.Marshal(values)
|
||||
if err := yaml.Unmarshal(out, &vv); err != nil {
|
||||
log.Printf("Error parsing values: %s", err)
|
||||
logger.Warnf("Error parsing values: %s", err)
|
||||
}
|
||||
|
||||
result := make(map[string]string)
|
||||
|
||||
@@ -3,7 +3,6 @@ package generator
|
||||
import (
|
||||
"bytes"
|
||||
"fmt"
|
||||
"log"
|
||||
"regexp"
|
||||
"strings"
|
||||
|
||||
@@ -280,7 +279,7 @@ func addStaticVolumes(deployments map[string]*Deployment, service types.ServiceC
|
||||
var d *Deployment
|
||||
var ok bool
|
||||
if d, ok = deployments[service.Name]; !ok {
|
||||
log.Printf("service %s not found in deployments", service.Name)
|
||||
logger.Warnf("service %s not found in deployments", service.Name)
|
||||
return
|
||||
}
|
||||
|
||||
@@ -434,7 +433,7 @@ func samePodVolume(service types.ServiceConfig, v types.ServiceVolumeConfig, dep
|
||||
// check if it has the same volume
|
||||
for _, tv := range target.Spec.Template.Spec.Volumes {
|
||||
if tv.Name == v.Source {
|
||||
log.Printf("found same pod volume %s in deployment %s and %s", tv.Name, service.Name, targetDeployment)
|
||||
logger.Warnf("found same pod volume %s in deployment %s and %s", tv.Name, service.Name, targetDeployment)
|
||||
return true
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3,7 +3,6 @@ package katenaryfile
|
||||
import (
|
||||
"bytes"
|
||||
"encoding/json"
|
||||
"log"
|
||||
"os"
|
||||
"reflect"
|
||||
"strings"
|
||||
@@ -113,7 +112,7 @@ func getLabelContent(o any, service *types.ServiceConfig, labelName string) erro
|
||||
|
||||
c, err := yaml.Marshal(o)
|
||||
if err != nil {
|
||||
log.Println(err)
|
||||
logger.Failure(err.Error())
|
||||
return err
|
||||
}
|
||||
val := strings.TrimSpace(string(c))
|
||||
|
||||
@@ -2,10 +2,10 @@ package labelstructs
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"log"
|
||||
|
||||
"gopkg.in/yaml.v3"
|
||||
corev1 "k8s.io/api/core/v1"
|
||||
"katenary.io/internal/logger"
|
||||
)
|
||||
|
||||
type HealthCheck struct {
|
||||
@@ -24,13 +24,13 @@ func ProbeFrom(data string) (*HealthCheck, error) {
|
||||
if livenessProbe, ok := tmp["livenessProbe"]; ok {
|
||||
livenessProbeBytes, err := json.Marshal(livenessProbe)
|
||||
if err != nil {
|
||||
log.Printf("Error marshalling livenessProbe: %v", err)
|
||||
logger.Warnf("Error marshalling livenessProbe: %v", err)
|
||||
return nil, err
|
||||
}
|
||||
livenessProbe := &corev1.Probe{}
|
||||
err = json.Unmarshal(livenessProbeBytes, livenessProbe)
|
||||
if err != nil {
|
||||
log.Printf("Error unmarshalling livenessProbe: %v", err)
|
||||
logger.Warnf("Error unmarshalling livenessProbe: %v", err)
|
||||
return nil, err
|
||||
}
|
||||
mapping.LivenessProbe = livenessProbe
|
||||
@@ -39,13 +39,13 @@ func ProbeFrom(data string) (*HealthCheck, error) {
|
||||
if readinessProbe, ok := tmp["readinessProbe"]; ok {
|
||||
readinessProbeBytes, err := json.Marshal(readinessProbe)
|
||||
if err != nil {
|
||||
log.Printf("Error marshalling readinessProbe: %v", err)
|
||||
logger.Warnf("Error marshalling readinessProbe: %v", err)
|
||||
return nil, err
|
||||
}
|
||||
readinessProbe := &corev1.Probe{}
|
||||
err = json.Unmarshal(readinessProbeBytes, readinessProbe)
|
||||
if err != nil {
|
||||
log.Printf("Error unmarshalling readinessProbe: %v", err)
|
||||
logger.Warnf("Error unmarshalling readinessProbe: %v", err)
|
||||
return nil, err
|
||||
}
|
||||
mapping.ReadinessProbe = readinessProbe
|
||||
|
||||
@@ -1,11 +1,11 @@
|
||||
package generator
|
||||
|
||||
import (
|
||||
"log"
|
||||
"os"
|
||||
"os/exec"
|
||||
"testing"
|
||||
|
||||
"katenary.io/internal/logger"
|
||||
"katenary.io/internal/parser"
|
||||
)
|
||||
|
||||
@@ -23,7 +23,7 @@ func setup(content string) string {
|
||||
|
||||
func teardown(tmpDir string) {
|
||||
// remove the temporary directory
|
||||
log.Println("Removing temporary directory: ", tmpDir)
|
||||
logger.Info("Removing temporary directory: ", tmpDir)
|
||||
if err := os.RemoveAll(tmpDir); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
@@ -59,7 +59,7 @@ func compileTest(t *testing.T, force bool, options ...string) string {
|
||||
ChartVersion: chartVersion,
|
||||
}
|
||||
if err := Convert(convertOptions, "compose.yml"); err != nil {
|
||||
log.Printf("Failed to convert: %s", err)
|
||||
logger.Warnf("Failed to convert: %s", err)
|
||||
return err.Error()
|
||||
}
|
||||
|
||||
|
||||
@@ -27,34 +27,72 @@ const (
|
||||
|
||||
const reset = "\033[0m"
|
||||
|
||||
// Print prints a message without icon.
|
||||
func Print(msg ...any) {
|
||||
fmt.Print(msg...)
|
||||
}
|
||||
|
||||
// Printf prints a formatted message without icon.
|
||||
func Printf(format string, msg ...any) {
|
||||
fmt.Printf(format, msg...)
|
||||
}
|
||||
|
||||
// Info prints an informational message.
|
||||
func Info(msg ...any) {
|
||||
message("", IconInfo, msg...)
|
||||
}
|
||||
|
||||
// Infof prints a formatted informational message.
|
||||
func Infof(format string, msg ...any) {
|
||||
message("", IconInfo, fmt.Sprintf(format, msg...))
|
||||
}
|
||||
|
||||
// Warn prints a warning message.
|
||||
func Warn(msg ...any) {
|
||||
orange := "\033[38;5;214m"
|
||||
message(orange, IconWarning, msg...)
|
||||
}
|
||||
|
||||
// Warnf prints a formatted warning message.
|
||||
func Warnf(format string, msg ...any) {
|
||||
orange := "\033[38;5;214m"
|
||||
message(orange, IconWarning, fmt.Sprintf(format, msg...))
|
||||
}
|
||||
|
||||
// Success prints a success message.
|
||||
func Success(msg ...any) {
|
||||
green := "\033[38;5;34m"
|
||||
message(green, IconSuccess, msg...)
|
||||
}
|
||||
|
||||
// Successf prints a formatted success message.
|
||||
func Successf(format string, msg ...any) {
|
||||
green := "\033[38;5;34m"
|
||||
message(green, IconSuccess, fmt.Sprintf(format, msg...))
|
||||
}
|
||||
|
||||
// Failure prints a failure message.
|
||||
func Failure(msg ...any) {
|
||||
red := "\033[38;5;196m"
|
||||
message(red, IconFailure, msg...)
|
||||
}
|
||||
|
||||
// Failuref prints a formatted failure message.
|
||||
func Failuref(format string, msg ...any) {
|
||||
red := "\033[38;5;196m"
|
||||
message(red, IconFailure, fmt.Sprintf(format, msg...))
|
||||
}
|
||||
|
||||
// Log prints a message with a custom icon.
|
||||
func Log(icon Icon, msg ...any) {
|
||||
message("", icon, msg...)
|
||||
}
|
||||
|
||||
// Logf prints a formatted message with a custom icon.
|
||||
func Logf(icon Icon, format string, msg ...any) {
|
||||
message("", icon, fmt.Sprintf(format, msg...))
|
||||
}
|
||||
|
||||
func fatal(red string, icon Icon, msg ...any) {
|
||||
fmt.Print(icon, " ", red)
|
||||
fmt.Print(msg...)
|
||||
|
||||
@@ -3,7 +3,6 @@ package utils
|
||||
import (
|
||||
"bytes"
|
||||
"fmt"
|
||||
"log"
|
||||
"path/filepath"
|
||||
"strings"
|
||||
|
||||
@@ -133,7 +132,7 @@ func GetValuesFromLabel(service types.ServiceConfig, LabelValues string) map[str
|
||||
labelContent := []any{}
|
||||
err := yaml.Unmarshal([]byte(v), &labelContent)
|
||||
if err != nil {
|
||||
log.Printf("Error parsing label %s: %s", v, err)
|
||||
logger.Warnf("Error parsing label %s: %s", v, err)
|
||||
logger.Fatal(err)
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user