diff --git a/app/log/log.go b/app/log/log.go index 22bba19ef..1b47cb567 100644 --- a/app/log/log.go +++ b/app/log/log.go @@ -29,6 +29,13 @@ func New(ctx context.Context, config *Config) (*Instance, error) { } log.RegisterHandler(g) + // start logger instantly on inited + // other modules would log during init + if err := g.startInternal(); err != nil { + return nil, err + } + + newError("Logger started").AtDebug().WriteToLog() return g, nil } @@ -81,13 +88,7 @@ func (g *Instance) startInternal() error { // Start implements common.Runnable.Start(). func (g *Instance) Start() error { - if err := g.startInternal(); err != nil { - return err - } - - newError("Logger started").AtDebug().WriteToLog() - - return nil + return g.startInternal() } // Handle implements log.Handler. diff --git a/infra/conf/v2ray.go b/infra/conf/v2ray.go index 3d3c0d112..01f74b4ff 100644 --- a/infra/conf/v2ray.go +++ b/infra/conf/v2ray.go @@ -341,11 +341,15 @@ func (c *Config) Build() (*core.Config, error) { config.App = append(config.App, serial.ToTypedMessage(statsConf)) } + var logConfMsg *serial.TypedMessage if c.LogConfig != nil { - config.App = append(config.App, serial.ToTypedMessage(c.LogConfig.Build())) + logConfMsg = serial.ToTypedMessage(c.LogConfig.Build()) } else { - config.App = append(config.App, serial.ToTypedMessage(DefaultLogConfig())) + logConfMsg = serial.ToTypedMessage(DefaultLogConfig()) } + // let logger module be the first App to start, + // so that other modules could print log during initiating + config.App = append([]*serial.TypedMessage{logConfMsg}, config.App...) if c.RouterConfig != nil { routerConfig, err := c.RouterConfig.Build()