mirror of
https://github.com/postmannen/ctrl.git
synced 2025-03-31 01:24:31 +00:00
changed logInfo to structured logging
This commit is contained in:
parent
38389c4778
commit
23a5555a35
5 changed files with 16 additions and 28 deletions
|
@ -81,8 +81,7 @@ func newSchemaMain(configuration *Configuration, errorKernel *errorKernel) *sche
|
||||||
// Load ACLMap from disk if present.
|
// Load ACLMap from disk if present.
|
||||||
func() {
|
func() {
|
||||||
if _, err := os.Stat(s.ACLMapFilePath); os.IsNotExist(err) {
|
if _, err := os.Stat(s.ACLMapFilePath); os.IsNotExist(err) {
|
||||||
er := fmt.Errorf("info: newSchemaMain: no file for ACLMap found, will create new one, %v: %v", s.ACLMapFilePath, err)
|
errorKernel.logInfo("newSchemaMain: no file for ACLMap found, will create new one", "file", s.ACLMapFilePath, "error", err)
|
||||||
errorKernel.logInfo(er)
|
|
||||||
|
|
||||||
// If no aclmap is present on disk we just return from this
|
// If no aclmap is present on disk we just return from this
|
||||||
// function without loading any values.
|
// function without loading any values.
|
||||||
|
|
|
@ -145,7 +145,6 @@ func (c *centralAuth) addPublicKey(proc process, msg Message) {
|
||||||
|
|
||||||
er := fmt.Errorf("addPublicKey: key(s) needs to be allowed by operator for nodes: %v", notAckedNodes)
|
er := fmt.Errorf("addPublicKey: key(s) needs to be allowed by operator for nodes: %v", notAckedNodes)
|
||||||
c.pki.errorKernel.infoSend(proc, msg, er)
|
c.pki.errorKernel.infoSend(proc, msg, er)
|
||||||
c.pki.errorKernel.logInfo(er)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// deletePublicKeys to the db if the node do not exist, or if it is a new value.
|
// deletePublicKeys to the db if the node do not exist, or if it is a new value.
|
||||||
|
|
|
@ -142,7 +142,7 @@ func (e *errorKernel) start(ringBufferBulkInCh chan<- Message) error {
|
||||||
case logError:
|
case logError:
|
||||||
slog.Error("error", fmt.Errorf("%v", er))
|
slog.Error("error", fmt.Errorf("%v", er))
|
||||||
case logInfo:
|
case logInfo:
|
||||||
slog.Info(er)
|
slog.Info("info", fmt.Errorf("%v", er))
|
||||||
case logWarning:
|
case logWarning:
|
||||||
slog.Warn(er)
|
slog.Warn(er)
|
||||||
case logDebug:
|
case logDebug:
|
||||||
|
@ -258,7 +258,7 @@ func (e *errorKernel) errSend(proc process, msg Message, err error, logLevel log
|
||||||
case logError:
|
case logError:
|
||||||
e.logError("error", err)
|
e.logError("error", err)
|
||||||
case logInfo:
|
case logInfo:
|
||||||
e.logInfo(err)
|
e.logInfo("info", err)
|
||||||
case logWarning:
|
case logWarning:
|
||||||
e.logWarn(err)
|
e.logWarn(err)
|
||||||
case logDebug:
|
case logDebug:
|
||||||
|
@ -285,8 +285,8 @@ func (e *errorKernel) logError(msg string, args ...any) {
|
||||||
slog.Error(msg, args...)
|
slog.Error(msg, args...)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (e *errorKernel) logInfo(err error) {
|
func (e *errorKernel) logInfo(msg string, args ...any) {
|
||||||
slog.Info(err.Error())
|
slog.Info(msg, args...)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (e *errorKernel) logWarn(err error) {
|
func (e *errorKernel) logWarn(err error) {
|
||||||
|
|
|
@ -42,13 +42,11 @@ func (s *server) readStartupFolder() {
|
||||||
}
|
}
|
||||||
|
|
||||||
for _, fp := range filePaths {
|
for _, fp := range filePaths {
|
||||||
er := fmt.Errorf("info: ranging filepaths, current filePath contains: %v", fp)
|
s.errorKernel.logInfo("readStartupFolder: ranging filepaths, current filePath contains", "filepath", fp)
|
||||||
s.errorKernel.logInfo(er)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
for _, filePath := range filePaths {
|
for _, filePath := range filePaths {
|
||||||
er := fmt.Errorf("info: reading and working on file from startup folder %v", filePath)
|
s.errorKernel.logInfo("readStartupFolder: reading and working on file from startup folder ", "file", filePath)
|
||||||
s.errorKernel.logInfo(er)
|
|
||||||
|
|
||||||
// Read the content of each file.
|
// Read the content of each file.
|
||||||
readBytes, err := func(filePath string) ([]byte, error) {
|
readBytes, err := func(filePath string) ([]byte, error) {
|
||||||
|
@ -105,7 +103,7 @@ func (s *server) readStartupFolder() {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
er = fmt.Errorf("%v", messages)
|
er := fmt.Errorf("%v", messages)
|
||||||
s.errorKernel.errSend(s.processInitial, Message{}, er, logInfo)
|
s.errorKernel.errSend(s.processInitial, Message{}, er, logInfo)
|
||||||
|
|
||||||
s.messageDeliverLocalCh <- messages
|
s.messageDeliverLocalCh <- messages
|
||||||
|
|
24
node_auth.go
24
node_auth.go
|
@ -212,8 +212,7 @@ func (p *publicKeys) loadFromFile() error {
|
||||||
if _, err := os.Stat(p.filePath); os.IsNotExist(err) {
|
if _, err := os.Stat(p.filePath); os.IsNotExist(err) {
|
||||||
// Just logging the error since it is not crucial that a key file is missing,
|
// Just logging the error since it is not crucial that a key file is missing,
|
||||||
// since a new one will be created on the next update.
|
// since a new one will be created on the next update.
|
||||||
er := fmt.Errorf("no public keys file found at %v, new file will be created", p.filePath)
|
p.errorKernel.logInfo("publicKeys: loadFromFile: no public keys file found, new file will be created", "file", p.filePath)
|
||||||
p.errorKernel.logInfo(er)
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -316,8 +315,7 @@ func (n *nodeAuth) loadSigningKeys() error {
|
||||||
n.SignPublicKey = pub
|
n.SignPublicKey = pub
|
||||||
n.SignPrivateKey = priv
|
n.SignPrivateKey = priv
|
||||||
|
|
||||||
er := fmt.Errorf("info: no signing keys found, generating new keys")
|
n.errorKernel.logInfo("loadSigningKeys: no signing keys found, generating new keys")
|
||||||
n.errorKernel.logInfo(er)
|
|
||||||
|
|
||||||
// We got the new generated keys now, so we can return.
|
// We got the new generated keys now, so we can return.
|
||||||
return nil
|
return nil
|
||||||
|
@ -404,8 +402,7 @@ func (n *nodeAuth) verifySignature(m Message) bool {
|
||||||
// in the map, we return that the signature was verified
|
// in the map, we return that the signature was verified
|
||||||
// to true to allow the method to be executed.
|
// to true to allow the method to be executed.
|
||||||
if _, ok := signatureCheckMap[m.Method]; !ok {
|
if _, ok := signatureCheckMap[m.Method]; !ok {
|
||||||
er := fmt.Errorf("verifySignature: will not do signature check for method: %v", m.Method)
|
n.errorKernel.logInfo("verifySignature: will not do signature check for method", "method", m.Method)
|
||||||
n.errorKernel.logInfo(er)
|
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -433,8 +430,7 @@ func (n *nodeAuth) verifySignature(m Message) bool {
|
||||||
n.errorKernel.logError("verifySignature", "error", err)
|
n.errorKernel.logError("verifySignature", "error", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
er := fmt.Errorf("info: verifySignature, result: %v, fromNode: %v, method: %v", ok, m.FromNode, m.Method)
|
n.errorKernel.logInfo("verifySignature:", "result", ok, "fromNode", m.FromNode, "method", m.Method)
|
||||||
n.errorKernel.logInfo(er)
|
|
||||||
|
|
||||||
return ok
|
return ok
|
||||||
}
|
}
|
||||||
|
@ -443,8 +439,7 @@ func (n *nodeAuth) verifySignature(m Message) bool {
|
||||||
func (n *nodeAuth) verifyAcl(m Message) bool {
|
func (n *nodeAuth) verifyAcl(m Message) bool {
|
||||||
// NB: Only enable acl checking for REQCliCommand for now.
|
// NB: Only enable acl checking for REQCliCommand for now.
|
||||||
if m.Method != CliCommand {
|
if m.Method != CliCommand {
|
||||||
er := fmt.Errorf("verifyAcl: not REQCliCommand and will not do acl check, method: %v", m.Method)
|
n.errorKernel.logInfo("verifyAcl: we shall not do acl check on method", "method", m.Method)
|
||||||
n.errorKernel.logInfo(er)
|
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -462,20 +457,17 @@ func (n *nodeAuth) verifyAcl(m Message) bool {
|
||||||
|
|
||||||
_, ok = cmdMap[command("*")]
|
_, ok = cmdMap[command("*")]
|
||||||
if ok {
|
if ok {
|
||||||
er := fmt.Errorf("verifyAcl: The acl said \"*\", all commands allowed from node=%v", m.FromNode)
|
n.errorKernel.logInfo("verifyAcl: The acl said \"*\", all commands allowed from node", "fromNode", m.FromNode)
|
||||||
n.errorKernel.logInfo(er)
|
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
|
||||||
_, ok = cmdMap[command(argsStringified)]
|
_, ok = cmdMap[command(argsStringified)]
|
||||||
if !ok {
|
if !ok {
|
||||||
er := fmt.Errorf("verifyAcl: The command=%v was NOT FOUND in the acl", m.MethodArgs)
|
n.errorKernel.logInfo("verifyAcl: The command was NOT FOUND in the acl", "methodArgs", m.MethodArgs)
|
||||||
n.errorKernel.logInfo(er)
|
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
er := fmt.Errorf("verifyAcl: the command was FOUND in the acl, verifyAcl, result: %v, fromNode: %v, method: %v", ok, m.FromNode, m.Method)
|
n.errorKernel.logInfo("verifyAcl: the command was FOUND in the acl", "result", ok, "fromNode", m.FromNode, "method", m.Method)
|
||||||
n.errorKernel.logInfo(er)
|
|
||||||
|
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue