Skip to content

Commit

Permalink
feat: Support log management (#1087)
Browse files Browse the repository at this point in the history
Co-authored-by: Marco <[email protected]>
Co-authored-by: wenxuwan <[email protected]>
  • Loading branch information
3 people authored Dec 19, 2024
1 parent 079b75e commit 13c49c2
Show file tree
Hide file tree
Showing 62 changed files with 932 additions and 309 deletions.
20 changes: 19 additions & 1 deletion cmd/layotto/cmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@ import (
mosn_zipkin "mosn.io/mosn/pkg/trace/zipkin"
"mosn.io/pkg/buffer"

"mosn.io/layotto/kit/logger"

component_actuators "mosn.io/layotto/components/pkg/actuators"
"mosn.io/layotto/diagnostics"
"mosn.io/layotto/diagnostics/jaeger"
Expand Down Expand Up @@ -113,6 +115,14 @@ var (
}, cli.StringSliceFlag{
Name: "component-log-level, lc",
Usage: "mosn component format, currently useless",
}, cli.StringFlag{
Name: "logging-level, ll",
Usage: "layotto log level, trace|debug|info|warn|error|fatal",
EnvVar: "LOGGING_LEVEL",
}, cli.StringFlag{
Name: "logging-path, lp",
Usage: "layotto log file path, default ./",
EnvVar: "LOGGING_PATH",
}, cli.StringFlag{
Name: "local-address-ip-version",
Usage: "ip version, v4 or v6, currently useless",
Expand Down Expand Up @@ -247,6 +257,13 @@ func SetActuatorAfterStart(_ stagemanager.Application) {
}

func DefaultParamsParsed(c *cli.Context) {
// log level control
flagLoggingLevel := c.String("logging-level")
logger.SetDefaultLoggerLevel(flagLoggingLevel)

flagLoggingPath := c.String("logging-path")
logger.SetDefaultLoggerFilePath(flagLoggingPath)

// log level control
flagLogLevel := c.String("log-level")
if mosnLogLevel, ok := flagToMosnLogLevel[flagLogLevel]; ok {
Expand Down Expand Up @@ -295,8 +312,9 @@ func ExtensionsRegister(_ *cli.Context) {
trace.RegisterTracerBuilder(mosn_jaeger.DriverName, lprotocol.Layotto, jaeger.NewGrpcJaegerTracer)
trace.RegisterTracerBuilder(mosn_zipkin.DriverName, lprotocol.Layotto, zipkin.NewGrpcZipTracer)

log := logger.NewLayottoLogger("iobuffer")
// register buffer logger
buffer.SetLogFunc(func(msg string) {
log.DefaultLogger.Errorf("[iobuffer] iobuffer error log info: %s", msg)
log.Errorf("[iobuffer] iobuffer error log info: %s", msg)
})
}
34 changes: 20 additions & 14 deletions cmd/layotto/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,6 @@ import (

dbindings "github.com/dapr/components-contrib/bindings"
"github.com/dapr/components-contrib/bindings/http"
"mosn.io/pkg/log"

"mosn.io/layotto/components/configstores/etcdv3"
"mosn.io/layotto/components/configstores/nacos"
Expand Down Expand Up @@ -161,6 +160,7 @@ import (
_ "mosn.io/layotto/pkg/actuator"
"mosn.io/layotto/pkg/actuator/health"
actuatorInfo "mosn.io/layotto/pkg/actuator/info"
actuatorLogger "mosn.io/layotto/pkg/actuator/logger"
_ "mosn.io/layotto/pkg/filter/stream/actuator/http"
"mosn.io/layotto/pkg/integrate/actuator"

Expand All @@ -178,6 +178,8 @@ import (
_ "mosn.io/mosn/pkg/wasm/runtime/wasmer"
_ "mosn.io/pkg/buffer"

layottoLogger "mosn.io/layotto/kit/logger"

_ "mosn.io/layotto/pkg/filter/network/tcpcopy"
_ "mosn.io/layotto/pkg/filter/stream/wasm/http"
l8_grpc "mosn.io/layotto/pkg/grpc"
Expand Down Expand Up @@ -234,6 +236,9 @@ import (
// loggerForDaprComp is constructed for reusing dapr's components.
var loggerForDaprComp = logger.NewLogger("reuse.dapr.component")

// loggerForLayotto is constructed for layotto.
var loggerForLayotto = layottoLogger.NewLayottoLogger("layotto")

// GitVersion mosn version is specified by latest tag
var GitVersion = ""
var IstioVersion = "1.10.6"
Expand All @@ -242,6 +247,7 @@ func init() {
mgrpc.RegisterServerHandler("runtime", NewRuntimeGrpcServer)
// Register default actuator implementations
actuatorInfo.AddInfoContributor("app", actuator.GetAppContributor())
actuatorLogger.NewEndpoint()
health.AddReadinessIndicator("runtime_startup", actuator.GetRuntimeReadinessIndicator())
health.AddLivenessIndicator("runtime_startup", actuator.GetRuntimeLivenessIndicator())
}
Expand All @@ -253,7 +259,7 @@ func NewRuntimeGrpcServer(data json.RawMessage, opts ...grpc.ServerOption) (mgrp
// fail fast if error occurs during startup.
// The reason we panic in a new goroutine is to prevent mosn from recovering.
go func() {
log.DefaultLogger.Errorf("An error occurred during startup : %v", err)
loggerForLayotto.Errorf("An error occurred during startup : %v", err)
panic(err)
}()
}
Expand Down Expand Up @@ -432,22 +438,22 @@ func NewRuntimeGrpcServer(data json.RawMessage, opts ...grpc.ServerOption) (mgrp
// Lock
runtime.WithLockFactory(
runtime_lock.NewFactory("redis_cluster", func() lock.LockStore {
return lock_redis.NewClusterRedisLock(log.DefaultLogger)
return lock_redis.NewClusterRedisLock()
}),
runtime_lock.NewFactory("redis", func() lock.LockStore {
return lock_redis.NewStandaloneRedisLock(log.DefaultLogger)
return lock_redis.NewStandaloneRedisLock()
}),
runtime_lock.NewFactory("zookeeper", func() lock.LockStore {
return lock_zookeeper.NewZookeeperLock(log.DefaultLogger)
return lock_zookeeper.NewZookeeperLock()
}),
runtime_lock.NewFactory("etcd", func() lock.LockStore {
return lock_etcd.NewEtcdLock(log.DefaultLogger)
return lock_etcd.NewEtcdLock()
}),
runtime_lock.NewFactory("consul", func() lock.LockStore {
return lock_consul.NewConsulLock(log.DefaultLogger)
return lock_consul.NewConsulLock()
}),
runtime_lock.NewFactory("mongo", func() lock.LockStore {
return lock_mongo.NewMongoLock(log.DefaultLogger)
return lock_mongo.NewMongoLock()
}),
runtime_lock.NewFactory("in-memory", func() lock.LockStore {
return lock_inmemory.NewInMemoryLock()
Expand All @@ -464,25 +470,25 @@ func NewRuntimeGrpcServer(data json.RawMessage, opts ...grpc.ServerOption) (mgrp
// Sequencer
runtime.WithSequencerFactory(
runtime_sequencer.NewFactory("etcd", func() sequencer.Store {
return sequencer_etcd.NewEtcdSequencer(log.DefaultLogger)
return sequencer_etcd.NewEtcdSequencer()
}),
runtime_sequencer.NewFactory("redis", func() sequencer.Store {
return sequencer_redis.NewStandaloneRedisSequencer(log.DefaultLogger)
return sequencer_redis.NewStandaloneRedisSequencer()
}),
runtime_sequencer.NewFactory("zookeeper", func() sequencer.Store {
return sequencer_zookeeper.NewZookeeperSequencer(log.DefaultLogger)
return sequencer_zookeeper.NewZookeeperSequencer()
}),
runtime_sequencer.NewFactory("mongo", func() sequencer.Store {
return sequencer_mongo.NewMongoSequencer(log.DefaultLogger)
return sequencer_mongo.NewMongoSequencer()
}),
runtime_sequencer.NewFactory("in-memory", func() sequencer.Store {
return sequencer_inmemory.NewInMemorySequencer()
}),
runtime_sequencer.NewFactory("mysql", func() sequencer.Store {
return sequencer_mysql.NewMySQLSequencer(log.DefaultLogger)
return sequencer_mysql.NewMySQLSequencer()
}),
runtime_sequencer.NewFactory("snowflake", func() sequencer.Store {
return sequencer_snowflake.NewSnowFlakeSequencer(log.DefaultLogger)
return sequencer_snowflake.NewSnowFlakeSequencer()
}),
),
// secretstores
Expand Down
5 changes: 4 additions & 1 deletion cmd/layotto_multiple_api/cmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ import (
"runtime"
"time"

"mosn.io/layotto/kit/logger"

"mosn.io/api"
"mosn.io/mosn/istio/istio1106"
v2 "mosn.io/mosn/pkg/config/v2"
Expand Down Expand Up @@ -295,8 +297,9 @@ func ExtensionsRegister(_ *cli.Context) {
trace.RegisterTracerBuilder(mosn_jaeger.DriverName, lprotocol.Layotto, jaeger.NewGrpcJaegerTracer)
trace.RegisterTracerBuilder(mosn_zipkin.DriverName, lprotocol.Layotto, zipkin.NewGrpcZipTracer)

log := logger.NewLayottoLogger("iobuffer")
// register buffer logger
buffer.SetLogFunc(func(msg string) {
log.DefaultLogger.Errorf("[iobuffer] iobuffer error log info: %s", msg)
log.Errorf("[iobuffer] iobuffer error log info: %s", msg)
})
}
34 changes: 20 additions & 14 deletions cmd/layotto_multiple_api/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,9 @@ import (
"strconv"
"time"

layottoLogger "mosn.io/layotto/kit/logger"
actuatorLogger "mosn.io/layotto/pkg/actuator/logger"

"mosn.io/layotto/components/sms"

"mosn.io/layotto/components/cryption"
Expand Down Expand Up @@ -70,7 +73,6 @@ import (

dbindings "github.com/dapr/components-contrib/bindings"
"github.com/dapr/components-contrib/bindings/http"
"mosn.io/pkg/log"

"mosn.io/layotto/cmd/layotto_multiple_api/helloworld/component"
"mosn.io/layotto/components/configstores/etcdv3"
Expand Down Expand Up @@ -231,6 +233,9 @@ import (
// loggerForDaprComp is constructed for reusing dapr's components.
var loggerForDaprComp = logger.NewLogger("reuse.dapr.component")

// loggerForLayotto is constructed for layotto.
var loggerForLayotto = layottoLogger.NewLayottoLogger("layotto")

// GitVersion mosn version is specified by latest tag
var GitVersion = ""
var IstioVersion = "1.10.6"
Expand All @@ -239,6 +244,7 @@ func init() {
mgrpc.RegisterServerHandler("runtime", NewRuntimeGrpcServer)
// Register default actuator implementations
actuatorInfo.AddInfoContributor("app", actuator.GetAppContributor())
actuatorLogger.NewEndpoint()
health.AddReadinessIndicator("runtime_startup", actuator.GetRuntimeReadinessIndicator())
health.AddLivenessIndicator("runtime_startup", actuator.GetRuntimeLivenessIndicator())
}
Expand All @@ -250,7 +256,7 @@ func NewRuntimeGrpcServer(data json.RawMessage, opts ...grpc.ServerOption) (mgrp
// fail fast if error occurs during startup.
// The reason we panic in a new goroutine is to prevent mosn from recovering.
go func() {
log.DefaultLogger.Errorf("An error occurred during startup : %v", err)
loggerForLayotto.Errorf("An error occurred during startup : %v", err)
panic(err)
}()
}
Expand Down Expand Up @@ -436,22 +442,22 @@ func NewRuntimeGrpcServer(data json.RawMessage, opts ...grpc.ServerOption) (mgrp
// Lock
runtime.WithLockFactory(
runtime_lock.NewFactory("redis_cluster", func() lock.LockStore {
return lock_redis.NewClusterRedisLock(log.DefaultLogger)
return lock_redis.NewClusterRedisLock()
}),
runtime_lock.NewFactory("redis", func() lock.LockStore {
return lock_redis.NewStandaloneRedisLock(log.DefaultLogger)
return lock_redis.NewStandaloneRedisLock()
}),
runtime_lock.NewFactory("zookeeper", func() lock.LockStore {
return lock_zookeeper.NewZookeeperLock(log.DefaultLogger)
return lock_zookeeper.NewZookeeperLock()
}),
runtime_lock.NewFactory("etcd", func() lock.LockStore {
return lock_etcd.NewEtcdLock(log.DefaultLogger)
return lock_etcd.NewEtcdLock()
}),
runtime_lock.NewFactory("consul", func() lock.LockStore {
return lock_consul.NewConsulLock(log.DefaultLogger)
return lock_consul.NewConsulLock()
}),
runtime_lock.NewFactory("mongo", func() lock.LockStore {
return lock_mongo.NewMongoLock(log.DefaultLogger)
return lock_mongo.NewMongoLock()
}),
runtime_lock.NewFactory("in-memory", func() lock.LockStore {
return lock_inmemory.NewInMemoryLock()
Expand All @@ -468,25 +474,25 @@ func NewRuntimeGrpcServer(data json.RawMessage, opts ...grpc.ServerOption) (mgrp
// Sequencer
runtime.WithSequencerFactory(
runtime_sequencer.NewFactory("etcd", func() sequencer.Store {
return sequencer_etcd.NewEtcdSequencer(log.DefaultLogger)
return sequencer_etcd.NewEtcdSequencer()
}),
runtime_sequencer.NewFactory("redis", func() sequencer.Store {
return sequencer_redis.NewStandaloneRedisSequencer(log.DefaultLogger)
return sequencer_redis.NewStandaloneRedisSequencer()
}),
runtime_sequencer.NewFactory("zookeeper", func() sequencer.Store {
return sequencer_zookeeper.NewZookeeperSequencer(log.DefaultLogger)
return sequencer_zookeeper.NewZookeeperSequencer()
}),
runtime_sequencer.NewFactory("mongo", func() sequencer.Store {
return sequencer_mongo.NewMongoSequencer(log.DefaultLogger)
return sequencer_mongo.NewMongoSequencer()
}),
runtime_sequencer.NewFactory("in-memory", func() sequencer.Store {
return sequencer_inmemory.NewInMemorySequencer()
}),
runtime_sequencer.NewFactory("mysql", func() sequencer.Store {
return sequencer_mysql.NewMySQLSequencer(log.DefaultLogger)
return sequencer_mysql.NewMySQLSequencer()
}),
runtime_sequencer.NewFactory("snowflake", func() sequencer.Store {
return sequencer_snowflake.NewSnowFlakeSequencer(log.DefaultLogger)
return sequencer_snowflake.NewSnowFlakeSequencer()
}),
),
// secretstores
Expand Down
20 changes: 19 additions & 1 deletion cmd/layotto_without_xds/cmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ import (
"os"
"runtime"

"mosn.io/layotto/kit/logger"

"mosn.io/api"
v2 "mosn.io/mosn/pkg/config/v2"
"mosn.io/mosn/pkg/configmanager"
Expand Down Expand Up @@ -68,6 +70,14 @@ var (
Name: "log-level, l",
Usage: "mosn log level, trace|debug|info|warning|error|critical|off",
EnvVar: "LOG_LEVEL",
}, cli.StringFlag{
Name: "logging-level, ll",
Usage: "layotto log level, trace|debug|info|warn|error|fatal",
EnvVar: "LOGGING_LEVEL",
}, cli.StringFlag{
Name: "logging-path, lp",
Usage: "layotto log file path, default ./",
EnvVar: "LOGGING_PATH",
},
},
Action: func(c *cli.Context) error {
Expand Down Expand Up @@ -144,6 +154,13 @@ func SetActuatorAfterStart(_ stagemanager.Application) {
}

func DefaultParamsParsed(c *cli.Context) {
// log level control
flagLoggingLevel := c.String("logging-level")
logger.SetDefaultLoggerLevel(flagLoggingLevel)

flagLoggingPath := c.String("logging-path")
logger.SetDefaultLoggerFilePath(flagLoggingPath)

// log level control
flagLogLevel := c.String("log-level")
if mosnLogLevel, ok := flagToMosnLogLevel[flagLogLevel]; ok {
Expand Down Expand Up @@ -192,8 +209,9 @@ func ExtensionsRegister(_ *cli.Context) {
trace.RegisterTracerBuilder(mosn_jaeger.DriverName, lprotocol.Layotto, jaeger.NewGrpcJaegerTracer)
trace.RegisterTracerBuilder(mosn_zipkin.DriverName, lprotocol.Layotto, zipkin.NewGrpcZipTracer)

log := logger.NewLayottoLogger("iobuffer")
// register buffer logger
buffer.SetLogFunc(func(msg string) {
log.DefaultLogger.Errorf("[iobuffer] iobuffer error log info: %s", msg)
log.Errorf("[iobuffer] iobuffer error log info: %s", msg)
})
}
Loading

0 comments on commit 13c49c2

Please sign in to comment.