Skip to content

Commit

Permalink
Merge pull request #50 from ecadlabs/27-structured-logging
Browse files Browse the repository at this point in the history
27 structured logging
  • Loading branch information
jevonearth authored Aug 23, 2019
2 parents d013af4 + 773fe88 commit 5525cc5
Show file tree
Hide file tree
Showing 8 changed files with 141 additions and 83 deletions.
21 changes: 18 additions & 3 deletions cmd/signatory/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -133,20 +133,35 @@ func main() {
log.Fatal(err)
}
if len(pubKeys) == 0 {
log.Error("No keys discovered in Key Valut(s), exiting..")
log.Error("No keys discovered in Key Vault(s), exiting..")
os.Exit(1)
}

log.Info("Keys discovered in Key Vault:")
var allowedKeyCount int
for _, key := range pubKeys {
l := log.WithField(signatory.LogPKH, key)

vault, _, err := s.GetCachedPublicKey(ctx, key)
if err != nil {
l.Error(err)
continue
}

logfields := log.Fields{signatory.LogVault: vault.Name()}
if n, ok := vault.(signatory.VaultNamer); ok {
logfields[signatory.LogVaultName] = n.VaultName()
}
l = l.WithFields(logfields)

if s.IsAllowed(key) {
allowedKeyCount++
log.Infof("%s (Configured, ready for use)", key)
l.Info("Key configured, ready for use")
} else {
log.Infof("%s (Found in vault, not configured for use in %s)", key, configFile)
l.Infof("Key found in vault but not configured in %s", configFile)
}
}

if allowedKeyCount == 0 {
log.Errorf("No keys configured for signing. To allow a key add it to the tezos.keys list in %s ", configFile)
os.Exit(1)
Expand Down
2 changes: 1 addition & 1 deletion pkg/crypto/crypto.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ func GetCurve(name string) elliptic.Curve {
return nil
}

// ECCoordinateFromPrivateKey given an elliptic curve name it will produce X and Y coordiante from D
// ECCoordinateFromPrivateKey given an elliptic curve name it will produce X and Y coordinate from D
func ECCoordinateFromPrivateKey(d []byte, curveName string) (xBytes, yBytes []byte) {
curve := GetCurve(curveName)

Expand Down
2 changes: 1 addition & 1 deletion pkg/metrics/vaultmetrics.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ var (
)

// Interceptor function collects sing operation metrics
func Interceptor(opt *signatory.SingInterceptorOptions, sing func() error) error {
func Interceptor(opt *signatory.SignInterceptorOptions, sing func() error) error {
timer := prometheus.NewTimer(prometheus.ObserverFunc(func(seconds float64) {
vaultSigningHist.WithLabelValues(opt.Vault).Observe(seconds * 1000)
}))
Expand Down
8 changes: 4 additions & 4 deletions pkg/signatory/import.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,11 +55,11 @@ func (s *Signatory) Import(pubkey string, secretKey string, importer Importer) (
}

logfields := log.Fields{
logPKH: hash,
logVault: importer.Name(),
LogPKH: hash,
LogVault: importer.Name(),
}
if n, ok := importer.(VaultNamer); ok {
logfields[logVaultName] = n.VaultName()
logfields[LogVaultName] = n.VaultName()
}
l := s.logger.WithFields(logfields)

Expand All @@ -70,7 +70,7 @@ func (s *Signatory) Import(pubkey string, secretKey string, importer Importer) (
return nil, err
}

l.WithField(logKeyID, keyID).Info("Successfully imported")
l.WithField(LogKeyID, keyID).Info("Successfully imported")

importedKey := &ImportedKey{
KeyID: keyID,
Expand Down
Loading

0 comments on commit 5525cc5

Please sign in to comment.