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

configurable logs #31

Merged
merged 1 commit into from
Sep 21, 2023
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
2 changes: 1 addition & 1 deletion cmd/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ func runServer(*cli.Context) error {
log.Info(">> App begin")

// Create stream server
s, err := datastreamer.New(6900, StSequencer, "streamfile.bin")
s, err := datastreamer.New(6900, StSequencer, "streamfile.bin", nil)
if err != nil {
os.Exit(1)
}
Expand Down
4 changes: 4 additions & 0 deletions datastreamer/config.go
Original file line number Diff line number Diff line change
@@ -1,8 +1,12 @@
package datastreamer

import "github.com/0xPolygonHermez/zkevm-data-streamer/log"

type Config struct {
// Port to listen on
Port uint16 `mapstructure:"Port"`
// Filename of the binary data file
Filename string `mapstructure:"Filename"`
// Log
Log log.Config `mapstructure:"Logs"`
}
7 changes: 6 additions & 1 deletion datastreamer/streamserver.go
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ type ResultEntry struct {
errorStr []byte
}

func New(port uint16, streamType StreamType, fileName string) (StreamServer, error) {
func New(port uint16, streamType StreamType, fileName string, cfg *log.Config) (StreamServer, error) {
// Create the server data stream
s := StreamServer{
port: port,
Expand Down Expand Up @@ -136,6 +136,11 @@ func New(port uint16, streamType StreamType, fileName string) (StreamServer, err
// Initialize the data entry number
s.nextEntry = s.sf.header.TotalEntries

// Initialize the logger
if cfg != nil {
log.Init(*cfg)
}

return s, nil
}

Expand Down
1 change: 0 additions & 1 deletion tool/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ const (
type Config struct {
StreamServer datastreamer.Config `mapstructure:"StreamServer"`
StateDB db.Config `mapstructure:"StateDB"`
LogConfig log.Config `mapstructure:"Log"`
}

// Default parses the default configuration values.
Expand Down
4 changes: 4 additions & 0 deletions tool/config/default.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,10 @@ const DefaultValues = `
[StreamServer]
Port = 8080
Filename = "datastreamer.bin"
[Log]
Environment = "development" # "production" or "development"
Level = "info"
Outputs = ["stderr"]

[StateDB]
User = "state_user"
Expand Down
9 changes: 4 additions & 5 deletions tool/config/tool.config.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@
[StreamServer]
Port = 6900
Filename = "streamfile.bin"
[Log]
Environment = "development"
Level = "info"
Outputs = ["stdout"]

[StateDB]
User = "state_user"
Expand All @@ -11,8 +15,3 @@ Host = "localhost"
Port = "5432"
EnableLog = false
MaxConns = 200

[Log]
Environment = "development"
Level = "info"
Outputs = ["stdout"]
4 changes: 2 additions & 2 deletions tool/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,11 +68,11 @@ func start(cliCtx *cli.Context) error {
log.Infof("Loaded configuration: %+v", c)

// Init logger
log.Init(c.LogConfig)
log.Init(c.StreamServer.Log)
log.Info("Starting tool")

// Create a stream server
streamServer, err := datastreamer.New(c.StreamServer.Port, db.StreamTypeSequencer, c.StreamServer.Filename)
streamServer, err := datastreamer.New(c.StreamServer.Port, db.StreamTypeSequencer, c.StreamServer.Filename, &c.StreamServer.Log)
if err != nil {
log.Fatal(err)
}
Expand Down