Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: config: Persistent subsystem log level config #8283

Merged
merged 1 commit into from
Mar 10, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions documentation/en/default-lotus-config.toml
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,12 @@
#DisableMetadataLog = false


[Logging]
[Logging.SubsystemLevels]
# env var: LOTUS_LOGGING_SUBSYSTEMLEVELS_EXAMPLE-SUBSYSTEM
#example-subsystem = "INFO"


[Libp2p]
# Binding address for the libp2p host - 0 means random port.
# Format: multiaddress; see https://multiformats.io/multiaddr/
Expand Down
6 changes: 6 additions & 0 deletions documentation/en/default-lotus-miner-config.toml
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,12 @@
#DisableMetadataLog = false


[Logging]
[Logging.SubsystemLevels]
# env var: LOTUS_LOGGING_SUBSYSTEMLEVELS_EXAMPLE-SUBSYSTEM
#example-subsystem = "INFO"


[Libp2p]
# Binding address for the libp2p host - 0 means random port.
# Format: multiaddress; see https://multiformats.io/multiaddr/
Expand Down
11 changes: 11 additions & 0 deletions lib/lotuslog/config.go
Original file line number Diff line number Diff line change
@@ -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
}
}
}
4 changes: 4 additions & 0 deletions node/builder.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ import (
"github.com/filecoin-project/lotus/extern/sector-storage/stores"
"github.com/filecoin-project/lotus/journal"
"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/sigs/bls"
_ "github.com/filecoin-project/lotus/lib/sigs/secp"
Expand Down Expand Up @@ -249,6 +250,9 @@ func Base() Option {

// Config sets up constructors based on the provided Config
func ConfigCommon(cfg *config.Common, enableLibp2pNode bool) Option {
// setup logging early
lotuslog.SetLevelsFromConfig(cfg.Logging.SubsystemLevels)

return Options(
func(s *Settings) error { s.Config = true; return nil },
Override(new(dtypes.APIEndpoint), func() (dtypes.APIEndpoint, error) {
Expand Down
5 changes: 5 additions & 0 deletions node/config/def.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,11 @@ func defCommon() Common {
ListenAddress: "/ip4/127.0.0.1/tcp/1234/http",
Timeout: Duration(30 * time.Second),
},
Logging: Logging{
SubsystemLevels: map[string]string{
"example-subsystem": "INFO",
},
},
Libp2p: Libp2p{
ListenAddresses: []string{
"/ip4/0.0.0.0/tcp/0",
Expand Down
18 changes: 18 additions & 0 deletions node/config/def_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,24 @@ func TestDefaultFullNodeRoundtrip(t *testing.T) {
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) {
c := DefaultStorageMiner()

Expand Down
14 changes: 14 additions & 0 deletions node/config/doc_gen.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion node/config/doc_util.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ func findDoc(root interface{}, section, name string) *DocField {
return findDocSect("Common", section, name)
}

func findDocSect(root string, section, name string) *DocField {
func findDocSect(root, section, name string) *DocField {
path := strings.Split(section, ".")

docSection := Doc[root]
Expand Down
2 changes: 1 addition & 1 deletion node/config/load.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ func ConfigUpdate(cfgCur, cfgDef interface{}, comment bool) ([]byte, error) {
}

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")
defaults := map[string]struct{}{}
for i := range defLines {
Expand Down
15 changes: 11 additions & 4 deletions node/config/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,11 @@ import (

// Common is common config between full node and miner
type Common struct {
API API
Backup Backup
Libp2p Libp2p
Pubsub Pubsub
API API
Backup Backup
Logging Logging
Libp2p Libp2p
Pubsub Pubsub
}

// FullNode is a full node config
Expand All @@ -39,6 +40,12 @@ type Backup struct {
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
type StorageMiner struct {
Common
Expand Down