Skip to content

Commit

Permalink
cleanup logging syntax
Browse files Browse the repository at this point in the history
  • Loading branch information
rocketbitz committed Nov 1, 2018
1 parent 524f72f commit 2d0417c
Show file tree
Hide file tree
Showing 30 changed files with 196 additions and 196 deletions.
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ plugins:
$(MAKE) -C contrib/bitmexfeeder
$(MAKE) -C contrib/binancefeeder

unittest:
unittest: all
go fmt ./...
go test ./...
$(MAKE) -C tests/integ test
Expand Down
4 changes: 2 additions & 2 deletions cmd/connect/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import (
"errors"

"github.com/alpacahq/marketstore/cmd/connect/session"
. "github.com/alpacahq/marketstore/utils/log"
"github.com/alpacahq/marketstore/utils/log"
"github.com/spf13/cobra"
)

Expand Down Expand Up @@ -94,6 +94,6 @@ func executeConnect(cmd *cobra.Command, args []string) error {
return err
}

Log(INFO, "closed connection")
log.Info("closed connection")
return nil
}
2 changes: 1 addition & 1 deletion cmd/connect/session/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,9 @@ import (
"strings"
"time"

"github.com/alpacahq/marketstore/sqlparser"
"github.com/alpacahq/marketstore/executor"
"github.com/alpacahq/marketstore/frontend/client"
"github.com/alpacahq/marketstore/sqlparser"
"github.com/alpacahq/marketstore/utils"
dbio "github.com/alpacahq/marketstore/utils/io"
"github.com/chzyer/readline"
Expand Down
8 changes: 4 additions & 4 deletions cmd/connect/session/gap.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import (

"github.com/alpacahq/marketstore/executor"
"github.com/alpacahq/marketstore/planner"
. "github.com/alpacahq/marketstore/utils/log"
"github.com/alpacahq/marketstore/utils/log"
)

// findGaps finds gaps in data in the date range.
Expand All @@ -27,18 +27,18 @@ func (c *Client) findGaps(line string) {

pr, err := query.Parse()
if err != nil {
Log(ERROR, "Parsing query: %v", err)
log.Error("Parsing query: %v", err)
os.Exit(1)
}

scanner, err := executor.NewReader(pr)
if err != nil {
Log(ERROR, "Error return from query scanner: %v", err)
log.Error("Error return from query scanner: %v", err)
return
}
csm, _, err := scanner.Read()
if err != nil {
Log(ERROR, "Error return from query scanner: %v", err)
log.Error("Error return from query scanner: %v", err)
return
}

Expand Down
10 changes: 5 additions & 5 deletions cmd/connect/session/show.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import (
"github.com/alpacahq/marketstore/frontend"
"github.com/alpacahq/marketstore/planner"
"github.com/alpacahq/marketstore/utils/io"
. "github.com/alpacahq/marketstore/utils/log"
"github.com/alpacahq/marketstore/utils/log"
)

// show displays data in the date range.
Expand Down Expand Up @@ -85,18 +85,18 @@ func processShowLocal(tbk *io.TimeBucketKey, start, end *time.Time) (csm io.Colu
pr, err := query.Parse()
if err != nil {
fmt.Println("No results")
Log(ERROR, "Parsing query: %v", err)
log.Error("Parsing query: %v", err)
return
}

scanner, err := executor.NewReader(pr)
if err != nil {
Log(ERROR, "Error return from query scanner: %v", err)
log.Error("Error return from query scanner: %v", err)
return
}
csm, _, err = scanner.Read()
if err != nil {
Log(ERROR, "Error return from query scanner: %v", err)
log.Error("Error return from query scanner: %v", err)
return
}

Expand Down Expand Up @@ -145,7 +145,7 @@ func (c *Client) parseQueryArgs(args []string) (tbk *io.TimeBucketKey, start, en
default:
t, err := parseTime(arg)
if err != nil {
Log(ERROR, "Invalid Symbol/Timeframe/recordFormat string %v", arg)
log.Error("Invalid Symbol/Timeframe/recordFormat string %v", arg)
fmt.Printf("Invalid time string %v\n", arg)
return nil, nil, nil
}
Expand Down
2 changes: 1 addition & 1 deletion cmd/connect/session/sql.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ import (
"fmt"
"time"

"github.com/alpacahq/marketstore/sqlparser"
"github.com/alpacahq/marketstore/frontend"
"github.com/alpacahq/marketstore/sqlparser"
"github.com/alpacahq/marketstore/utils/io"
)

Expand Down
8 changes: 4 additions & 4 deletions cmd/connect/session/trim.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,28 +7,28 @@ import (

"github.com/alpacahq/marketstore/executor"
"github.com/alpacahq/marketstore/utils/io"
. "github.com/alpacahq/marketstore/utils/log"
"github.com/alpacahq/marketstore/utils/log"
)

// trim removes the data in the date range from the db.
func (c *Client) trim(line string) {
Log(INFO, "Trimming...")
log.Info("Trimming...")
args := strings.Split(line, " ")
if len(args) < 3 {
fmt.Println("Not enough arguments - need \"trim key date\"")
return
}
trimDate, err := parseTime(args[len(args)-1])
if err != nil {
Log(ERROR, "Failed to parse trim date - Error: %v", trimDate)
log.Error("Failed to parse trim date - Error: %v", trimDate)
}
fInfos := executor.ThisInstance.CatalogDir.GatherTimeBucketInfo()
for _, info := range fInfos {
if info.Year == int16(trimDate.Year()) {
offset := io.TimeToOffset(trimDate, info.GetTimeframe(), info.GetRecordLength())
fp, err := os.OpenFile(info.Path, os.O_CREATE|os.O_RDWR, 0600)
if err != nil {
Log(ERROR, "Failed to open file %v - Error: %v", info.Path, err)
log.Error("Failed to open file %v - Error: %v", info.Path, err)
continue
}
fp.Seek(offset, os.SEEK_SET)
Expand Down
24 changes: 12 additions & 12 deletions cmd/start/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import (
"github.com/alpacahq/marketstore/frontend"
"github.com/alpacahq/marketstore/frontend/stream"
"github.com/alpacahq/marketstore/utils"
. "github.com/alpacahq/marketstore/utils/log"
"github.com/alpacahq/marketstore/utils/log"
"github.com/spf13/cobra"
)

Expand Down Expand Up @@ -58,7 +58,7 @@ func executeStart(cmd *cobra.Command, args []string) error {
}

// Log config location.
Log(INFO, "using %v for configuration", configFilePath)
log.Info("using %v for configuration", configFilePath)

// Attempt to set configuration.
err = utils.InstanceConfig.Parse(data)
Expand All @@ -72,12 +72,12 @@ func executeStart(cmd *cobra.Command, args []string) error {
for s := range signalChan {
switch s {
case syscall.SIGUSR1:
Log(INFO, "dumping stack traces due to SIGUSR1 request")
log.Info("dumping stack traces due to SIGUSR1 request")
pprof.Lookup("goroutine").WriteTo(os.Stdout, 1)
case syscall.SIGINT:
Log(INFO, "initiating graceful shutdown due to SIGINT request")
log.Info("initiating graceful shutdown due to SIGINT request")
atomic.StoreUint32(&frontend.Queryable, uint32(0))
Log(INFO, "waiting a grace period of %v to shutdown...", utils.InstanceConfig.StopGracePeriod)
log.Info("waiting a grace period of %v to shutdown...", utils.InstanceConfig.StopGracePeriod)
time.Sleep(utils.InstanceConfig.StopGracePeriod)
shutdown()
}
Expand All @@ -88,19 +88,19 @@ func executeStart(cmd *cobra.Command, args []string) error {

// Initialize marketstore services.
// --------------------------------
Log(INFO, "initializing marketstore...")
log.Info("initializing marketstore...")

//
executor.NewInstanceSetup(utils.InstanceConfig.RootDirectory, true, true, true)
// New server.
server, _ := frontend.NewServer()

// Set rpc handler.
Log(INFO, "launching rpc data server...")
log.Info("launching rpc data server...")
go http.Handle("/rpc", server)

// Set websocket handler.
Log(INFO, "initializing websocket...")
log.Info("initializing websocket...")
stream.Initialize()
go http.HandleFunc("/ws", stream.Handler)

Expand All @@ -109,14 +109,14 @@ func executeStart(cmd *cobra.Command, args []string) error {
RunBgWorkers()

// Start heartbeat.
Log(INFO, "launching heartbeat service...")
log.Info("launching heartbeat service...")
go frontend.Heartbeat(utils.InstanceConfig.ListenPort)

Log(INFO, "enabling query access...")
log.Info("enabling query access...")
atomic.StoreUint32(&frontend.Queryable, 1)

// Serve.
Log(INFO, "launching tcp listener for all services...")
log.Info("launching tcp listener for all services...")
if err := http.ListenAndServe(utils.InstanceConfig.ListenPort, nil); err != nil {
return fmt.Errorf("failed to start server - error: %s", err.Error())
}
Expand All @@ -127,6 +127,6 @@ func executeStart(cmd *cobra.Command, args []string) error {
func shutdown() {
executor.ThisInstance.ShutdownPending = true
executor.ThisInstance.WALWg.Wait()
Log(INFO, "exiting...")
log.Info("exiting...")
os.Exit(0)
}
20 changes: 10 additions & 10 deletions cmd/start/plugins.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,15 @@ import (
"github.com/alpacahq/marketstore/plugins/bgworker"
"github.com/alpacahq/marketstore/plugins/trigger"
"github.com/alpacahq/marketstore/utils"
. "github.com/alpacahq/marketstore/utils/log"
"github.com/alpacahq/marketstore/utils/log"
)

func InitializeTriggers() {
Log(INFO, "InitializeTriggers")
log.Info("InitializeTriggers")
config := utils.InstanceConfig
theInstance := executor.ThisInstance
for _, triggerSetting := range config.Triggers {
Log(INFO, "triggerSetting = %v", triggerSetting)
log.Info("triggerSetting = %v", triggerSetting)
tmatcher := NewTriggerMatcher(triggerSetting)
if tmatcher != nil {
theInstance.TriggerMatchers = append(
Expand All @@ -26,28 +26,28 @@ func InitializeTriggers() {
func NewTriggerMatcher(ts *utils.TriggerSetting) *trigger.TriggerMatcher {
loader, err := plugins.NewSymbolLoader(ts.Module)
if err != nil {
Log(ERROR, "Unable to open plugin for trigger in %s: %v", ts.Module, err)
log.Error("Unable to open plugin for trigger in %s: %v", ts.Module, err)
return nil
}
trig, err := trigger.Load(loader, ts.Config)
if err != nil {
Log(ERROR, "Error returned while creating a trigger: %v", err)
log.Error("Error returned while creating a trigger: %v", err)
return nil
}
return trigger.NewMatcher(trig, ts.On)
}

func RunBgWorkers() {
Log(INFO, "InitializeBgWorkers")
log.Info("InitializeBgWorkers")
config := utils.InstanceConfig
for _, bgWorkerSetting := range config.BgWorkers {
Log(INFO, "bgWorkerSetting = %v", bgWorkerSetting)
log.Info("bgWorkerSetting = %v", bgWorkerSetting)
bgWorker := NewBgWorker(bgWorkerSetting)
if bgWorker != nil {
// we should probably keep track of this process status
// and may want to kill it or get info. utils.Process may help
// but will figure it out later.
Log(INFO, "Start running BgWorker %s...", bgWorkerSetting.Name)
log.Info("Start running BgWorker %s...", bgWorkerSetting.Name)
go bgWorker.Run()
}
}
Expand All @@ -56,12 +56,12 @@ func RunBgWorkers() {
func NewBgWorker(s *utils.BgWorkerSetting) bgworker.BgWorker {
loader, err := plugins.NewSymbolLoader(s.Module)
if err != nil {
Log(ERROR, "Unable to open plugin for bgworker in %s: %v", s.Module, err)
log.Error("Unable to open plugin for bgworker in %s: %v", s.Module, err)
return nil
}
bgWorker, err := bgworker.Load(loader, s.Config)
if err != nil {
Log(ERROR, "Failed to create bgworker: %v", err)
log.Error("Failed to create bgworker: %v", err)
}
return bgWorker
}
18 changes: 9 additions & 9 deletions cmd/tool/integrity/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import (

"github.com/alpacahq/marketstore/planner"
"github.com/alpacahq/marketstore/utils/io"
. "github.com/alpacahq/marketstore/utils/log"
"github.com/alpacahq/marketstore/utils/log"
"github.com/spf13/cobra"
)

Expand Down Expand Up @@ -80,9 +80,9 @@ func init() {
}

if !parallel {
Log(INFO, "Running single threaded")
log.Info("Running single threaded")
} else {
Log(INFO, "Running in parallel")
log.Info("Running in parallel")
}

if yearEnd == 0 {
Expand All @@ -92,12 +92,12 @@ func init() {
monthEnd = 10000
} else {
if monthEnd < 1 || monthEnd > 12 {
Log(FATAL, "Ending month must be in the range 1-12")
log.Fatal("Ending month must be in the range 1-12")
}
}
if monthStart != 0 {
if monthStart < 1 || monthStart > 12 {
Log(FATAL, "Start month must be in the range 1-12")
log.Fatal("Start month must be in the range 1-12")
}
}

Expand Down Expand Up @@ -143,9 +143,9 @@ func init() {
// executeIntegrity implements the integrity tool.
func executeIntegrity(cmd *cobra.Command, args []string) error {

SetLogLevel(INFO)
log.SetLevel(log.INFO)

Log(INFO, "Root directory: %v", rootDirPath)
log.Info("Root directory: %v", rootDirPath)

// Perform integrity check.
return filepath.Walk(rootDirPath, cksumDataFiles)
Expand Down Expand Up @@ -249,11 +249,11 @@ func processChunk(myChunk int, offset int64, buffer []byte, fp *os.File, filenam
nread, err := fp.ReadAt(buffer, offset)
if err != nil {
if err.Error() != "EOF" {
Log(FATAL, "Error reading "+fp.Name()+": "+err.Error())
log.Fatal("Error reading " + fp.Name() + ": " + err.Error())
}
}
if nread == 0 {
Log(FATAL, "Short read "+fp.Name())
log.Fatal("Short read " + fp.Name())
}
// Align the checksum range to 8-bytes
sumRange := io.AlignedSize(nread)
Expand Down
5 changes: 3 additions & 2 deletions executor/errors.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,9 @@ package executor

import (
"fmt"

"github.com/alpacahq/marketstore/utils/io"
. "github.com/alpacahq/marketstore/utils/log"
"github.com/alpacahq/marketstore/utils/log"
)

type RecordLengthNotConsistent string
Expand Down Expand Up @@ -69,6 +70,6 @@ func (msg ShortReadError) Error() string {

func errReport(base string, msg string) string {
base = io.GetCallerFileContext(2) + ":" + base
Log(ERROR, base, msg)
log.Error(base, msg)
return fmt.Sprintf(base, msg)
}
Loading

0 comments on commit 2d0417c

Please sign in to comment.