Merge pull request #8283 from filecoin-project/feat/loglvl-config

feat: config: Persistent subsystem log level config
This commit is contained in:
Łukasz Magiera 2022-03-10 23:22:26 +01:00 committed by GitHub
commit b248097b42
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
10 changed files with 77 additions and 6 deletions

View File

@ -23,6 +23,12 @@
#DisableMetadataLog = false #DisableMetadataLog = false
[Logging]
[Logging.SubsystemLevels]
# env var: LOTUS_LOGGING_SUBSYSTEMLEVELS_EXAMPLE-SUBSYSTEM
#example-subsystem = "INFO"
[Libp2p] [Libp2p]
# Binding address for the libp2p host - 0 means random port. # Binding address for the libp2p host - 0 means random port.
# Format: multiaddress; see https://multiformats.io/multiaddr/ # Format: multiaddress; see https://multiformats.io/multiaddr/

View File

@ -23,6 +23,12 @@
#DisableMetadataLog = false #DisableMetadataLog = false
[Logging]
[Logging.SubsystemLevels]
# env var: LOTUS_LOGGING_SUBSYSTEMLEVELS_EXAMPLE-SUBSYSTEM
#example-subsystem = "INFO"
[Libp2p] [Libp2p]
# Binding address for the libp2p host - 0 means random port. # Binding address for the libp2p host - 0 means random port.
# Format: multiaddress; see https://multiformats.io/multiaddr/ # Format: multiaddress; see https://multiformats.io/multiaddr/

11
lib/lotuslog/config.go Normal file
View File

@ -0,0 +1,11 @@
package lotuslog
import logging "github.com/ipfs/go-log/v2"
func SetLevelsFromConfig(l map[string]string) {
for sys, level := range l {
if err := logging.SetLogLevel(sys, level); err != nil {
continue
}
}
}

View File

@ -33,6 +33,7 @@ import (
"github.com/filecoin-project/lotus/extern/sector-storage/stores" "github.com/filecoin-project/lotus/extern/sector-storage/stores"
"github.com/filecoin-project/lotus/journal" "github.com/filecoin-project/lotus/journal"
"github.com/filecoin-project/lotus/journal/alerting" "github.com/filecoin-project/lotus/journal/alerting"
"github.com/filecoin-project/lotus/lib/lotuslog"
"github.com/filecoin-project/lotus/lib/peermgr" "github.com/filecoin-project/lotus/lib/peermgr"
_ "github.com/filecoin-project/lotus/lib/sigs/bls" _ "github.com/filecoin-project/lotus/lib/sigs/bls"
_ "github.com/filecoin-project/lotus/lib/sigs/secp" _ "github.com/filecoin-project/lotus/lib/sigs/secp"
@ -249,6 +250,9 @@ func Base() Option {
// Config sets up constructors based on the provided Config // Config sets up constructors based on the provided Config
func ConfigCommon(cfg *config.Common, enableLibp2pNode bool) Option { func ConfigCommon(cfg *config.Common, enableLibp2pNode bool) Option {
// setup logging early
lotuslog.SetLevelsFromConfig(cfg.Logging.SubsystemLevels)
return Options( return Options(
func(s *Settings) error { s.Config = true; return nil }, func(s *Settings) error { s.Config = true; return nil },
Override(new(dtypes.APIEndpoint), func() (dtypes.APIEndpoint, error) { Override(new(dtypes.APIEndpoint), func() (dtypes.APIEndpoint, error) {

View File

@ -47,6 +47,11 @@ func defCommon() Common {
ListenAddress: "/ip4/127.0.0.1/tcp/1234/http", ListenAddress: "/ip4/127.0.0.1/tcp/1234/http",
Timeout: Duration(30 * time.Second), Timeout: Duration(30 * time.Second),
}, },
Logging: Logging{
SubsystemLevels: map[string]string{
"example-subsystem": "INFO",
},
},
Libp2p: Libp2p{ Libp2p: Libp2p{
ListenAddresses: []string{ ListenAddresses: []string{
"/ip4/0.0.0.0/tcp/0", "/ip4/0.0.0.0/tcp/0",

View File

@ -32,6 +32,24 @@ func TestDefaultFullNodeRoundtrip(t *testing.T) {
require.True(t, reflect.DeepEqual(c, c2)) require.True(t, reflect.DeepEqual(c, c2))
} }
func TestDefaultFullNodeCommentRoundtrip(t *testing.T) {
c := DefaultFullNode()
var s string
{
c, err := ConfigComment(DefaultFullNode())
require.NoError(t, err)
s = string(c)
}
c2, err := FromReader(strings.NewReader(s), DefaultFullNode())
require.NoError(t, err)
fmt.Println(s)
require.True(t, reflect.DeepEqual(c, c2))
}
func TestDefaultMinerRoundtrip(t *testing.T) { func TestDefaultMinerRoundtrip(t *testing.T) {
c := DefaultStorageMiner() c := DefaultStorageMiner()

View File

@ -127,6 +127,12 @@ of automatically performing on-chain operations.`,
Comment: ``, Comment: ``,
}, },
{
Name: "Logging",
Type: "Logging",
Comment: ``,
},
{ {
Name: "Libp2p", Name: "Libp2p",
Type: "Libp2p", Type: "Libp2p",
@ -484,6 +490,14 @@ count towards this limit.`,
closed by the connection manager.`, closed by the connection manager.`,
}, },
}, },
"Logging": []DocField{
{
Name: "SubsystemLevels",
Type: "map[string]string",
Comment: `SubsystemLevels specify per-subsystem log levels`,
},
},
"MinerAddressConfig": []DocField{ "MinerAddressConfig": []DocField{
{ {
Name: "PreCommitControl", Name: "PreCommitControl",

View File

@ -16,7 +16,7 @@ func findDoc(root interface{}, section, name string) *DocField {
return findDocSect("Common", section, name) return findDocSect("Common", section, name)
} }
func findDocSect(root string, section, name string) *DocField { func findDocSect(root, section, name string) *DocField {
path := strings.Split(section, ".") path := strings.Split(section, ".")
docSection := Doc[root] docSection := Doc[root]

View File

@ -69,7 +69,7 @@ func ConfigUpdate(cfgCur, cfgDef interface{}, comment bool) ([]byte, error) {
} }
if comment { if comment {
// create a map of default lines so we can comment those out later // create a map of default lines, so we can comment those out later
defLines := strings.Split(defStr, "\n") defLines := strings.Split(defStr, "\n")
defaults := map[string]struct{}{} defaults := map[string]struct{}{}
for i := range defLines { for i := range defLines {

View File

@ -15,6 +15,7 @@ import (
type Common struct { type Common struct {
API API API API
Backup Backup Backup Backup
Logging Logging
Libp2p Libp2p Libp2p Libp2p
Pubsub Pubsub Pubsub Pubsub
} }
@ -39,6 +40,12 @@ type Backup struct {
DisableMetadataLog bool DisableMetadataLog bool
} }
// Logging is the logging system config
type Logging struct {
// SubsystemLevels specify per-subsystem log levels
SubsystemLevels map[string]string
}
// StorageMiner is a miner config // StorageMiner is a miner config
type StorageMiner struct { type StorageMiner struct {
Common Common