Skip to content

Commit

Permalink
Merge pull request #27 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 64c13fc + 9a86571 commit f1e161c
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 22 deletions.
52 changes: 31 additions & 21 deletions cmd/koinos-contract-meta-store/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import (

"github.com/dgraph-io/badger/v3"
"github.com/koinos/koinos-contract-meta-store/internal/metastore"
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/broadcast"
"github.com/koinos/koinos-proto-golang/koinos/contract_meta_store"
Expand All @@ -28,34 +28,38 @@ import (
)

const (
basedirOption = "basedir"
amqpOption = "amqp"
instanceIDOption = "instance-id"
logLevelOption = "log-level"
resetOption = "reset"
jobsOption = "jobs"
versionOption = "version"
basedirOption = "basedir"
amqpOption = "amqp"
instanceIDOption = "instance-id"
logLevelOption = "log-level"
logDirOption = "log-dir"
logColorOption = "log-color"
logDatetimeOption = "log-datetime"
resetOption = "reset"
jobsOption = "jobs"
versionOption = "version"
)

const (
basedirDefault = ".koinos"
amqpDefault = "amqp://guest:guest@localhost:5672/"
instanceIDDefault = ""
logLevelDefault = "info"
resetDefault = false
basedirDefault = ".koinos"
amqpDefault = "amqp://guest:guest@localhost:5672/"
instanceIDDefault = ""
logLevelDefault = "info"
logColorDefault = true
logDatetimeDefault = true
resetDefault = false
)

const (
metaStoreRPC = "contract_meta_store"
blockAccept = "koinos.block.accept"
appName = "contract_meta_store"
logDir = "logs"
)

// Version display values
const (
DisplayAppName = "Koinos Contract Meta Store"
Version = "v1.0.0"
Version = "v1.1.0"
)

// Gets filled in by the linker
Expand All @@ -70,7 +74,10 @@ func main() {
amqp := flag.StringP(amqpOption, "a", "", "AMQP server URL")
reset := flag.BoolP(resetOption, "r", resetDefault, "Reset the database")
instanceID := flag.StringP(instanceIDOption, "i", instanceIDDefault, "The instance ID to identify this service")
logLevel := flag.StringP(logLevelOption, "l", logLevelDefault, "The log filtering level (debug, info, warn, error)")
logLevel := flag.StringP(logLevelOption, "l", logLevelDefault, "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")
jobs := flag.IntP(jobsOption, "j", jobsDefault, "Number of RPC jobs to run")
version := flag.BoolP(versionOption, "v", false, "Print version and exit")

Expand All @@ -91,17 +98,20 @@ func main() {

*amqp = util.GetStringOption(amqpOption, amqpDefault, *amqp, yamlConfig.ContractMetaStore, yamlConfig.Global)
*logLevel = util.GetStringOption(logLevelOption, logLevelDefault, *logLevel, yamlConfig.ContractMetaStore, yamlConfig.Global)
*logDir = util.GetStringOption(logDirOption, *logDir, *logDir, yamlConfig.ContractMetaStore, yamlConfig.Global)
*logColor = util.GetBoolOption(logColorOption, logColorDefault, *logColor, yamlConfig.ContractMetaStore, yamlConfig.Global)
*logDatetime = util.GetBoolOption(logDatetimeOption, logDatetimeDefault, *logDatetime, yamlConfig.ContractMetaStore, yamlConfig.Global)
*instanceID = util.GetStringOption(instanceIDOption, util.GenerateBase58ID(5), *instanceID, yamlConfig.ContractMetaStore, yamlConfig.Global)
*reset = util.GetBoolOption(resetOption, resetDefault, *reset, yamlConfig.ContractMetaStore, yamlConfig.Global)
*jobs = util.GetIntOption(jobsOption, jobsDefault, *jobs, yamlConfig.ContractMetaStore, 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, appName+".log")
err = log.InitLogger(*logLevel, false, logFilename, appID)
err = log.InitLogger(appName, *instanceID, *logLevel, *logDir, *logColor, *logDatetime)
if err != nil {
fmt.Printf("Invalid log-level: %s. Please choose one of: debug, info, warn, error", *logLevel)
fmt.Printf("Invalid log-level: %s. Please choose one of: debug, info, warning, error", *logLevel)
os.Exit(1)
}

Expand Down
3 changes: 2 additions & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@ go 1.16

require (
github.com/dgraph-io/badger/v3 v3.2103.2
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
6 changes: 6 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -257,6 +257,12 @@ 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.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 f1e161c

Please sign in to comment.