mirror of
https://github.com/openimsdk/open-im-server.git
synced 2025-05-03 16:26:36 +08:00
fix cron
This commit is contained in:
parent
a348af74fa
commit
d73ab781fe
@ -43,6 +43,7 @@ func run(port int) error {
|
|||||||
}
|
}
|
||||||
fmt.Println("start api server, address: ", address, ", OpenIM version: ", config.Version)
|
fmt.Println("start api server, address: ", address, ", OpenIM version: ", config.Version)
|
||||||
log2.Info(context.Background(), "start server success", "address", address, "version", config.Version)
|
log2.Info(context.Background(), "start server success", "address", address, "version", config.Version)
|
||||||
|
log.Info("s", "start server")
|
||||||
err = router.Run(address)
|
err = router.Run(address)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Error("", "api run failed ", address, err.Error())
|
log.Error("", "api run failed ", address, err.Error())
|
||||||
|
@ -3,7 +3,6 @@ package cmd
|
|||||||
import (
|
import (
|
||||||
"OpenIM/pkg/common/config"
|
"OpenIM/pkg/common/config"
|
||||||
"OpenIM/pkg/common/constant"
|
"OpenIM/pkg/common/constant"
|
||||||
log "OpenIM/pkg/common/logger"
|
|
||||||
"github.com/spf13/cobra"
|
"github.com/spf13/cobra"
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -20,11 +19,7 @@ func NewRootCmd() (rootCmd *RootCmd) {
|
|||||||
Short: "Start the server",
|
Short: "Start the server",
|
||||||
Long: `Start the server`,
|
Long: `Start the server`,
|
||||||
PersistentPreRunE: func(cmd *cobra.Command, args []string) error {
|
PersistentPreRunE: func(cmd *cobra.Command, args []string) error {
|
||||||
err := rootCmd.getConfFromCmdAndInit(cmd)
|
return rootCmd.getConfFromCmdAndInit(cmd)
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
return log.InitFromConfig("newlog")
|
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
rootCmd.Command = c
|
rootCmd.Command = c
|
||||||
|
17
pkg/common/log/logger.go
Normal file
17
pkg/common/log/logger.go
Normal file
@ -0,0 +1,17 @@
|
|||||||
|
package log
|
||||||
|
|
||||||
|
import "context"
|
||||||
|
|
||||||
|
type Logger interface {
|
||||||
|
Debug(ctx context.Context, msg string, keysAndValues ...interface{})
|
||||||
|
Info(ctx context.Context, msg string, keysAndValues ...interface{})
|
||||||
|
Warn(ctx context.Context, msg string, err error, keysAndValues ...interface{})
|
||||||
|
Error(ctx context.Context, msg string, err error, keysAndValues ...interface{})
|
||||||
|
WithValues(keysAndValues ...interface{}) LogrusLogger
|
||||||
|
WithName(name string) LogrusLogger
|
||||||
|
WithCallDepth(depth int) LogrusLogger
|
||||||
|
|
||||||
|
WithItemSampler() LogrusLogger
|
||||||
|
// WithoutSampler returns the original logger without sampling
|
||||||
|
WithoutSampler() LogrusLogger
|
||||||
|
}
|
@ -16,10 +16,10 @@ import (
|
|||||||
"github.com/sirupsen/logrus"
|
"github.com/sirupsen/logrus"
|
||||||
)
|
)
|
||||||
|
|
||||||
var logger *Logger
|
var logger *LogrusLogger
|
||||||
var ctxLogger *Logger
|
var ctxLogger *LogrusLogger
|
||||||
|
|
||||||
type Logger struct {
|
type LogrusLogger struct {
|
||||||
*logrus.Logger
|
*logrus.Logger
|
||||||
Pid int
|
Pid int
|
||||||
Type string
|
Type string
|
||||||
@ -35,7 +35,7 @@ func NewPrivateLog(moduleName string) {
|
|||||||
ctxLogger = ctxLoggerInit(moduleName)
|
ctxLogger = ctxLoggerInit(moduleName)
|
||||||
}
|
}
|
||||||
|
|
||||||
func ctxLoggerInit(moduleName string) *Logger {
|
func ctxLoggerInit(moduleName string) *LogrusLogger {
|
||||||
var ctxLogger = logrus.New()
|
var ctxLogger = logrus.New()
|
||||||
ctxLogger.SetLevel(logrus.Level(config.Config.Log.RemainLogLevel))
|
ctxLogger.SetLevel(logrus.Level(config.Config.Log.RemainLogLevel))
|
||||||
src, err := os.OpenFile(os.DevNull, os.O_APPEND|os.O_WRONLY, os.ModeAppend)
|
src, err := os.OpenFile(os.DevNull, os.O_APPEND|os.O_WRONLY, os.ModeAppend)
|
||||||
@ -55,14 +55,14 @@ func ctxLoggerInit(moduleName string) *Logger {
|
|||||||
//Log file segmentation hook
|
//Log file segmentation hook
|
||||||
hook := NewLfsHook(time.Duration(config.Config.Log.RotationTime)*time.Hour, config.Config.Log.RemainRotationCount, moduleName)
|
hook := NewLfsHook(time.Duration(config.Config.Log.RotationTime)*time.Hour, config.Config.Log.RemainRotationCount, moduleName)
|
||||||
ctxLogger.AddHook(hook)
|
ctxLogger.AddHook(hook)
|
||||||
return &Logger{
|
return &LogrusLogger{
|
||||||
ctxLogger,
|
ctxLogger,
|
||||||
os.Getpid(),
|
os.Getpid(),
|
||||||
"ctxLogger",
|
"ctxLogger",
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func loggerInit(moduleName string) *Logger {
|
func loggerInit(moduleName string) *LogrusLogger {
|
||||||
var logger = logrus.New()
|
var logger = logrus.New()
|
||||||
//All logs will be printed
|
//All logs will be printed
|
||||||
logger.SetLevel(logrus.Level(config.Config.Log.RemainLogLevel))
|
logger.SetLevel(logrus.Level(config.Config.Log.RemainLogLevel))
|
||||||
@ -93,7 +93,7 @@ func loggerInit(moduleName string) *Logger {
|
|||||||
//Log file segmentation hook
|
//Log file segmentation hook
|
||||||
hook := NewLfsHook(time.Duration(config.Config.Log.RotationTime)*time.Hour, config.Config.Log.RemainRotationCount, moduleName)
|
hook := NewLfsHook(time.Duration(config.Config.Log.RotationTime)*time.Hour, config.Config.Log.RemainRotationCount, moduleName)
|
||||||
logger.AddHook(hook)
|
logger.AddHook(hook)
|
||||||
return &Logger{
|
return &LogrusLogger{
|
||||||
logger,
|
logger,
|
||||||
os.Getpid(),
|
os.Getpid(),
|
||||||
"",
|
"",
|
||||||
|
Loading…
x
Reference in New Issue
Block a user