로거 되돌림

This commit is contained in:
2023-06-14 00:13:51 +09:00
parent 20b2df1fc5
commit 3add5d9355
10 changed files with 60 additions and 87 deletions

View File

@ -9,6 +9,7 @@ import (
"strconv"
"time"
"repositories.action2quare.com/ayo/gocommon/logger"
"repositories.action2quare.com/ayo/houston/shared"
)
@ -25,7 +26,7 @@ func (h *houstonHandler) GetAgents(w http.ResponseWriter, r *http.Request) {
func (h *houstonHandler) GetDeploySources(w http.ResponseWriter, r *http.Request) {
files, err := os.ReadDir(h.deployPath)
if err != nil {
shared.Logger().Println(err)
logger.Println(err)
w.WriteHeader(http.StatusInternalServerError)
return
}
@ -61,7 +62,7 @@ func (h *houstonHandler) UploadDeploySource(w http.ResponseWriter, r *http.Reque
// </form>
file, header, err := r.FormFile("file")
if err != nil {
shared.Logger().Println(err)
logger.Println(err)
w.WriteHeader(http.StatusBadRequest)
return
}
@ -69,7 +70,7 @@ func (h *houstonHandler) UploadDeploySource(w http.ResponseWriter, r *http.Reque
contents, err := io.ReadAll(file)
if err != nil {
shared.Logger().Println(err)
logger.Println(err)
w.WriteHeader(http.StatusInternalServerError)
return
}
@ -88,7 +89,7 @@ func (h *houstonHandler) UploadDeploySource(w http.ResponseWriter, r *http.Reque
}
if err = os.MkdirAll(path.Dir(filename), 0775); err != nil {
shared.Logger().Println(err)
logger.Println(err)
w.WriteHeader(http.StatusInternalServerError)
return
}
@ -96,7 +97,7 @@ func (h *houstonHandler) UploadDeploySource(w http.ResponseWriter, r *http.Reque
// 파일 저장
err = os.WriteFile(filename, contents, 0644)
if err != nil {
shared.Logger().Println(err)
logger.Println(err)
w.WriteHeader(http.StatusInternalServerError)
return
}
@ -118,7 +119,7 @@ func (h *houstonHandler) DeleteDeploySource(w http.ResponseWriter, r *http.Reque
// deploys 폴더는 파일시스템 서비스이므로 다운로드 가능
targetpath := path.Join(h.deployPath, name, version)
if err := os.RemoveAll(targetpath); err != nil {
shared.Logger().Println("deleteDeploySource failed :", err)
logger.Println("deleteDeploySource failed :", err)
w.WriteHeader(http.StatusInternalServerError)
return
}
@ -138,7 +139,7 @@ func (h *houstonHandler) Deploy(w http.ResponseWriter, r *http.Request) {
var targets []string
if len(traws) > 0 {
if err := json.Unmarshal([]byte(traws), &targets); err != nil {
shared.Logger().Println(err)
logger.Println(err)
w.WriteHeader(http.StatusBadRequest)
return
}
@ -152,7 +153,7 @@ func (h *houstonHandler) Deploy(w http.ResponseWriter, r *http.Request) {
relPath := path.Join(h.deployPath, name, version)
files, err := os.ReadDir(relPath)
if err != nil {
shared.Logger().Println(err)
logger.Println(err)
w.WriteHeader(http.StatusBadRequest)
return
}
@ -199,7 +200,7 @@ func (h *houstonHandler) Undeploy(w http.ResponseWriter, r *http.Request) {
var targets []string
if len(traws) > 0 {
if err := json.Unmarshal([]byte(traws), &targets); err != nil {
shared.Logger().Println(err)
logger.Println(err)
w.WriteHeader(http.StatusBadRequest)
return
}
@ -235,7 +236,7 @@ func (h *houstonHandler) StartProcess(w http.ResponseWriter, r *http.Request) {
var targets []string
if len(traws) > 0 {
if err := json.Unmarshal([]byte(traws), &targets); err != nil {
shared.Logger().Println(err)
logger.Println(err)
w.WriteHeader(http.StatusBadRequest)
return
}
@ -274,7 +275,7 @@ func (h *houstonHandler) StopProcess(w http.ResponseWriter, r *http.Request) {
var targets []string
if len(traws) > 0 {
if err := json.Unmarshal([]byte(traws), &targets); err != nil {
shared.Logger().Println(err)
logger.Println(err)
w.WriteHeader(http.StatusBadRequest)
return
}
@ -311,7 +312,7 @@ func (h *houstonHandler) UploadLogs(w http.ResponseWriter, r *http.Request) {
}
var targets []string
if err := json.Unmarshal([]byte(traws), &targets); err != nil {
shared.Logger().Println(err)
logger.Println(err)
w.WriteHeader(http.StatusBadRequest)
return
}

View File

@ -10,7 +10,7 @@ import (
"runtime/debug"
"strings"
"repositories.action2quare.com/ayo/houston/shared"
"repositories.action2quare.com/ayo/gocommon/logger"
)
const (
@ -57,7 +57,7 @@ func (h *houstonHandler) RegisterHandlers(serveMux *http.ServeMux, prefix string
return err
}
shared.Logger().Printf("houstonHandler registed. deployPath : %s, downloadPath : %s", h.deployPath, h.downloadPath)
logger.Printf("houstonHandler registed. deployPath : %s, downloadPath : %s", h.deployPath, h.downloadPath)
if len(prefix) > 0 {
prefix = "/" + prefix
@ -74,7 +74,7 @@ func (h *houstonHandler) RegisterHandlers(serveMux *http.ServeMux, prefix string
defer func() {
s := recover()
if s != nil {
shared.Logger().Println(s)
logger.Println(s)
debug.PrintStack()
}
io.Copy(io.Discard, r.Body)
@ -107,7 +107,7 @@ func (h *houstonHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
defer func() {
s := recover()
if s != nil {
shared.Logger().Println(s)
logger.Println(s)
debug.PrintStack()
}
}()
@ -132,7 +132,7 @@ func (h *houstonHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
method, ok := h.methods[strings.ToLower(operation)]
if !ok {
// 없는 operation
shared.Logger().Println("fail to call api. operation is not valid :", operation)
logger.Println("fail to call api. operation is not valid :", operation)
w.WriteHeader(http.StatusBadRequest)
return
}

View File

@ -6,6 +6,7 @@ import (
"net"
"os"
"repositories.action2quare.com/ayo/gocommon/logger"
"repositories.action2quare.com/ayo/houston/shared"
"repositories.action2quare.com/ayo/houston/shared/protos"
@ -109,7 +110,7 @@ type Operation interface {
func loadServerConfig() serverConfig {
configFile, err := os.Open("config.json")
if err != nil {
shared.Logger().Println(err)
logger.Println(err)
return serverConfig{
GrpcPort: 8080,
}
@ -125,14 +126,14 @@ func loadServerConfig() serverConfig {
dec := json.NewDecoder(configFile)
err = dec.Decode(&config)
if err != nil {
shared.Logger().Println(err)
logger.Println(err)
return serverConfig{
GrpcPort: 8080,
}
}
if config.Houston == nil {
shared.Logger().Println(`"houston" object is missing in config.json`)
logger.Println(`"houston" object is missing in config.json`)
return serverConfig{
GrpcPort: 8080,
}
@ -166,7 +167,7 @@ type houstonServer struct {
}
func (hs *houstonServer) Start() error {
shared.Logger().Println("houston server is started at port", hs.port)
logger.Println("houston server is started at port", hs.port)
lis, err := net.Listen("tcp", fmt.Sprintf("0.0.0.0:%d", hs.port))
if err != nil {
return err