Skip to content

Commit

Permalink
Merge pull request #60 from koinos/normalize-logs
Browse files Browse the repository at this point in the history
Normalize logs
  • Loading branch information
mvandeberg authored Oct 3, 2023
2 parents 8ecfda7 + 9291cc4 commit a5a4e5b
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 10 deletions.
28 changes: 19 additions & 9 deletions cmd/koinos-jsonrpc/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import (
"time"

jsonrpc "github.com/koinos/koinos-jsonrpc/internal"
log "github.com/koinos/koinos-log-golang"
log "github.com/koinos/koinos-log-golang/v2"
koinosmq "github.com/koinos/koinos-mq-golang"
"github.com/koinos/koinos-proto-golang/koinos"
"github.com/koinos/koinos-proto-golang/koinos/protocol"
Expand All @@ -34,6 +34,9 @@ const (
listenOption = "listen"
endpointOption = "endpoint"
logLevelOption = "log-level"
logDirOption = "log-dir"
logColorOption = "log-color"
logDatetimeOption = "log-datetime"
instanceIDOption = "instance-id"
descriptorsDirOption = "descriptors"
jobsOption = "jobs"
Expand All @@ -50,6 +53,8 @@ const (
listenDefault = "/ip4/127.0.0.1/tcp/8080"
endpointDefault = "/"
logLevelDefault = "info"
logColorDefault = true
logDatetimeDefault = true
descriptorsDirDefault = "descriptors"
jobsDefault = 16
gatewayTimeoutDefault = 3
Expand All @@ -58,7 +63,6 @@ const (

const (
appName = "jsonrpc"
logDir = "logs"
)

type Job struct {
Expand All @@ -69,7 +73,7 @@ type Job struct {
// Version display values
const (
DisplayAppName = "Koinos JSONRPC"
Version = "v1.0.0"
Version = "v1.1.0"
)

// Gets filled in by the linker
Expand All @@ -80,7 +84,10 @@ func main() {
amqp := flag.StringP(amqpOption, "a", "", "AMQP server URL")
listen := flag.StringP(listenOption, "L", "", "Multiaddr to listen on")
endpoint := flag.StringP(endpointOption, "e", "", "Http listen endpoint")
logLevel := flag.StringP(logLevelOption, "l", "", "The log filtering level (debug, info, warn, error)")
logLevel := flag.StringP(logLevelOption, "l", "", "The log filtering level (debug, info, warning, error)")
logDir := flag.String(logDirOption, "", "The logging directory")
logColor := flag.Bool(logColorOption, logColorDefault, "Log color toggle")
logDatetime := flag.Bool(logDatetimeOption, logDatetimeDefault, "Log datetime on console toggle")
instanceID := flag.StringP(instanceIDOption, "i", "", "The instance ID to identify this node")
descriptorsDir := flag.StringP(descriptorsDirOption, "D", "", "The directory containing protobuf descriptors for rpc message types")
jobs := flag.UintP(jobsOption, "j", jobsDefault, "Number of jobs")
Expand Down Expand Up @@ -109,20 +116,23 @@ func main() {
*listen = util.GetStringOption(listenOption, listenDefault, *listen, yamlConfig.JSONRPC)
*endpoint = util.GetStringOption(endpointOption, endpointDefault, *endpoint, yamlConfig.JSONRPC)
*logLevel = util.GetStringOption(logLevelOption, logLevelDefault, *logLevel, yamlConfig.JSONRPC, yamlConfig.Global)
*logDir = util.GetStringOption(logDirOption, *logDir, *logDir, yamlConfig.JSONRPC, yamlConfig.Global)
*logColor = util.GetBoolOption(logColorOption, logColorDefault, *logColor, yamlConfig.JSONRPC, yamlConfig.Global)
*logDatetime = util.GetBoolOption(logDatetimeOption, logDatetimeDefault, *logDatetime, yamlConfig.JSONRPC, yamlConfig.Global)
*instanceID = util.GetStringOption(instanceIDOption, util.GenerateBase58ID(5), *instanceID, yamlConfig.JSONRPC, yamlConfig.Global)
*descriptorsDir = util.GetStringOption(descriptorsDirOption, descriptorsDirDefault, *descriptorsDir, yamlConfig.JSONRPC, yamlConfig.Global)
*gatewayTimeout = util.GetIntOption(gatewayTimeoutOption, gatewayTimeoutDefault, *gatewayTimeout, yamlConfig.JSONRPC, yamlConfig.Global)
*mqTimeout = util.GetIntOption(mqTimeoutOption, mqTimeoutDefault, *mqTimeout, yamlConfig.JSONRPC, yamlConfig.Global)
*whitelist = util.GetStringSliceOption(whitelistOption, *whitelist, yamlConfig.JSONRPC, yamlConfig.Global)
*blacklist = util.GetStringSliceOption(blacklistOption, *blacklist, yamlConfig.JSONRPC, yamlConfig.Global)

appID := fmt.Sprintf("%s.%s", appName, *instanceID)
if len(*logDir) > 0 && !path.IsAbs(*logDir) {
*logDir = path.Join(util.GetAppDir(baseDir, appName), *logDir)
}

// Initialize logger
logFilename := path.Join(util.GetAppDir(baseDir, appName), logDir, "jsonrpc.log")
err = log.InitLogger(*logLevel, false, logFilename, appID)
err = log.InitLogger(appName, *instanceID, *logLevel, *logDir, *logColor, *logDatetime)
if err != nil {
panic(fmt.Sprintf("Invalid log-level: %s. Please choose one of: debug, info, warn, error", *logLevel))
panic(fmt.Sprintf("Invalid log-level: %s. Please choose one of: debug, info, warning, error", *logLevel))
}

log.Info(makeVersionString())
Expand Down
3 changes: 2 additions & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@ module github.com/koinos/koinos-jsonrpc
go 1.15

require (
github.com/koinos/koinos-log-golang v1.0.0
github.com/koinos/koinos-log-golang v1.0.1-0.20231002210928-929b5ecd5bc8
github.com/koinos/koinos-log-golang/v2 v2.0.0 // indirect
github.com/koinos/koinos-mq-golang v1.0.0
github.com/koinos/koinos-proto-golang v1.0.0
github.com/koinos/koinos-util-golang v1.0.0
Expand Down
12 changes: 12 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -224,6 +224,18 @@ github.com/klauspost/crc32 v0.0.0-20161016154125-cb6bfca970f6/go.mod h1:+ZoRqAPR
github.com/klauspost/pgzip v1.0.2-0.20170402124221-0bf5dcad4ada/go.mod h1:Ch1tH69qFZu15pkjo5kYi6mth2Zzwzt50oCQKQE9RUs=
github.com/koinos/koinos-log-golang v1.0.0 h1:BlA8N2AOT3Xai5+ErvyIPz9RLHedLGfUxYnUAPRrzac=
github.com/koinos/koinos-log-golang v1.0.0/go.mod h1:/dzAVdA+woySENUYwls8RT+5i87Rm4qoMZ4ctEQI8k0=
github.com/koinos/koinos-log-golang v1.0.1-0.20230929222233-29d4d8d95208 h1:3ksKEBo5Tl6NAeboNa2C9UmxUj7KTYgmBsKaLcO4/p4=
github.com/koinos/koinos-log-golang v1.0.1-0.20230929222233-29d4d8d95208/go.mod h1:/dzAVdA+woySENUYwls8RT+5i87Rm4qoMZ4ctEQI8k0=
github.com/koinos/koinos-log-golang v1.0.1-0.20230929223505-52c99907ee48 h1:GpW2DG20RSuBvThMC5zQPW85z3omPPZomLW/EKCvRPo=
github.com/koinos/koinos-log-golang v1.0.1-0.20230929223505-52c99907ee48/go.mod h1:/dzAVdA+woySENUYwls8RT+5i87Rm4qoMZ4ctEQI8k0=
github.com/koinos/koinos-log-golang v1.0.1-0.20230929233744-4d8929eaa109 h1:JbtijaVp1VMP14g4qFTM6xjQtt7ecUD4vWh0+U4/fjo=
github.com/koinos/koinos-log-golang v1.0.1-0.20230929233744-4d8929eaa109/go.mod h1:/dzAVdA+woySENUYwls8RT+5i87Rm4qoMZ4ctEQI8k0=
github.com/koinos/koinos-log-golang v1.0.1-0.20231002172323-6250e0990208 h1:SFc+bKoAoyB2twNOftAzp7H7Qo3O5QZ7/oQwrDxdTmA=
github.com/koinos/koinos-log-golang v1.0.1-0.20231002172323-6250e0990208/go.mod h1:/dzAVdA+woySENUYwls8RT+5i87Rm4qoMZ4ctEQI8k0=
github.com/koinos/koinos-log-golang v1.0.1-0.20231002210928-929b5ecd5bc8 h1:Ahl9MdIeHqDBQV62fCpzbQIN2Z13IyEeIATQKMqBXe0=
github.com/koinos/koinos-log-golang v1.0.1-0.20231002210928-929b5ecd5bc8/go.mod h1:/dzAVdA+woySENUYwls8RT+5i87Rm4qoMZ4ctEQI8k0=
github.com/koinos/koinos-log-golang/v2 v2.0.0 h1:fOFySSI9+cdmIol9W0a4LQ7Bss1sV1pqxh0JKVx2K3g=
github.com/koinos/koinos-log-golang/v2 v2.0.0/go.mod h1:P4Xa5LX5Jt+KkzT3CuT9/i2yTrTaJVHN5jd51MM2Tmk=
github.com/koinos/koinos-mq-golang v1.0.0 h1:zEslw0vsJN+Ki0WKZ/S2c+Tc7/BoEKOOyTGiVE0msmQ=
github.com/koinos/koinos-mq-golang v1.0.0/go.mod h1:0tg4BPijVFyjZenhDGWNbWNq6X2pMwmllwA4tqEXEKI=
github.com/koinos/koinos-proto-golang v1.0.0 h1:N8haj+tMRLc/a1j636wjryoaxW+aJwKKSdZ01CRJoOU=
Expand Down

0 comments on commit a5a4e5b

Please sign in to comment.