파일에 직접 로깅하는 로거로 교체
This commit is contained in:
@ -9,7 +9,6 @@ import (
|
||||
"strconv"
|
||||
"time"
|
||||
|
||||
"repositories.action2quare.com/ayo/gocommon/logger"
|
||||
"repositories.action2quare.com/ayo/houston/shared"
|
||||
)
|
||||
|
||||
@ -26,7 +25,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 {
|
||||
logger.Error(err)
|
||||
shared.Logger().Println(err)
|
||||
w.WriteHeader(http.StatusInternalServerError)
|
||||
return
|
||||
}
|
||||
@ -62,7 +61,7 @@ func (h *houstonHandler) UploadDeploySource(w http.ResponseWriter, r *http.Reque
|
||||
// </form>
|
||||
file, header, err := r.FormFile("file")
|
||||
if err != nil {
|
||||
logger.Error(err)
|
||||
shared.Logger().Println(err)
|
||||
w.WriteHeader(http.StatusBadRequest)
|
||||
return
|
||||
}
|
||||
@ -70,7 +69,7 @@ func (h *houstonHandler) UploadDeploySource(w http.ResponseWriter, r *http.Reque
|
||||
|
||||
contents, err := io.ReadAll(file)
|
||||
if err != nil {
|
||||
logger.Error(err)
|
||||
shared.Logger().Println(err)
|
||||
w.WriteHeader(http.StatusInternalServerError)
|
||||
return
|
||||
}
|
||||
@ -89,7 +88,7 @@ func (h *houstonHandler) UploadDeploySource(w http.ResponseWriter, r *http.Reque
|
||||
}
|
||||
|
||||
if err = os.MkdirAll(path.Dir(filename), 0775); err != nil {
|
||||
logger.Error(err)
|
||||
shared.Logger().Println(err)
|
||||
w.WriteHeader(http.StatusInternalServerError)
|
||||
return
|
||||
}
|
||||
@ -97,7 +96,7 @@ func (h *houstonHandler) UploadDeploySource(w http.ResponseWriter, r *http.Reque
|
||||
// 파일 저장
|
||||
err = os.WriteFile(filename, contents, 0644)
|
||||
if err != nil {
|
||||
logger.Error(err)
|
||||
shared.Logger().Println(err)
|
||||
w.WriteHeader(http.StatusInternalServerError)
|
||||
return
|
||||
}
|
||||
@ -119,7 +118,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 {
|
||||
logger.Println("deleteDeploySource failed :", err)
|
||||
shared.Logger().Println("deleteDeploySource failed :", err)
|
||||
w.WriteHeader(http.StatusInternalServerError)
|
||||
return
|
||||
}
|
||||
@ -139,7 +138,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 {
|
||||
logger.Error(err)
|
||||
shared.Logger().Println(err)
|
||||
w.WriteHeader(http.StatusBadRequest)
|
||||
return
|
||||
}
|
||||
@ -153,7 +152,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 {
|
||||
logger.Error(err)
|
||||
shared.Logger().Println(err)
|
||||
w.WriteHeader(http.StatusBadRequest)
|
||||
return
|
||||
}
|
||||
@ -200,7 +199,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 {
|
||||
logger.Error(err)
|
||||
shared.Logger().Println(err)
|
||||
w.WriteHeader(http.StatusBadRequest)
|
||||
return
|
||||
}
|
||||
@ -236,7 +235,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 {
|
||||
logger.Error(err)
|
||||
shared.Logger().Println(err)
|
||||
w.WriteHeader(http.StatusBadRequest)
|
||||
return
|
||||
}
|
||||
@ -275,7 +274,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 {
|
||||
logger.Error(err)
|
||||
shared.Logger().Println(err)
|
||||
w.WriteHeader(http.StatusBadRequest)
|
||||
return
|
||||
}
|
||||
@ -312,7 +311,7 @@ func (h *houstonHandler) UploadLogs(w http.ResponseWriter, r *http.Request) {
|
||||
}
|
||||
var targets []string
|
||||
if err := json.Unmarshal([]byte(traws), &targets); err != nil {
|
||||
logger.Error(err)
|
||||
shared.Logger().Println(err)
|
||||
w.WriteHeader(http.StatusBadRequest)
|
||||
return
|
||||
}
|
||||
|
||||
@ -10,7 +10,7 @@ import (
|
||||
"runtime/debug"
|
||||
"strings"
|
||||
|
||||
"repositories.action2quare.com/ayo/gocommon/logger"
|
||||
"repositories.action2quare.com/ayo/houston/shared"
|
||||
)
|
||||
|
||||
const (
|
||||
@ -57,7 +57,7 @@ func (h *houstonHandler) RegisterHandlers(serveMux *http.ServeMux, prefix string
|
||||
return err
|
||||
}
|
||||
|
||||
logger.Printf("houstonHandler registed. deployPath : %s, downloadPath : %s", h.deployPath, h.downloadPath)
|
||||
shared.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 {
|
||||
logger.Println(s)
|
||||
shared.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 {
|
||||
logger.Println(s)
|
||||
shared.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
|
||||
logger.Println("fail to call api. operation is not valid :", operation)
|
||||
shared.Logger().Println("fail to call api. operation is not valid :", operation)
|
||||
w.WriteHeader(http.StatusBadRequest)
|
||||
return
|
||||
}
|
||||
|
||||
@ -7,8 +7,6 @@ import (
|
||||
"reflect"
|
||||
"sync"
|
||||
|
||||
"repositories.action2quare.com/ayo/gocommon/logger"
|
||||
|
||||
"repositories.action2quare.com/ayo/houston/shared"
|
||||
"repositories.action2quare.com/ayo/houston/shared/protos"
|
||||
)
|
||||
@ -75,7 +73,7 @@ func (sp *hostPool) regist(desc *protos.OperationQueryRequest) (string, chan *op
|
||||
sp.hosts[desc.Hostname] = host
|
||||
|
||||
test, _ := json.Marshal(sp.hosts)
|
||||
logger.Println(string(test))
|
||||
shared.Logger().Println(string(test))
|
||||
return desc.Hostname, host.opChan
|
||||
}
|
||||
|
||||
@ -90,7 +88,7 @@ func (sp *hostPool) refresh(desc *protos.OperationQueryRequest) {
|
||||
}
|
||||
|
||||
test, _ := json.Marshal(sp.hosts)
|
||||
logger.Println(string(test))
|
||||
shared.Logger().Println(string(test))
|
||||
}
|
||||
|
||||
func (sp *hostPool) unregist(key string) {
|
||||
|
||||
@ -6,7 +6,6 @@ import (
|
||||
"net"
|
||||
"os"
|
||||
|
||||
"repositories.action2quare.com/ayo/gocommon/logger"
|
||||
"repositories.action2quare.com/ayo/houston/shared"
|
||||
"repositories.action2quare.com/ayo/houston/shared/protos"
|
||||
|
||||
@ -110,7 +109,7 @@ type Operation interface {
|
||||
func loadServerConfig() serverConfig {
|
||||
configFile, err := os.Open("config.json")
|
||||
if err != nil {
|
||||
logger.Error(err)
|
||||
shared.Logger().Println(err)
|
||||
return serverConfig{
|
||||
GrpcPort: 8080,
|
||||
}
|
||||
@ -126,14 +125,14 @@ func loadServerConfig() serverConfig {
|
||||
dec := json.NewDecoder(configFile)
|
||||
err = dec.Decode(&config)
|
||||
if err != nil {
|
||||
logger.Error(err)
|
||||
shared.Logger().Println(err)
|
||||
return serverConfig{
|
||||
GrpcPort: 8080,
|
||||
}
|
||||
}
|
||||
|
||||
if config.Houston == nil {
|
||||
logger.Error(`"houston" object is missing in config.json`)
|
||||
shared.Logger().Println(`"houston" object is missing in config.json`)
|
||||
return serverConfig{
|
||||
GrpcPort: 8080,
|
||||
}
|
||||
@ -167,7 +166,7 @@ type houstonServer struct {
|
||||
}
|
||||
|
||||
func (hs *houstonServer) Start() error {
|
||||
logger.Println("houston server is started at port", hs.port)
|
||||
shared.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
|
||||
|
||||
Reference in New Issue
Block a user