use logrus for logging

This commit is contained in:
Taka Goto 2018-11-20 22:47:01 -06:00
parent 128d20c9bf
commit e8be96a4e7
57 changed files with 79 additions and 83 deletions

1
.gitignore vendored
View File

@ -11,3 +11,4 @@ vulcanizedb
postgraphile/build/
postgraphile/node_modules/
postgraphile/package-lock.json
vulcanizedb.log

View File

@ -41,6 +41,10 @@
branch = "master"
name = "github.com/lib/pq"
[[constraint]]
name = "gopkg.in/Sirupsen/logrus.v1"
version = "1.2.0"
[[constraint]]
name = "github.com/spf13/cobra"
version = "0.0.1"

View File

@ -18,6 +18,7 @@ Vulcanize DB is a set of tools that make it easier for developers to write appli
## Installation
`go get github.com/vulcanize/vulcanizedb`
`go get gopkg.in/DataDog/dd-trace-go.v1/ddtrace`
`go get gopkg.in/Sirupsen/logrus.v1`
## Setting up the Database
1. Install Postgres

View File

@ -15,8 +15,7 @@
package cmd
import (
"log"
log "github.com/sirupsen/logrus"
"github.com/spf13/cobra"
"github.com/vulcanize/vulcanizedb/libraries/shared"

View File

@ -15,8 +15,7 @@
package cmd
import (
"log"
log "github.com/sirupsen/logrus"
"github.com/spf13/cobra"
"github.com/vulcanize/vulcanizedb/pkg/crypto"

View File

@ -16,9 +16,9 @@ package cmd
import (
"fmt"
"log"
"time"
log "github.com/sirupsen/logrus"
"github.com/spf13/cobra"
"github.com/vulcanize/vulcanizedb/libraries/shared"

View File

@ -15,9 +15,9 @@
package cmd
import (
"log"
"time"
log "github.com/sirupsen/logrus"
"github.com/spf13/cobra"
"github.com/vulcanize/vulcanizedb/examples/erc20_watcher/every_block"

View File

@ -15,9 +15,9 @@
package cmd
import (
log "github.com/sirupsen/logrus"
"github.com/spf13/cobra"
"github.com/vulcanize/vulcanizedb/pkg/transformers/shared/constants"
"log"
)
// getSignaturesCmd represents the getSignatures command

View File

@ -15,10 +15,10 @@
package cmd
import (
"log"
"os"
"time"
log "github.com/sirupsen/logrus"
"github.com/spf13/cobra"
"github.com/vulcanize/vulcanizedb/pkg/core"

View File

@ -15,13 +15,12 @@
package cmd
import (
"fmt"
"log"
"os"
"time"
"github.com/ethereum/go-ethereum/rpc"
"github.com/mitchellh/go-homedir"
log "github.com/sirupsen/logrus"
"github.com/spf13/cobra"
"github.com/spf13/viper"
@ -55,7 +54,7 @@ var rootCmd = &cobra.Command{
func Execute() {
if err := rootCmd.Execute(); err != nil {
fmt.Println(err)
log.Fatal(err)
os.Exit(1)
}
}
@ -102,7 +101,7 @@ func initConfig() {
} else {
home, err := homedir.Dir()
if err != nil {
fmt.Println(err)
log.Fatal(err)
os.Exit(1)
}
@ -113,7 +112,7 @@ func initConfig() {
viper.AutomaticEnv()
if err := viper.ReadInConfig(); err == nil {
fmt.Printf("Using config file: %s\n\n", viper.ConfigFileUsed())
log.Printf("Using config file: %s\n\n", viper.ConfigFileUsed())
}
}

View File

@ -15,10 +15,10 @@
package cmd
import (
"log"
"os"
"time"
log "github.com/sirupsen/logrus"
"github.com/spf13/cobra"
"github.com/vulcanize/vulcanizedb/pkg/core"

View File

@ -1,19 +0,0 @@
[database]
name = "vulcanize_public"
hostname = "localhost"
port = 5432
[client]
ipcPath = "http://127.0.0.1:7545"
[contract]
cat = "0x2f34f22a00ee4b7a8f8bbc4eaee1658774c624e0"
drip = "0x891c04639a5edcae088e546fa125b5d7fb6a2b9d"
eth_flip = "0x32D496Ad866D110060866B7125981C73642cc509"
mcd_flap = "0x8868BAd8e74FcA4505676D1B5B21EcC23328d132"
mcd_flop = "0x6191C9b0086c2eBF92300cC507009b53996FbFFa"
pep = "0xB1997239Cfc3d15578A3a09730f7f84A90BB4975"
pip = "0x9FfFE440258B79c5d6604001674A4722FfC0f7Bc"
pit = "0xe7cf3198787c9a4daac73371a38f29aaeeced87e"
rep = "0xf88bBDc1E2718F8857F30A180076ec38d53cf296"
vat = "0xcd726790550afcd77e9a7a47e86a3f9010af126b"

View File

@ -19,8 +19,8 @@ import (
. "github.com/onsi/ginkgo"
. "github.com/onsi/gomega"
log "github.com/sirupsen/logrus"
"io/ioutil"
"log"
)
func TestEveryBlock(t *testing.T) {

View File

@ -16,7 +16,7 @@ package every_block
import (
"fmt"
"log"
log "github.com/sirupsen/logrus"
"math/big"
"github.com/vulcanize/vulcanizedb/pkg/core"
@ -50,7 +50,7 @@ func (fe *fetcherError) Error() string {
func newFetcherError(err error, fetchMethod string) *fetcherError {
e := fetcherError{err.Error(), fetchMethod}
log.Println(e.Error())
log.Info(e.Error())
return &e
}

View File

@ -16,8 +16,8 @@ package every_block
import (
"fmt"
log "github.com/sirupsen/logrus"
"github.com/vulcanize/vulcanizedb/pkg/datastore/postgres"
"log"
)
type ERC20RepositoryInterface interface {

View File

@ -16,9 +16,10 @@ package every_block
import (
"fmt"
"log"
"math/big"
log "github.com/sirupsen/logrus"
"github.com/vulcanize/vulcanizedb/examples/erc20_watcher"
"github.com/vulcanize/vulcanizedb/pkg/core"
"github.com/vulcanize/vulcanizedb/pkg/datastore/postgres"

10
main.go
View File

@ -3,11 +3,21 @@ package main
import (
"github.com/vulcanize/vulcanizedb/cmd"
log "github.com/sirupsen/logrus"
"github.com/spf13/viper"
"gopkg.in/DataDog/dd-trace-go.v1/ddtrace/tracer"
"os"
)
func main() {
log.SetFormatter(&log.JSONFormatter{})
file, err := os.OpenFile("vulcanizedb.log", os.O_CREATE|os.O_WRONLY, 0666)
if err == nil {
log.SetOutput(file)
} else {
log.Info("Failed to log to file, using default stderr")
}
tracer.Start(tracer.WithServiceName(viper.GetString("datadog.name")))
cmd.Execute()

View File

@ -3,8 +3,8 @@ package postgres_test
import (
"testing"
log "github.com/sirupsen/logrus"
"io/ioutil"
"log"
. "github.com/onsi/ginkgo"
. "github.com/onsi/gomega"

View File

@ -4,7 +4,7 @@ import (
"context"
"database/sql"
"errors"
"log"
log "github.com/sirupsen/logrus"
"github.com/jmoiron/sqlx"

View File

@ -1,7 +1,7 @@
package testing
import (
"log"
log "github.com/sirupsen/logrus"
"github.com/vulcanize/vulcanizedb/pkg/core"
"github.com/vulcanize/vulcanizedb/pkg/geth"

View File

@ -4,8 +4,8 @@ import (
. "github.com/onsi/ginkgo"
. "github.com/onsi/gomega"
log "github.com/sirupsen/logrus"
"io/ioutil"
"log"
"testing"
)

View File

@ -1,7 +1,7 @@
package history
import (
"log"
log "github.com/sirupsen/logrus"
"github.com/vulcanize/vulcanizedb/pkg/core"
"github.com/vulcanize/vulcanizedb/pkg/datastore"
@ -11,7 +11,6 @@ import (
func PopulateMissingHeaders(blockchain core.BlockChain, headerRepository datastore.HeaderRepository, startingBlockNumber int64) (int, error) {
lastBlock := blockchain.LastBlock().Int64()
blockRange := headerRepository.MissingBlockNumbers(startingBlockNumber, lastBlock, blockchain.Node().ID)
log.SetPrefix("")
log.Printf("Backfilling %d blocks\n\n", len(blockRange))
_, err := RetrieveAndUpdateHeaders(blockchain, headerRepository, blockRange)
if err != nil {

View File

@ -19,8 +19,8 @@ import (
. "github.com/onsi/ginkgo"
. "github.com/onsi/gomega"
log "github.com/sirupsen/logrus"
"io/ioutil"
"log"
)
func TestBite(t *testing.T) {

View File

@ -15,8 +15,8 @@
package chop_lump_test
import (
log "github.com/sirupsen/logrus"
"io/ioutil"
"log"
"testing"
. "github.com/onsi/ginkgo"

View File

@ -15,8 +15,8 @@
package flip_test
import (
log "github.com/sirupsen/logrus"
"io/ioutil"
"log"
"testing"
. "github.com/onsi/ginkgo"

View File

@ -15,8 +15,8 @@
package pit_vow_test
import (
log "github.com/sirupsen/logrus"
"io/ioutil"
"log"
"testing"
. "github.com/onsi/ginkgo"

View File

@ -5,8 +5,8 @@ import (
. "github.com/onsi/ginkgo"
. "github.com/onsi/gomega"
log "github.com/sirupsen/logrus"
"io/ioutil"
"log"
)
func TestFlipDeal(t *testing.T) {

View File

@ -5,8 +5,8 @@ import (
. "github.com/onsi/ginkgo"
. "github.com/onsi/gomega"
log "github.com/sirupsen/logrus"
"io/ioutil"
"log"
)
func TestDent(t *testing.T) {

View File

@ -15,8 +15,8 @@
package drip_drip_test
import (
log "github.com/sirupsen/logrus"
"io/ioutil"
"log"
"testing"
. "github.com/onsi/ginkgo"

View File

@ -15,8 +15,8 @@
package ilk_test
import (
log "github.com/sirupsen/logrus"
"io/ioutil"
"log"
"testing"
. "github.com/onsi/ginkgo"

View File

@ -15,8 +15,8 @@
package repo_test
import (
log "github.com/sirupsen/logrus"
"io/ioutil"
"log"
"testing"
. "github.com/onsi/ginkgo"

View File

@ -15,8 +15,8 @@
package vow_test
import (
log "github.com/sirupsen/logrus"
"io/ioutil"
"log"
"testing"
. "github.com/onsi/ginkgo"

View File

@ -5,8 +5,8 @@ import (
. "github.com/onsi/ginkgo"
. "github.com/onsi/gomega"
log "github.com/sirupsen/logrus"
"io/ioutil"
"log"
)
func TestFactories(t *testing.T) {

View File

@ -15,7 +15,7 @@
package factories
import (
"log"
log "github.com/sirupsen/logrus"
"github.com/ethereum/go-ethereum/common"
@ -41,7 +41,7 @@ func (transformer LogNoteTransformer) Execute() error {
transformerName := transformer.Config.TransformerName
missingHeaders, err := transformer.Repository.MissingHeaders(transformer.Config.StartingBlockNumber, transformer.Config.EndingBlockNumber)
if err != nil {
log.Printf("Error fetching mising headers in %v transformer: %v \n", transformerName, err)
log.Printf("Error fetching mising headers in %v transformer: %v", transformerName, err)
return err
}
@ -49,7 +49,7 @@ func (transformer LogNoteTransformer) Execute() error {
// (Double-array structure required for go-ethereum FilterQuery)
var topic = [][]common.Hash{{common.HexToHash(transformer.Config.Topic)}}
log.Printf("Fetching %v event logs for %d headers \n", transformerName, len(missingHeaders))
log.Printf("Fetching %v event logs for %d headers", transformerName, len(missingHeaders))
for _, header := range missingHeaders {
// Fetch the missing logs for a given header
matchingLogs, err := transformer.Fetcher.FetchLogs(transformer.Config.ContractAddresses, topic, header)

View File

@ -15,7 +15,7 @@
package factories
import (
"log"
log "github.com/sirupsen/logrus"
"github.com/ethereum/go-ethereum/common"

View File

@ -15,8 +15,8 @@
package flap_kick_test
import (
log "github.com/sirupsen/logrus"
"io/ioutil"
"log"
"testing"
. "github.com/onsi/ginkgo"

View File

@ -15,8 +15,8 @@
package flip_kick
import (
log "github.com/sirupsen/logrus"
"io/ioutil"
"log"
"testing"
. "github.com/onsi/ginkgo"

View File

@ -18,6 +18,7 @@ import (
"bytes"
"encoding/json"
"fmt"
log "github.com/sirupsen/logrus"
"github.com/ethereum/go-ethereum/accounts/abi/bind"
"github.com/ethereum/go-ethereum/common"
@ -30,6 +31,7 @@ type FrobConverter struct{}
func (FrobConverter) ToEntities(contractAbi string, ethLogs []types.Log) ([]interface{}, error) {
var entities []interface{}
log.Info("blah")
for _, ethLog := range ethLogs {
entity := FrobEntity{}
address := ethLog.Address

View File

@ -15,8 +15,8 @@
package frob_test
import (
log "github.com/sirupsen/logrus"
"io/ioutil"
"log"
"testing"
. "github.com/onsi/ginkgo"

View File

@ -1,7 +1,7 @@
package integration_tests
import (
"log"
log "github.com/sirupsen/logrus"
"testing"
. "github.com/onsi/ginkgo"

View File

@ -33,13 +33,13 @@ var _ = Describe("VowFlog LogNoteTransformer", func() {
rpcClient, ethClient, err := getClients(ipc)
Expect(err).NotTo(HaveOccurred())
blockchain, err := getBlockChain(rpcClient, ethClient)
blockChain, err := getBlockChain(rpcClient, ethClient)
Expect(err).NotTo(HaveOccurred())
db := test_config.NewTestDB(blockchain.Node())
db := test_config.NewTestDB(blockChain.Node())
test_config.CleanTestDB(db)
err = persistHeader(db, blockNumber, blockchain)
err = persistHeader(db, blockNumber, blockChain)
Expect(err).NotTo(HaveOccurred())
Expect(1).To(Equal(1))
@ -49,7 +49,7 @@ var _ = Describe("VowFlog LogNoteTransformer", func() {
Converter: &vow_flog.VowFlogConverter{},
Repository: &vow_flog.VowFlogRepository{},
}
transformer := initializer.NewLogNoteTransformer(db, blockchain)
transformer := initializer.NewLogNoteTransformer(db, blockChain)
err = transformer.Execute()
Expect(err).NotTo(HaveOccurred())

View File

@ -15,8 +15,8 @@
package debt_ceiling_test
import (
log "github.com/sirupsen/logrus"
"io/ioutil"
"log"
"testing"
. "github.com/onsi/ginkgo"

View File

@ -15,8 +15,8 @@
package ilk_test
import (
log "github.com/sirupsen/logrus"
"io/ioutil"
"log"
"testing"
. "github.com/onsi/ginkgo"

View File

@ -15,8 +15,8 @@
package price_feeds_test
import (
log "github.com/sirupsen/logrus"
"io/ioutil"
"log"
"testing"
. "github.com/onsi/ginkgo"

View File

@ -1,8 +1,8 @@
package tend_test
import (
log "github.com/sirupsen/logrus"
"io/ioutil"
"log"
"testing"
. "github.com/onsi/ginkgo"

View File

@ -1,8 +1,8 @@
package vat_flux_test
import (
log "github.com/sirupsen/logrus"
"io/ioutil"
"log"
"testing"
. "github.com/onsi/ginkgo"

View File

@ -1,8 +1,8 @@
package vat_fold_test
import (
log "github.com/sirupsen/logrus"
"io/ioutil"
"log"
"testing"
. "github.com/onsi/ginkgo"

View File

@ -1,8 +1,8 @@
package vat_grab_test
import (
log "github.com/sirupsen/logrus"
"io/ioutil"
"log"
"testing"
. "github.com/onsi/ginkgo"

View File

@ -1,8 +1,8 @@
package vat_heal_test
import (
log "github.com/sirupsen/logrus"
"io/ioutil"
"log"
"testing"
. "github.com/onsi/ginkgo"

View File

@ -15,8 +15,8 @@
package vat_init_test
import (
log "github.com/sirupsen/logrus"
"io/ioutil"
"log"
"testing"
. "github.com/onsi/ginkgo"

View File

@ -15,8 +15,8 @@
package vat_move_test
import (
log "github.com/sirupsen/logrus"
"io/ioutil"
"log"
"testing"
. "github.com/onsi/ginkgo"

View File

@ -19,8 +19,8 @@ import (
. "github.com/onsi/ginkgo"
. "github.com/onsi/gomega"
log "github.com/sirupsen/logrus"
"io/ioutil"
"log"
)
func TestVatSlip(t *testing.T) {

View File

@ -5,8 +5,8 @@ import (
. "github.com/onsi/ginkgo"
. "github.com/onsi/gomega"
log "github.com/sirupsen/logrus"
"io/ioutil"
"log"
)
func TestVatToll(t *testing.T) {

View File

@ -5,8 +5,8 @@ import (
. "github.com/onsi/ginkgo"
. "github.com/onsi/gomega"
log "github.com/sirupsen/logrus"
"io/ioutil"
"log"
)
func TestVatTune(t *testing.T) {

View File

@ -19,8 +19,8 @@ import (
. "github.com/onsi/ginkgo"
. "github.com/onsi/gomega"
log "github.com/sirupsen/logrus"
"io/ioutil"
"log"
)
func TestVowFlog(t *testing.T) {

View File

@ -1,7 +1,7 @@
package test_config
import (
"log"
log "github.com/sirupsen/logrus"
"os"
. "github.com/onsi/gomega"

View File

@ -1,7 +1,7 @@
package utils
import (
"log"
log "github.com/sirupsen/logrus"
"path/filepath"