1
0
Fork 0
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:
postmannen 2025-01-10 10:15:43 +01:00
parent 38389c4778
commit 23a5555a35
5 changed files with 16 additions and 28 deletions

View file

@ -81,8 +81,7 @@ func newSchemaMain(configuration *Configuration, errorKernel *errorKernel) *sche
// Load ACLMap from disk if present.
func() {
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(er)
errorKernel.logInfo("newSchemaMain: no file for ACLMap found, will create new one", "file", s.ACLMapFilePath, "error", err)
// If no aclmap is present on disk we just return from this
// function without loading any values.

View file

@ -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)
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.

View file

@ -142,7 +142,7 @@ func (e *errorKernel) start(ringBufferBulkInCh chan<- Message) error {
case logError:
slog.Error("error", fmt.Errorf("%v", er))
case logInfo:
slog.Info(er)
slog.Info("info", fmt.Errorf("%v", er))
case logWarning:
slog.Warn(er)
case logDebug:
@ -258,7 +258,7 @@ func (e *errorKernel) errSend(proc process, msg Message, err error, logLevel log
case logError:
e.logError("error", err)
case logInfo:
e.logInfo(err)
e.logInfo("info", err)
case logWarning:
e.logWarn(err)
case logDebug:
@ -285,8 +285,8 @@ func (e *errorKernel) logError(msg string, args ...any) {
slog.Error(msg, args...)
}
func (e *errorKernel) logInfo(err error) {
slog.Info(err.Error())
func (e *errorKernel) logInfo(msg string, args ...any) {
slog.Info(msg, args...)
}
func (e *errorKernel) logWarn(err error) {

View file

@ -42,13 +42,11 @@ func (s *server) readStartupFolder() {
}
for _, fp := range filePaths {
er := fmt.Errorf("info: ranging filepaths, current filePath contains: %v", fp)
s.errorKernel.logInfo(er)
s.errorKernel.logInfo("readStartupFolder: ranging filepaths, current filePath contains", "filepath", fp)
}
for _, filePath := range filePaths {
er := fmt.Errorf("info: reading and working on file from startup folder %v", filePath)
s.errorKernel.logInfo(er)
s.errorKernel.logInfo("readStartupFolder: reading and working on file from startup folder ", "file", filePath)
// Read the content of each file.
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.messageDeliverLocalCh <- messages

View file

@ -212,8 +212,7 @@ func (p *publicKeys) loadFromFile() error {
if _, err := os.Stat(p.filePath); os.IsNotExist(err) {
// 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.
er := fmt.Errorf("no public keys file found at %v, new file will be created", p.filePath)
p.errorKernel.logInfo(er)
p.errorKernel.logInfo("publicKeys: loadFromFile: no public keys file found, new file will be created", "file", p.filePath)
return nil
}
@ -316,8 +315,7 @@ func (n *nodeAuth) loadSigningKeys() error {
n.SignPublicKey = pub
n.SignPrivateKey = priv
er := fmt.Errorf("info: no signing keys found, generating new keys")
n.errorKernel.logInfo(er)
n.errorKernel.logInfo("loadSigningKeys: no signing keys found, generating new keys")
// We got the new generated keys now, so we can return.
return nil
@ -404,8 +402,7 @@ func (n *nodeAuth) verifySignature(m Message) bool {
// in the map, we return that the signature was verified
// to true to allow the method to be executed.
if _, ok := signatureCheckMap[m.Method]; !ok {
er := fmt.Errorf("verifySignature: will not do signature check for method: %v", m.Method)
n.errorKernel.logInfo(er)
n.errorKernel.logInfo("verifySignature: will not do signature check for method", "method", m.Method)
return true
}
@ -433,8 +430,7 @@ func (n *nodeAuth) verifySignature(m Message) bool {
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(er)
n.errorKernel.logInfo("verifySignature:", "result", ok, "fromNode", m.FromNode, "method", m.Method)
return ok
}
@ -443,8 +439,7 @@ func (n *nodeAuth) verifySignature(m Message) bool {
func (n *nodeAuth) verifyAcl(m Message) bool {
// NB: Only enable acl checking for REQCliCommand for now.
if m.Method != CliCommand {
er := fmt.Errorf("verifyAcl: not REQCliCommand and will not do acl check, method: %v", m.Method)
n.errorKernel.logInfo(er)
n.errorKernel.logInfo("verifyAcl: we shall not do acl check on method", "method", m.Method)
return true
}
@ -462,20 +457,17 @@ func (n *nodeAuth) verifyAcl(m Message) bool {
_, ok = cmdMap[command("*")]
if ok {
er := fmt.Errorf("verifyAcl: The acl said \"*\", all commands allowed from node=%v", m.FromNode)
n.errorKernel.logInfo(er)
n.errorKernel.logInfo("verifyAcl: The acl said \"*\", all commands allowed from node", "fromNode", m.FromNode)
return true
}
_, ok = cmdMap[command(argsStringified)]
if !ok {
er := fmt.Errorf("verifyAcl: The command=%v was NOT FOUND in the acl", m.MethodArgs)
n.errorKernel.logInfo(er)
n.errorKernel.logInfo("verifyAcl: The command was NOT FOUND in the acl", "methodArgs", m.MethodArgs)
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(er)
n.errorKernel.logInfo("verifyAcl: the command was FOUND in the acl", "result", ok, "fromNode", m.FromNode, "method", m.Method)
return true
}