log: use native log/slog instead of golang/exp (#29302)

This commit is contained in:
Daniel Liu 2024-11-15 10:02:42 +08:00
parent 40fd68a124
commit 946c085f9f
11 changed files with 13 additions and 16 deletions

View file

@ -23,6 +23,7 @@ package debug
import ( import (
"errors" "errors"
"io" "io"
"log/slog"
"os" "os"
"os/user" "os/user"
"path/filepath" "path/filepath"
@ -35,7 +36,6 @@ import (
"time" "time"
"github.com/XinFinOrg/XDPoSChain/log" "github.com/XinFinOrg/XDPoSChain/log"
"golang.org/x/exp/slog"
) )
// Handler is the global debugging handler. // Handler is the global debugging handler.

View file

@ -19,6 +19,7 @@ package debug
import ( import (
"fmt" "fmt"
"io" "io"
"log/slog"
"net/http" "net/http"
_ "net/http/pprof" _ "net/http/pprof"
"os" "os"
@ -30,7 +31,6 @@ import (
"github.com/XinFinOrg/XDPoSChain/metrics/exp" "github.com/XinFinOrg/XDPoSChain/metrics/exp"
"github.com/mattn/go-colorable" "github.com/mattn/go-colorable"
"github.com/mattn/go-isatty" "github.com/mattn/go-isatty"
"golang.org/x/exp/slog"
"gopkg.in/natefinch/lumberjack.v2" "gopkg.in/natefinch/lumberjack.v2"
"gopkg.in/urfave/cli.v1" "gopkg.in/urfave/cli.v1"
) )

View file

@ -21,11 +21,11 @@ import (
"bytes" "bytes"
"context" "context"
"fmt" "fmt"
"log/slog"
"sync" "sync"
"testing" "testing"
"github.com/XinFinOrg/XDPoSChain/log" "github.com/XinFinOrg/XDPoSChain/log"
"golang.org/x/exp/slog"
) )
const ( const (

View file

@ -3,6 +3,7 @@ package log
import ( import (
"bytes" "bytes"
"fmt" "fmt"
"log/slog"
"math/big" "math/big"
"reflect" "reflect"
"strconv" "strconv"
@ -10,7 +11,6 @@ import (
"unicode/utf8" "unicode/utf8"
"github.com/holiman/uint256" "github.com/holiman/uint256"
"golang.org/x/exp/slog"
) )
const ( const (

View file

@ -4,13 +4,13 @@ import (
"context" "context"
"fmt" "fmt"
"io" "io"
"log/slog"
"math/big" "math/big"
"reflect" "reflect"
"sync" "sync"
"time" "time"
"github.com/holiman/uint256" "github.com/holiman/uint256"
"golang.org/x/exp/slog"
) )
type discardHandler struct{} type discardHandler struct{}

View file

@ -20,14 +20,13 @@ import (
"context" "context"
"errors" "errors"
"fmt" "fmt"
"log/slog"
"regexp" "regexp"
"runtime" "runtime"
"strconv" "strconv"
"strings" "strings"
"sync" "sync"
"sync/atomic" "sync/atomic"
"golang.org/x/exp/slog"
) )
// errVmoduleSyntax is returned when a user vmodule pattern is invalid. // errVmoduleSyntax is returned when a user vmodule pattern is invalid.

View file

@ -2,12 +2,11 @@ package log
import ( import (
"context" "context"
"log/slog"
"math" "math"
"os" "os"
"runtime" "runtime"
"time" "time"
"golang.org/x/exp/slog"
) )
const errorKey = "LOG_ERROR" const errorKey = "LOG_ERROR"

View file

@ -5,6 +5,7 @@ import (
"errors" "errors"
"fmt" "fmt"
"io" "io"
"log/slog"
"math/big" "math/big"
"os" "os"
"strings" "strings"
@ -12,7 +13,6 @@ import (
"time" "time"
"github.com/holiman/uint256" "github.com/holiman/uint256"
"golang.org/x/exp/slog"
) )
// TestLoggingWithVmodule checks that vmodule works. // TestLoggingWithVmodule checks that vmodule works.

View file

@ -2,10 +2,9 @@ package log
import ( import (
"context" "context"
"log/slog"
"os" "os"
"sync/atomic" "sync/atomic"
"golang.org/x/exp/slog"
) )
var root atomic.Value var root atomic.Value

View file

@ -24,6 +24,7 @@ import (
"errors" "errors"
"fmt" "fmt"
"io" "io"
"log/slog"
"net" "net"
"os" "os"
"os/exec" "os/exec"
@ -42,7 +43,6 @@ import (
"github.com/XinFinOrg/XDPoSChain/rpc" "github.com/XinFinOrg/XDPoSChain/rpc"
"github.com/docker/docker/pkg/reexec" "github.com/docker/docker/pkg/reexec"
"github.com/gorilla/websocket" "github.com/gorilla/websocket"
"golang.org/x/exp/slog"
) )
// ExecAdapter is a NodeAdapter which runs simulation nodes by executing the // ExecAdapter is a NodeAdapter which runs simulation nodes by executing the
@ -384,7 +384,7 @@ func initLogging() {
// and the node config from an environment variable. // and the node config from an environment variable.
func execP2PNode() { func execP2PNode() {
initLogging() initLogging()
// read the services from argv // read the services from argv
serviceNames := strings.Split(os.Args[1], ",") serviceNames := strings.Split(os.Args[1], ",")
@ -395,7 +395,7 @@ func execP2PNode() {
} }
var conf execNodeConfig var conf execNodeConfig
if err := json.Unmarshal([]byte(confEnv), &conf); err != nil { if err := json.Unmarshal([]byte(confEnv), &conf); err != nil {
log.Crit("error decoding " + envNodeConfig, "err", err) log.Crit("error decoding "+envNodeConfig, "err", err)
} }
conf.Stack.P2P.PrivateKey = conf.Node.PrivateKey conf.Stack.P2P.PrivateKey = conf.Node.PrivateKey
conf.Stack.Logger = log.New("node.id", conf.Node.ID.String()) conf.Stack.Logger = log.New("node.id", conf.Node.ID.String())

View file

@ -21,6 +21,7 @@ import (
"encoding/hex" "encoding/hex"
"encoding/json" "encoding/json"
"fmt" "fmt"
"log/slog"
"os" "os"
"github.com/XinFinOrg/XDPoSChain/crypto" "github.com/XinFinOrg/XDPoSChain/crypto"
@ -30,7 +31,6 @@ import (
"github.com/XinFinOrg/XDPoSChain/rpc" "github.com/XinFinOrg/XDPoSChain/rpc"
"github.com/docker/docker/pkg/reexec" "github.com/docker/docker/pkg/reexec"
"github.com/gorilla/websocket" "github.com/gorilla/websocket"
"golang.org/x/exp/slog"
) )
// Node represents a node in a simulation network which is created by a // Node represents a node in a simulation network which is created by a