Skip to content

Commit

Permalink
unified log configuration and deletion of redundant
Browse files Browse the repository at this point in the history
  • Loading branch information
小滋润 committed Nov 11, 2024
1 parent 7bb82ad commit f75f93f
Show file tree
Hide file tree
Showing 9 changed files with 26 additions and 96 deletions.
5 changes: 3 additions & 2 deletions global/cron/enter.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,11 @@ package cron

import (
"context"

"github.com/ZiRunHua/LeapLedger/global"
"github.com/ZiRunHua/LeapLedger/global/constant"
"github.com/ZiRunHua/LeapLedger/global/nats"
"github.com/ZiRunHua/LeapLedger/initialize"
"github.com/ZiRunHua/LeapLedger/util/log"
"go.uber.org/zap"
)

Expand All @@ -19,7 +20,7 @@ var (

func init() {
var err error
logger, err = log.GetNewZapLogger(logPath)
logger, err = global.Config.Logger.New(logPath)
if err != nil {
panic(err)
}
Expand Down
8 changes: 4 additions & 4 deletions global/nats/manager/enter.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@ package manager
import (
"runtime/debug"

"github.com/ZiRunHua/LeapLedger/global"
"github.com/ZiRunHua/LeapLedger/global/constant"
"github.com/ZiRunHua/LeapLedger/initialize"
"github.com/ZiRunHua/LeapLedger/util/log"
"github.com/nats-io/nats.go/jetstream"
"go.uber.org/zap"
)
Expand Down Expand Up @@ -39,15 +39,15 @@ func init() {
if err != nil {
panic(err)
}
taskLogger, err = log.GetNewZapLogger(natsTaskLogPath)
taskLogger, err = global.Config.Logger.New(natsTaskLogPath)
if err != nil {
panic(err)
}
eventLogger, err = log.GetNewZapLogger(natsEventLogPath)
eventLogger, err = global.Config.Logger.New(natsEventLogPath)
if err != nil {
panic(err)
}
dlqLogger, err = log.GetNewZapLogger(dlqLogPath)
dlqLogger, err = global.Config.Logger.New(dlqLogPath)
if err != nil {
panic(err)
}
Expand Down
13 changes: 9 additions & 4 deletions initialize/logger.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package initialize

import (
"os"
"path/filepath"

"github.com/ZiRunHua/LeapLedger/global/constant"
"go.uber.org/zap"
Expand All @@ -21,13 +22,13 @@ const (
func (l *_logger) do() error {
l.setEncoder()
var err error
if RequestLogger, err = l.initLogger(_requestLogPath); err != nil {
if RequestLogger, err = l.New(_requestLogPath); err != nil {
return err
}
if ErrorLogger, err = l.initLogger(_errorLogPath); err != nil {
if ErrorLogger, err = l.New(_errorLogPath); err != nil {
return err
}
if PanicLogger, err = l.initLogger(_panicLogPath); err != nil {
if PanicLogger, err = l.New(_panicLogPath); err != nil {
return err
}
return nil
Expand All @@ -40,7 +41,11 @@ func (l *_logger) setEncoder() {
l.encoder = zapcore.NewConsoleEncoder(encoderConfig)
}

func (l *_logger) initLogger(path string) (*zap.Logger, error) {
func (l *_logger) New(path string) (*zap.Logger, error) {
err := os.MkdirAll(filepath.Dir(path), os.ModePerm)
if err != nil {
return nil, err
}
file, err := os.OpenFile(path, os.O_CREATE|os.O_WRONLY|os.O_APPEND, 0666)
if err != nil {
return nil, err
Expand Down
16 changes: 0 additions & 16 deletions service/category/enter.go
Original file line number Diff line number Diff line change
@@ -1,10 +1,7 @@
package categoryService

import (
"github.com/ZiRunHua/LeapLedger/global/constant"
_thirdpartyService "github.com/ZiRunHua/LeapLedger/service/thirdparty"
_log "github.com/ZiRunHua/LeapLedger/util/log"
"go.uber.org/zap"
)

type Group struct {
Expand All @@ -14,17 +11,4 @@ type Group struct {

var GroupApp = new(Group)

var task = &_task{}
var aiService = _thirdpartyService.GroupApp.Ai
var errorLog *zap.Logger

// 初始化
func init() {
initLog()
}
func initLog() {
var err error
if errorLog, err = _log.GetNewZapLogger(constant.LOG_PATH + "/service/category/error.log"); err != nil {
panic(err)
}
}
16 changes: 7 additions & 9 deletions service/product/bill/reader.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,19 +9,17 @@
package bill

import (
"context"
"strings"

"github.com/ZiRunHua/LeapLedger/global"
"github.com/ZiRunHua/LeapLedger/global/constant"
"github.com/ZiRunHua/LeapLedger/global/db"
accountModel "github.com/ZiRunHua/LeapLedger/model/account"
productModel "github.com/ZiRunHua/LeapLedger/model/product"
transactionModel "github.com/ZiRunHua/LeapLedger/model/transaction"
"github.com/ZiRunHua/LeapLedger/util/log"
"go.uber.org/zap"
"strings"
)

import (
"context"
"github.com/ZiRunHua/LeapLedger/global/db"
"github.com/pkg/errors"
"go.uber.org/zap"
)

const logPath = constant.LOG_PATH + "/service/product/bill.log"
Expand All @@ -30,7 +28,7 @@ var logger *zap.Logger

func init() {
var err error
if logger, err = log.GetNewZapLogger(logPath); err != nil {
if logger, err = global.Config.Logger.New(logPath); err != nil {
panic(err)
}
}
Expand Down
4 changes: 2 additions & 2 deletions service/template/enter.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"context"
"errors"

"github.com/ZiRunHua/LeapLedger/global"
"github.com/ZiRunHua/LeapLedger/global/constant"
"github.com/ZiRunHua/LeapLedger/global/cus"
"github.com/ZiRunHua/LeapLedger/global/db"
Expand All @@ -14,7 +15,6 @@ import (
_productService "github.com/ZiRunHua/LeapLedger/service/product"
_userService "github.com/ZiRunHua/LeapLedger/service/user"
"github.com/ZiRunHua/LeapLedger/util"
_log "github.com/ZiRunHua/LeapLedger/util/log"
"github.com/ZiRunHua/LeapLedger/util/rand"
"go.uber.org/zap"
"gorm.io/gorm"
Expand Down Expand Up @@ -48,7 +48,7 @@ var (

func init() {
var err error
if errorLog, err = _log.GetNewZapLogger(constant.LOG_PATH + "/service/template/error.log"); err != nil {
if errorLog, err = global.Config.Logger.New(constant.LOG_PATH + "/service/template/error.log"); err != nil {
panic(err)
}

Expand Down
12 changes: 0 additions & 12 deletions service/thirdparty/enter.go
Original file line number Diff line number Diff line change
@@ -1,10 +1,7 @@
package thirdpartyService

import (
"github.com/ZiRunHua/LeapLedger/global/constant"
"github.com/ZiRunHua/LeapLedger/service/thirdparty/email"
_log "github.com/ZiRunHua/LeapLedger/util/log"
"go.uber.org/zap"
)

type Group struct {
Expand All @@ -13,14 +10,5 @@ type Group struct {

var (
GroupApp = new(Group)
log *zap.Logger
emailServer = email.Service
)

// 初始化
func init() {
var err error
if log, err = _log.GetNewZapLogger(constant.LOG_PATH + "/service/thirdparty/email.log"); err != nil {
panic(err)
}
}
18 changes: 1 addition & 17 deletions service/transaction/enter.go
Original file line number Diff line number Diff line change
@@ -1,11 +1,5 @@
package transactionService

import (
"github.com/ZiRunHua/LeapLedger/global/constant"
_log "github.com/ZiRunHua/LeapLedger/util/log"
"go.uber.org/zap"
)

type Group struct {
Transaction
Timing Timing
Expand All @@ -14,15 +8,5 @@ type Group struct {
var (
GroupApp = new(Group)

errorLog *zap.Logger
task = &_task{}
server = &Transaction{}
server = &Transaction{}
)

// 初始化
func init() {
var err error
if errorLog, err = _log.GetNewZapLogger(constant.LOG_PATH + "/service/transaction/error.log"); err != nil {
panic(err)
}
}
30 changes: 0 additions & 30 deletions util/log/log.go

This file was deleted.

0 comments on commit f75f93f

Please sign in to comment.