From 0d9cc143b8297138578cad3539469cd1986b85ed Mon Sep 17 00:00:00 2001 From: heedaeshin Date: Thu, 12 Sep 2024 15:06:33 +0900 Subject: [PATCH] update : config path --- config/config.go | 12 +- data/example/Migrate/AwsToNcp.json | 18 -- data/example/Migrate/NcpToAws.json | 18 -- data/example/NRDB/aws.json | 10 - data/example/NRDB/gcp.json | 10 - data/example/NRDB/ncp.json | 13 - data/example/OBJ/aws.json | 11 - data/example/OBJ/gcp.json | 11 - data/example/OBJ/ncp.json | 12 - data/example/RDB/aws.json | 10 - data/var/run/data-manager/task/task.json | 366 ++++++++++------------- docs/Datamanager-task-Guide.md | 51 ++++ internal/log/log.go | 115 ------- internal/zerolog/logger.go | 187 ------------ websrc/controllers/publicfunc.go | 35 +-- 15 files changed, 229 insertions(+), 650 deletions(-) delete mode 100644 data/example/Migrate/AwsToNcp.json delete mode 100644 data/example/Migrate/NcpToAws.json delete mode 100644 data/example/NRDB/aws.json delete mode 100644 data/example/NRDB/gcp.json delete mode 100644 data/example/NRDB/ncp.json delete mode 100644 data/example/OBJ/aws.json delete mode 100644 data/example/OBJ/gcp.json delete mode 100644 data/example/OBJ/ncp.json delete mode 100644 data/example/RDB/aws.json create mode 100644 docs/Datamanager-task-Guide.md delete mode 100644 internal/log/log.go delete mode 100644 internal/zerolog/logger.go diff --git a/config/config.go b/config/config.go index aa5bd3d..42b64e3 100644 --- a/config/config.go +++ b/config/config.go @@ -47,10 +47,14 @@ func Init() { log.Error().Err(err).Msg("Failed to get executable path") log.Info().Msg("Using Default Config") } - viper.AddConfigPath(filepath.Join(execPath, "../../data/var/run/data-manager/config")) - viper.AddConfigPath(filepath.Join(execPath, "/data/var/run/data-manager/config")) - viper.AddConfigPath(filepath.Join(execPath, "./")) - viper.AddConfigPath(filepath.Join(execPath, "./config/")) + execDir := filepath.Dir(execPath) + log.Info().Msgf("Executable directory: %s", execDir) + + log.Info().Msg(execPath) + viper.AddConfigPath(filepath.Join(execDir, "../../data/var/run/data-manager/config")) + viper.AddConfigPath(filepath.Join(execDir, "./data/var/run/data-manager/config")) + viper.AddConfigPath(filepath.Join(execDir, "./")) + viper.AddConfigPath(filepath.Join(execDir, "./config/")) viper.SetConfigName("config") err = viper.ReadInConfig() diff --git a/data/example/Migrate/AwsToNcp.json b/data/example/Migrate/AwsToNcp.json deleted file mode 100644 index e3a4b2b..0000000 --- a/data/example/Migrate/AwsToNcp.json +++ /dev/null @@ -1,18 +0,0 @@ -{ - "operationId": "opt-00735", - "sourcePoint": { - "profileName": "admin", - "provider": "aws", - "region": "ap-northeast-2" - }, - "targetPoint": { - "profileName": "admin", - "provider": "ncp", - "region": "kr", - "databaseName": "spero", - "host": "p4spq.pub-vpc.mg.naverncp.com", - "port": "17017", - "username": "manager", - "password": "N@mutech7^^7" - } -} \ No newline at end of file diff --git a/data/example/Migrate/NcpToAws.json b/data/example/Migrate/NcpToAws.json deleted file mode 100644 index 1eb41f1..0000000 --- a/data/example/Migrate/NcpToAws.json +++ /dev/null @@ -1,18 +0,0 @@ -{ - "operationId": "opt-00735", - "targetPoint": { - "profileName": "admin", - "provider": "aws", - "region": "ap-northeast-2" - }, - "sourcePoint": { - "profileName": "admin", - "provider": "ncp", - "region": "kr", - "databaseName": "spero", - "host": "p4spq.pub-vpc.mg.naverncp.com", - "port": "17017", - "username": "manager", - "password": "N@mutech7^^7" - } -} \ No newline at end of file diff --git a/data/example/NRDB/aws.json b/data/example/NRDB/aws.json deleted file mode 100644 index dcb17f4..0000000 --- a/data/example/NRDB/aws.json +++ /dev/null @@ -1,10 +0,0 @@ -{ - "operationId": "opt-00735", - "targetPoint": { - "profileName": "admin", - "provider": "aws", - "region": "ap-northeast-2", - "CheckServerJSON": true, - "SizeServerJSON": "1" - } -} \ No newline at end of file diff --git a/data/example/NRDB/gcp.json b/data/example/NRDB/gcp.json deleted file mode 100644 index f420a40..0000000 --- a/data/example/NRDB/gcp.json +++ /dev/null @@ -1,10 +0,0 @@ -{ - "operationId": "opt-00735", - "targetPoint": { - "profileName": "admin", - "provider": "gcp", - "region": "asia-northeast2", - "CheckServerJSON": true, - "SizeServerJSON": "1" - } -} \ No newline at end of file diff --git a/data/example/NRDB/ncp.json b/data/example/NRDB/ncp.json deleted file mode 100644 index 8a03f04..0000000 --- a/data/example/NRDB/ncp.json +++ /dev/null @@ -1,13 +0,0 @@ -{ - "operationId": "opt-00735", - "targetPoint": { - "profileName": "admin", - "provider": "ncp", - "region": "kr", - "databaseName": "spero", - "host": "p4spq.pub-vpc.mg.naverncp.com", - "port": "17017", - "username": "manager", - "password": "N@mutech7^^7" - } -} \ No newline at end of file diff --git a/data/example/OBJ/aws.json b/data/example/OBJ/aws.json deleted file mode 100644 index 2619f95..0000000 --- a/data/example/OBJ/aws.json +++ /dev/null @@ -1,11 +0,0 @@ -{ - "operationId": "opt-00735", - "targetPoint": { - "profileName": "admin", - "provider": "aws", - "region": "ap-northeast-2", - "bucket": "mc-data-manager", - "CheckServerJSON": true, - "SizeServerJSON": "1" - } -} \ No newline at end of file diff --git a/data/example/OBJ/gcp.json b/data/example/OBJ/gcp.json deleted file mode 100644 index 822684e..0000000 --- a/data/example/OBJ/gcp.json +++ /dev/null @@ -1,11 +0,0 @@ -{ - "operationId": "opt-00735", - "targetPoint": { - "profileName": "admin", - "provider": "gcp", - "region": "asia-east1", - "bucket": "mc-data-manager", - "CheckServerJSON": true, - "SizeServerJSON": "1" - } -} \ No newline at end of file diff --git a/data/example/OBJ/ncp.json b/data/example/OBJ/ncp.json deleted file mode 100644 index f84ce77..0000000 --- a/data/example/OBJ/ncp.json +++ /dev/null @@ -1,12 +0,0 @@ -{ - "operationId": "opt-00735", - "targetPoint": { - "profileName": "admin", - "provider": "ncp", - "region": "kr", - "endpoint": "https://kr.object.ncloudstorage.com", - "bucket": "mc-data-manager", - "CheckServerJSON": true, - "SizeServerJSON": "1" - } -} \ No newline at end of file diff --git a/data/example/RDB/aws.json b/data/example/RDB/aws.json deleted file mode 100644 index fc661d4..0000000 --- a/data/example/RDB/aws.json +++ /dev/null @@ -1,10 +0,0 @@ -{ - "operationId": "opt-00735", - "targetPoint": { - "provider": "aws", - "host": "database-1.c36826os8m6p.ap-northeast-2.rds.amazonaws.com", - "port": "3306", - "username": "admin", - "password": "NAmutech7^^7" - } -} \ No newline at end of file diff --git a/data/var/run/data-manager/task/task.json b/data/var/run/data-manager/task/task.json index 0936fe3..47c1560 100644 --- a/data/var/run/data-manager/task/task.json +++ b/data/var/run/data-manager/task/task.json @@ -368,226 +368,164 @@ "databaseId": "", "projectId": "" } - } - ], - "flows": [], - "schedules": [ + }, { - "operationId": "operation-001", - "tag": [ - "gen", - "minutely" - ], - "ScheduleID": "operation-001-schedule-20240911-180002", - "ScheduleName": "", - "tasks": [ - { - "operationId": "", - "meta": { - "serviceType": "nrdbms", - "taskType": "generate", - "taskId": "task-1", - "taskName": "Database Gen Task", - "description": "Gen the main database" - }, - "Directory": "./tmp/backup/dir", - "sourcePoint": { - "provider": "", - "region": "", - "profileName": "admin", - "path": "./tmp/source/db", - "bucket": "", - "endpoint": "", - "host": "", - "port": "", - "username": "", - "password": "", - "databaseName": "", - "databaseId": "", - "projectId": "" - }, - "targetPoint": { - "provider": "", - "region": "", - "profileName": "default", - "path": "./tmp/backup/db", - "bucket": "", - "endpoint": "", - "host": "", - "port": "", - "username": "", - "password": "", - "databaseName": "", - "databaseId": "", - "projectId": "" - } - } - ], - "cron": "* * * * *", - "tz": "Asia/Seoul", - "status": "active" + "operationId": "", + "meta": { + "serviceType": "nrdbms", + "taskType": "backup", + "taskId": "operationID-XXX-task-0-20240912-132510" + }, + "Directory": "./tmp/schedule/dummy/NRDB/aws", + "sourcePoint": { + "provider": "", + "region": "", + "profileName": "", + "path": "", + "bucket": "", + "endpoint": "", + "host": "", + "port": "", + "username": "", + "password": "", + "databaseName": "", + "databaseId": "", + "projectId": "" + }, + "targetPoint": { + "provider": "aws", + "region": "ap-northeast-2", + "profileName": "admin", + "path": "", + "bucket": "", + "endpoint": "", + "host": "", + "port": "", + "username": "", + "password": "", + "databaseName": "", + "databaseId": "", + "projectId": "" + } }, { - "operationId": "operation-18542", - "tag": [ - "backup", - "a minute" - ], - "ScheduleID": "operation-18542-schedule-20240911-180022", - "ScheduleName": "", - "tasks": [ - { - "operationId": "", - "meta": { - "serviceType": "nrdbms", - "taskType": "backup", - "taskName": "Database Backup Task", - "description": "Backup the main database" - }, - "Directory": "./tmp/schedule/dummy/NRDB/aws", - "sourcePoint": { - "provider": "", - "region": "", - "profileName": "", - "path": "", - "bucket": "", - "endpoint": "", - "host": "", - "port": "", - "username": "", - "password": "", - "databaseName": "", - "databaseId": "", - "projectId": "" - }, - "targetPoint": { - "provider": "aws", - "region": "ap-northeast-2", - "profileName": "admin", - "path": "", - "bucket": "", - "endpoint": "", - "host": "", - "port": "", - "username": "", - "password": "", - "databaseName": "", - "databaseId": "", - "projectId": "" - } - } - ], - "cron": "* * * * *", - "tz": "Asia/Seoul", - "status": "active" + "operationId": "", + "meta": { + "serviceType": "nrdbms", + "taskType": "backup", + "taskId": "operationID-Nrdb-backup-gcp-task-0-20240912-132910" + }, + "Directory": "./tmp/schedule/dummy/NRDB/gcp", + "sourcePoint": { + "provider": "", + "region": "", + "profileName": "", + "path": "", + "bucket": "", + "endpoint": "", + "host": "", + "port": "", + "username": "", + "password": "", + "databaseName": "", + "databaseId": "", + "projectId": "" + }, + "targetPoint": { + "provider": "gcp", + "region": "asia-northeast2", + "profileName": "admin", + "path": "", + "bucket": "", + "endpoint": "", + "host": "", + "port": "", + "username": "", + "password": "", + "databaseName": "", + "databaseId": "", + "projectId": "" + } }, { - "operationId": "operation-18542", - "tag": [ - "backup", - "a minute" - ], - "ScheduleID": "operation-18542-schedule-20240911-180024", - "ScheduleName": "", - "tasks": [ - { - "operationId": "", - "meta": { - "serviceType": "nrdbms", - "taskType": "backup", - "taskName": "Database Backup Task", - "description": "Backup the main database" - }, - "Directory": "./tmp/schedule/dummy/NRDB/gcp", - "sourcePoint": { - "provider": "", - "region": "", - "profileName": "", - "path": "", - "bucket": "", - "endpoint": "", - "host": "", - "port": "", - "username": "", - "password": "", - "databaseName": "", - "databaseId": "", - "projectId": "" - }, - "targetPoint": { - "provider": "gcp", - "region": "asia-northeast2", - "profileName": "admin", - "path": "", - "bucket": "", - "endpoint": "", - "host": "", - "port": "", - "username": "", - "password": "", - "databaseName": "", - "databaseId": "", - "projectId": "" - } - } - ], - "cron": "* * * * *", - "tz": "Asia/Seoul", - "status": "active" + "operationId": "", + "meta": { + "serviceType": "nrdbms", + "taskType": "backup", + "taskId": "operationID-Nrdb-backup-gcp-task-0-20240912-133025" + }, + "Directory": "./tmp/schedule/dummy/NRDB/gcp", + "sourcePoint": { + "provider": "", + "region": "", + "profileName": "", + "path": "", + "bucket": "", + "endpoint": "", + "host": "", + "port": "", + "username": "", + "password": "", + "databaseName": "", + "databaseId": "", + "projectId": "" + }, + "targetPoint": { + "provider": "gcp", + "region": "asia-northeast2", + "profileName": "admin", + "path": "", + "bucket": "", + "endpoint": "", + "host": "", + "port": "", + "username": "", + "password": "", + "databaseName": "", + "databaseId": "", + "projectId": "" + } }, { - "operationId": "operation-18542", - "tag": [ - "backup", - "a minute" - ], - "ScheduleID": "operation-18542-schedule-20240911-180026", - "ScheduleName": "", - "tasks": [ - { - "operationId": "", - "meta": { - "serviceType": "nrdbms", - "taskType": "backup", - "taskName": "Database Backup Task", - "description": "Backup the main database" - }, - "Directory": "./tmp/schedule/dummy/NRDB/ncp", - "sourcePoint": { - "provider": "", - "region": "", - "profileName": "", - "path": "", - "bucket": "", - "endpoint": "", - "host": "", - "port": "", - "username": "", - "password": "", - "databaseName": "", - "databaseId": "", - "projectId": "" - }, - "targetPoint": { - "provider": "ncp", - "region": "kr", - "profileName": "admin", - "path": "", - "bucket": "", - "endpoint": "", - "host": "p4spq.pub-vpc.mg.naverncp.com", - "port": "17017", - "username": "manager", - "password": "N@mutech7^^7", - "databaseName": "spero", - "databaseId": "", - "projectId": "" - } - } - ], - "cron": "* * * * *", - "tz": "Asia/Seoul", - "status": "active" + "operationId": "", + "meta": { + "serviceType": "nrdbms", + "taskType": "backup", + "taskId": "operationID-Nrdb-backup-gcp-task-0-20240912-133102" + }, + "Directory": "./tmp/schedule/dummy/NRDB/gcp", + "sourcePoint": { + "provider": "", + "region": "", + "profileName": "", + "path": "", + "bucket": "", + "endpoint": "", + "host": "", + "port": "", + "username": "", + "password": "", + "databaseName": "", + "databaseId": "", + "projectId": "" + }, + "targetPoint": { + "provider": "gcp", + "region": "asia-northeast2", + "profileName": "admin", + "path": "", + "bucket": "", + "endpoint": "", + "host": "", + "port": "", + "username": "", + "password": "", + "databaseName": "", + "databaseId": "", + "projectId": "" + } } - ] + ], + "flows": [], + "schedules": [] } diff --git a/docs/Datamanager-task-Guide.md b/docs/Datamanager-task-Guide.md new file mode 100644 index 0000000..685adea --- /dev/null +++ b/docs/Datamanager-task-Guide.md @@ -0,0 +1,51 @@ + + + + +AWS-NRDB-Backup +```go +{ + "cron": "* * * * *", + "tz": "Asia/Seoul", + + "operationId": "operationID-XXX", + "tasks": [ + { + "meta": { + "serviceType": "nrdbms", + "taskType": "backup", + }, + "targetPoint": { + "profileName": "admin", + "provider": "aws", + "region": "ap-northeast-2" + }, + "Directory":"./tmp/schedule/dummy/NRDB/aws" + } + ] +} +``` + + +GCP-NRDB-BACKUP +```go +{ + "cron": "* * * * *", + "tz": "Asia/Seoul", + "operationId": "operationID-Nrdb-backup-gcp", + "tasks": [ + { + "meta": { + "serviceType": "nrdbms", + "taskType": "backup" + }, + "targetPoint": { + "profileName": "admin", + "provider": "gcp", + "region": "asia-northeast2" + }, + "Directory": "./tmp/schedule/dummy/NRDB/gcp" + } + ] +} +``` \ No newline at end of file diff --git a/internal/log/log.go b/internal/log/log.go deleted file mode 100644 index 77b645a..0000000 --- a/internal/log/log.go +++ /dev/null @@ -1,115 +0,0 @@ -// /* -// Copyright 2023 The Cloud-Barista Authors. - -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at - -// http://www.apache.org/licenses/LICENSE-2.0 - -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. -// */ -package log - -// import ( -// "fmt" -// "io" -// "os" -// "path/filepath" -// "strings" -// "sync" - -// "github.com/sirupsen/logrus" -// ) - -// var ( -// instance *Logger -// once sync.Once -// ) - -// type Logger struct { -// *zerolog.Logger -// } - -// // GetInstance returns the singleton instance of Logger -// func GetInstance() *Logger { -// once.Do(func() { -// instance = &Logger{ -// Logger: logrus.New(), -// } -// instance.setupLogger() -// }) -// return instance -// } - -// func (l *Logger) setupLogger() { -// execPath, err := os.Executable() -// if err != nil { -// l.Fatal("Failed to get executable path: ", err) -// } - -// // Get the directory path of the binary file -// execDir := filepath.Dir(execPath) - -// // Set the log directory path -// logDir := filepath.Join(execDir, "log") - -// // Create the log directory -// if err := os.MkdirAll(logDir, os.ModePerm); err != nil { -// logrus.WithError(err).Fatal("Failed to create log directory") -// } - -// // Set the log file path -// logFilePath := filepath.Join(logDir, "data-manager.log") - -// // Open or create the log file -// logFile, err := os.OpenFile(logFilePath, os.O_CREATE|os.O_APPEND|os.O_RDWR, os.FileMode(0644)) -// if err != nil { -// logrus.WithError(err).Fatal("Failed to create log file") -// } -// logrus.SetLevel(logrus.DebugLevel) -// logrus.SetFormatter(&CustomTextFormatter{}) -// logrus.SetOutput(io.MultiWriter(os.Stdout, logFile)) -// } - -// type CustomTextFormatter struct { -// CmdName string -// JobName string -// } - -// func (f *CustomTextFormatter) Format(entry *logrus.Entry) ([]byte, error) { -// timeFormatted := entry.Time.Format("2006-01-02T15:04:05-07:00") -// cn := f.CmdName -// jn := f.JobName -// if _, ok := entry.Data["cmdbName"]; ok { -// cn = entry.Data["cmdbName"].(string) -// } -// if _, ok := entry.Data["jobName"]; ok { -// jn = entry.Data["jobName"].(string) -// } -// return []byte(fmt.Sprintf("[%s] [%s] [%s] [%s] %s\n", timeFormatted, entry.Level, cn, jn, strings.ToUpper(entry.Message[:1])+entry.Message[1:])), nil -// } - -// func Debug(args ...interface{}) { -// GetInstance().Debug(args...) -// } - -// func Info(args ...interface{}) { -// GetInstance().Info(args...) -// } - -// func Warn(args ...interface{}) { -// GetInstance().Warn(args...) -// } - -// func Error(args ...interface{}) { -// GetInstance().Error(args...) -// } - -// func Fatal(args ...interface{}) { -// GetInstance().Fatal(args...) -// } diff --git a/internal/zerolog/logger.go b/internal/zerolog/logger.go deleted file mode 100644 index 26337ea..0000000 --- a/internal/zerolog/logger.go +++ /dev/null @@ -1,187 +0,0 @@ -// /* -// Copyright 2023 The Cloud-Barista Authors. - -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at - -// http://www.apache.org/licenses/LICENSE-2.0 - -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. -// */ -package zlog - -// import ( -// "fmt" -// "os" -// "path/filepath" -// "strings" -// "sync" -// "time" - -// "github.com/rs/zerolog" -// "github.com/rs/zerolog/log" -// "gopkg.in/natefinch/lumberjack.v2" -// ) - -// var ( -// instance *Logger -// once sync.Once -// ) - -// type Logger struct { -// zerolog.Logger -// } - -// type LogEntry struct { -// logger *Logger -// level zerolog.Level -// cmdName string // ServiceType -// jobName string // TaskType -// message string -// } - -// // GetInstance returns the singleton instance of Logger -// func GetInstance() *Logger { -// once.Do(func() { -// instance = &Logger{} -// instance.setupLogger() -// }) -// return instance -// } - -// // setupLogger configures the Logger instance with lumberjack for log rotation and zerolog.MultiWriter -// func (l *Logger) setupLogger() { -// execPath, err := os.Executable() -// if err != nil { -// log.Fatal().Msgf("Failed to get executable path: %v", err) -// } - -// // Get the directory path of the binary file -// execDir := filepath.Dir(execPath) - -// // Set the log directory path -// logDir := filepath.Join(execDir, "./data/var/log") - -// // Create the log directory if it doesn't exist -// if err := os.MkdirAll(logDir, os.ModePerm); err != nil { -// log.Fatal().Msgf("Failed to create log directory: %v", err) -// } - -// // Set the log file path -// logFilePath := filepath.Join(logDir, "data-manager.log") - -// // Configure lumberjack for log rotation -// rotationLogger := &lumberjack.Logger{ -// Filename: logFilePath, -// MaxSize: 100, // Maximum size in megabytes before log is rotated -// MaxBackups: 3, // Maximum number of old log files to retain -// MaxAge: 28, // Maximum number of days to retain old log files -// Compress: true, // Whether to compress/zip old log files -// } - -// // Use Zerolog's MultiWriter to write to both stdout and the rotated log file -// multiWriter := zerolog.MultiLevelWriter(os.Stdout, rotationLogger) - -// // Set zerolog level and output -// l.Logger = zerolog.New(multiWriter).With().Timestamp().Logger() -// zerolog.SetGlobalLevel(zerolog.DebugLevel) -// } - -// // NewLogEntry creates a new log entry -// func (l *Logger) NewLogEntry() *LogEntry { -// return &LogEntry{ -// logger: l, -// } -// } - -// func (e *LogEntry) WithLevel(level zerolog.Level) *LogEntry { -// e.level = level -// return e -// } - -// func (e *LogEntry) WithCmdName(cmdName string) *LogEntry { -// e.cmdName = cmdName -// return e -// } - -// func (e *LogEntry) WithJobName(jobName string) *LogEntry { -// e.jobName = jobName -// return e -// } - -// func (e *LogEntry) WithMessage(message string) *LogEntry { -// e.message = message -// return e -// } - -// func (e *LogEntry) logWithCustomFormat() { -// timeFormatted := time.Now().Format(time.RFC3339) -// logEvent := e.logger.With(). -// Str("time", timeFormatted). -// Str("level", e.level.String()). -// Str("cmdName", e.cmdName). -// Str("jobName", e.jobName). -// Logger() - -// logEvent.Log().Msg(strings.ToUpper(e.message[:1]) + e.message[1:]) -// } - -// // Convenience methods for logging at different levels -// func Debug(cmdName, jobName string, args ...interface{}) { -// GetInstance().NewLogEntry(). -// WithLevel(zerolog.DebugLevel). -// WithCmdName(cmdName). -// WithJobName(jobName). -// WithMessage(fmt.Sprint(args...)). -// logWithCustomFormat() -// } - -// func Info(cmdName, jobName string, args ...interface{}) { -// GetInstance().NewLogEntry(). -// WithLevel(zerolog.InfoLevel). -// WithCmdName(cmdName). -// WithJobName(jobName). -// WithMessage(fmt.Sprint(args...)). -// logWithCustomFormat() -// } - -// func Warn(cmdName, jobName string, args ...interface{}) { -// GetInstance().NewLogEntry(). -// WithLevel(zerolog.WarnLevel). -// WithCmdName(cmdName). -// WithJobName(jobName). -// WithMessage(fmt.Sprint(args...)). -// logWithCustomFormat() -// } - -// func Error(cmdName, jobName string, args ...interface{}) { -// GetInstance().NewLogEntry(). -// WithLevel(zerolog.ErrorLevel). -// WithCmdName(cmdName). -// WithJobName(jobName). -// WithMessage(fmt.Sprint(args...)). -// logWithCustomFormat() -// } - -// func Fatal(cmdName, jobName string, args ...interface{}) { -// GetInstance().NewLogEntry(). -// WithLevel(zerolog.FatalLevel). -// WithCmdName(cmdName). -// WithJobName(jobName). -// WithMessage(fmt.Sprint(args...)). -// logWithCustomFormat() -// } - -// func Trace(cmdName, jobName string, args ...interface{}) { -// GetInstance().NewLogEntry(). -// WithLevel(zerolog.TraceLevel). -// WithCmdName(cmdName). -// WithJobName(jobName). -// WithMessage(fmt.Sprint(args...)). -// logWithCustomFormat() -// } diff --git a/websrc/controllers/publicfunc.go b/websrc/controllers/publicfunc.go index e1a6db2..46a8853 100644 --- a/websrc/controllers/publicfunc.go +++ b/websrc/controllers/publicfunc.go @@ -595,9 +595,9 @@ func getDataWithBind(logger *zerolog.Logger, startTime time.Time, ctx echo.Conte if err := ctx.Bind(params); err != nil { end := time.Now() logger.Error().Msg("Failed to bind form data") - logger.Info().Interface("params", ctx.Request().Body).Msg("") - logger.Info().Str("End time", end.Format("2006-01-02T15:04:05-07:00")).Msg("") - logger.Info().Str("Elapsed time", end.Sub(startTime).String()).Msg("") + logger.Error().Interface("params", ctx.Request().Body).Msg("") + logger.Error().Str("End time", end.Format("2006-01-02T15:04:05-07:00")).Msg("") + logger.Error().Str("Elapsed time", end.Sub(startTime).String()).Msg("") return false } return true @@ -612,16 +612,17 @@ func getDataWithReBind(logger *zerolog.Logger, startTime time.Time, ctx echo.Con return false } - logger.Info().Str("Request Body", string(bodyBytes)).Msg("") + logger.Info().Msgf("%+v", string(bodyBytes)) ctx.Request().Body = io.NopCloser(bytes.NewBuffer(bodyBytes)) if err := ctx.Bind(params); err != nil { end := time.Now() + logger.Error().Err(err) logger.Error().Msg("Failed to bind form data") - logger.Info().Interface("Params", string(bodyBytes)).Msg("") - logger.Info().Str("End time", end.Format("2006-01-02T15:04:05-07:00")).Msg("") - logger.Info().Str("Elapsed time", end.Sub(startTime).String()).Msg("") + logger.Error().Interface("Params", string(bodyBytes)).Msg("") + logger.Error().Str("End time", end.Format("2006-01-02T15:04:05-07:00")).Msg("") + logger.Error().Str("Elapsed time", end.Sub(startTime).String()).Msg("") return false } @@ -637,8 +638,8 @@ func gcpCreateCredFile(logger *zerolog.Logger, startTime time.Time, ctx echo.Con if err != nil { end := time.Now() logger.Error().Err(err).Msg("Get CredentialFile error") - logger.Info().Str("end time", end.Format("2006-01-02T15:04:05-07:00")).Msg("") - logger.Info().Str("Elapsed time", end.Sub(startTime).String()).Msg("") + logger.Error().Str("end time", end.Format("2006-01-02T15:04:05-07:00")).Msg("") + logger.Error().Str("Elapsed time", end.Sub(startTime).String()).Msg("") return "", "", false } @@ -646,8 +647,8 @@ func gcpCreateCredFile(logger *zerolog.Logger, startTime time.Time, ctx echo.Con if err != nil { end := time.Now() logger.Error().Err(err).Msg("Get CredentialFile error") - logger.Info().Str("end time", end.Format("2006-01-02T15:04:05-07:00")).Msg("") - logger.Info().Str("Elapsed time", end.Sub(startTime).String()).Msg("") + logger.Error().Str("end time", end.Format("2006-01-02T15:04:05-07:00")).Msg("") + logger.Error().Str("Elapsed time", end.Sub(startTime).String()).Msg("") return "", "", false } @@ -657,8 +658,8 @@ func gcpCreateCredFile(logger *zerolog.Logger, startTime time.Time, ctx echo.Con if err != nil { end := time.Now() logger.Error().Err(err).Msg("Get CredentialFile error") - logger.Info().Str("end time", end.Format("2006-01-02T15:04:05-07:00")).Msg("") - logger.Info().Str("Elapsed time", end.Sub(startTime).String()).Msg("") + logger.Error().Str("end time", end.Format("2006-01-02T15:04:05-07:00")).Msg("") + logger.Error().Str("Elapsed time", end.Sub(startTime).String()).Msg("") return "", "", false } defer gcpCredentialFile.Close() @@ -667,8 +668,8 @@ func gcpCreateCredFile(logger *zerolog.Logger, startTime time.Time, ctx echo.Con if err != nil { end := time.Now() logger.Error().Err(err).Msg("File create error") - logger.Info().Str("end time", end.Format("2006-01-02T15:04:05-07:00")).Msg("") - logger.Info().Str("Elapsed time", end.Sub(startTime).String()).Msg("") + logger.Error().Str("end time", end.Format("2006-01-02T15:04:05-07:00")).Msg("") + logger.Error().Str("Elapsed time", end.Sub(startTime).String()).Msg("") return "", "", false } defer dst.Close() @@ -676,8 +677,8 @@ func gcpCreateCredFile(logger *zerolog.Logger, startTime time.Time, ctx echo.Con if _, err = io.Copy(dst, gcpCredentialFile); err != nil { end := time.Now() logger.Error().Err(err).Msg("File copy error") - logger.Info().Str("end time", end.Format("2006-01-02T15:04:05-07:00")).Msg("") - logger.Info().Str("Elapsed time", end.Sub(startTime).String()).Msg("") + logger.Error().Str("end time", end.Format("2006-01-02T15:04:05-07:00")).Msg("") + logger.Error().Str("Elapsed time", end.Sub(startTime).String()).Msg("") return "", "", false }