Skip to content
Open
5 changes: 3 additions & 2 deletions lib-utilities/logs/formatter.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import (

var priorityLogFields = []string{
"host",
"procid",
}

var syslogPriorityNumerics = map[string]int8{
Expand Down Expand Up @@ -59,7 +60,7 @@ type ODIMSysLogFormatter struct{}
func (f *ODIMSysLogFormatter) Format(entry *logrus.Entry) ([]byte, error) {
level := entry.Level.String()
priorityNumber := findSysLogPriorityNumeric(level)
sysLogMsg := fmt.Sprintf("<%d> %s %s", priorityNumber, entry.Time.UTC().Format(time.RFC3339), level)
sysLogMsg := fmt.Sprintf("<%d> %s %s ", priorityNumber, entry.Time.UTC().Format(time.RFC3339), level)
sysLogMsg = formatPriorityFields(entry, sysLogMsg)
for k, v := range logFields {
if accountLog, present := formatSyslog(k, v, entry); present {
Expand All @@ -80,7 +81,7 @@ func formatPriorityFields(entry *logrus.Entry, msg string) string {
for _, v := range priorityLogFields {
if val, ok := entry.Data[v]; ok {
present = false
msg = fmt.Sprintf("%s %v ", msg, val)
msg = fmt.Sprintf("%s%v ", msg, val)
}
}
if !present {
Expand Down
45 changes: 29 additions & 16 deletions lib-utilities/logs/logger.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import (

// Logger is used when you import the log package in your service
// and logging using the package level methods.
// This can be customized using the functions InitSysLogger or InitJSONLogger
// This can be customized using the function InitLogger
var Logger *logrus.Entry

// LogFormat type
Expand All @@ -36,11 +36,16 @@ const (
// Config is used for user configuration
type Config struct {
LogFormat LogFormat
Host string
ProcID string
}

func init() {
Logger = logrus.NewEntry(logrus.New())
}

// InitLogger sets up the Logger and sets up the format and level
func InitLogger(c *Config) {
Logger = logrus.NewEntry(logrus.New())

// setting logger format
switch c.LogFormat {
Expand All @@ -52,6 +57,14 @@ func InitLogger(c *Config) {
Logger.Logger.SetFormatter(&ODIMSysLogFormatter{})
}

if c.Host != "" {
Logger = Logger.WithField("host", c.Host)
}

if c.ProcID != "" {
Logger = Logger.WithField("procid", c.ProcID)
}

// set the minimum level for logging
Logger.Logger.SetLevel(logrus.DebugLevel)
}
Expand Down Expand Up @@ -191,44 +204,44 @@ func Panicln(args ...interface{}) {
Logger.Panicln(args...)
}

// TraceWithFileds calls Trace method on package level after appending the fields passed
func TraceWithFileds(fields map[string]interface{}, args ...interface{}) {
// TraceWithFields calls Trace method on package level after appending the fields passed
func TraceWithFields(fields map[string]interface{}, args ...interface{}) {
data := getFields(fields)
Logger.WithFields(data).Trace(args...)
}

// DebugWithFileds calls Debug method on package level after appending the fields passed
func DebugWithFileds(fields map[string]interface{}, args ...interface{}) {
// DebugWithFields calls Debug method on package level after appending the fields passed
func DebugWithFields(fields map[string]interface{}, args ...interface{}) {
data := getFields(fields)
Logger.WithFields(data).Debug(args...)
}

// InfoWithFileds calls Info method on package level after appending the fields passed
func InfoWithFileds(fields map[string]interface{}, args ...interface{}) {
// InfoWithFields calls Info method on package level after appending the fields passed
func InfoWithFields(fields map[string]interface{}, args ...interface{}) {
data := getFields(fields)
Logger.WithFields(data).Info(args...)
}

// PrintWithFileds calls Info method on package level after appending the fields passed
func PrintWithFileds(fields map[string]interface{}, args ...interface{}) {
// PrintWithFields calls Info method on package level after appending the fields passed
func PrintWithFields(fields map[string]interface{}, args ...interface{}) {
data := getFields(fields)
Logger.WithFields(data).Info(args...)
}

// WarnWithFileds calls Warn method on package level after appending the fields passed
func WarnWithFileds(fields map[string]interface{}, args ...interface{}) {
// WarnWithFields calls Warn method on package level after appending the fields passed
func WarnWithFields(fields map[string]interface{}, args ...interface{}) {
data := getFields(fields)
Logger.WithFields(data).Warn(args...)
}

// ErrorWithFileds calls Error method on package level after appending the fields passed
func ErrorWithFileds(fields map[string]interface{}, args ...interface{}) {
// ErrorWithFields calls Error method on package level after appending the fields passed
func ErrorWithFields(fields map[string]interface{}, args ...interface{}) {
data := getFields(fields)
Logger.WithFields(data).Error(args...)
}

// PanicWithFileds calls Panic method on package level after appending the fields passed
func PanicWithFileds(fields map[string]interface{}, args ...interface{}) {
// PanicWithFields calls Panic method on package level after appending the fields passed
func PanicWithFields(fields map[string]interface{}, args ...interface{}) {
data := getFields(fields)
Logger.WithFields(data).Panic(args...)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,14 @@ spec:
value: {{ .Values.odimra.haDeploymentEnabled | quote }}
- name: ODIM_NAMESPACE
value: {{ .Values.odimra.namespace | quote }}
- name: HOST_NAME
valueFrom:
fieldRef:
fieldPath: spec.nodeName
- name: POD_NAME
valueFrom:
fieldRef:
fieldPath: metadata.name
image: account-session:{{ .Values.odimra.accountSessionImageTag }}
imagePullPolicy: IfNotPresent
ports:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,14 @@ spec:
value: {{ .Values.odimra.haDeploymentEnabled | quote }}
- name: ODIM_NAMESPACE
value: {{ .Values.odimra.namespace | quote }}
- name: HOST_NAME
valueFrom:
fieldRef:
fieldPath: spec.nodeName
- name: POD_NAME
valueFrom:
fieldRef:
fieldPath: metadata.name
image: aggregation:{{ .Values.odimra.aggregationImageTag }}
imagePullPolicy: IfNotPresent
ports:
Expand Down
8 changes: 8 additions & 0 deletions odim-controller/helmcharts/api/templates/deployment.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,14 @@ spec:
value: {{ .Values.odimra.haDeploymentEnabled | quote }}
- name: ODIM_NAMESPACE
value: {{ .Values.odimra.namespace | quote }}
- name: HOST_NAME
valueFrom:
fieldRef:
fieldPath: spec.nodeName
- name: POD_NAME
valueFrom:
fieldRef:
fieldPath: metadata.name
image: api:{{ .Values.odimra.apiImageTag }}
imagePullPolicy: IfNotPresent
ports:
Expand Down
8 changes: 8 additions & 0 deletions odim-controller/helmcharts/events/templates/deployment.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,14 @@ spec:
value: {{ .Values.odimra.haDeploymentEnabled | quote }}
- name: ODIM_NAMESPACE
value: {{ .Values.odimra.namespace | quote }}
- name: HOST_NAME
valueFrom:
fieldRef:
fieldPath: spec.nodeName
- name: POD_NAME
valueFrom:
fieldRef:
fieldPath: metadata.name
image: events:{{ .Values.odimra.eventImageTag }}
imagePullPolicy: IfNotPresent
ports:
Expand Down
8 changes: 8 additions & 0 deletions odim-controller/helmcharts/fabrics/templates/deployment.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,14 @@ spec:
value: {{ .Values.odimra.haDeploymentEnabled | quote }}
- name: ODIM_NAMESPACE
value: {{ .Values.odimra.namespace | quote }}
- name: HOST_NAME
valueFrom:
fieldRef:
fieldPath: spec.nodeName
- name: POD_NAME
valueFrom:
fieldRef:
fieldPath: metadata.name
image: fabrics:{{ .Values.odimra.fabricsImageTag }}
imagePullPolicy: IfNotPresent
ports:
Expand Down
8 changes: 8 additions & 0 deletions odim-controller/helmcharts/licenses/templates/deployment.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,14 @@ spec:
value: {{ .Values.odimra.haDeploymentEnabled | quote }}
- name: ODIM_NAMESPACE
value: {{ .Values.odimra.namespace | quote }}
- name: HOST_NAME
valueFrom:
fieldRef:
fieldPath: spec.nodeName
- name: POD_NAME
valueFrom:
fieldRef:
fieldPath: metadata.name
image: licenses:{{ .Values.odimra.licensesImageTag }}
imagePullPolicy: IfNotPresent
ports:
Expand Down
8 changes: 8 additions & 0 deletions odim-controller/helmcharts/managers/templates/deployment.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,14 @@ spec:
value: {{ .Values.odimra.haDeploymentEnabled | quote }}
- name: ODIM_NAMESPACE
value: {{ .Values.odimra.namespace | quote }}
- name: HOST_NAME
valueFrom:
fieldRef:
fieldPath: spec.nodeName
- name: POD_NAME
valueFrom:
fieldRef:
fieldPath: metadata.name
image: managers:{{ .Values.odimra.managersImageTag }}
imagePullPolicy: IfNotPresent
ports:
Expand Down
8 changes: 8 additions & 0 deletions odim-controller/helmcharts/systems/templates/deployment.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,14 @@ spec:
value: {{ .Values.odimra.haDeploymentEnabled | quote }}
- name: ODIM_NAMESPACE
value: {{ .Values.odimra.namespace | quote }}
- name: HOST_NAME
valueFrom:
fieldRef:
fieldPath: spec.nodeName
- name: POD_NAME
valueFrom:
fieldRef:
fieldPath: metadata.name
image: systems:{{ .Values.odimra.systemsImageTag }}
imagePullPolicy: IfNotPresent
ports:
Expand Down
8 changes: 8 additions & 0 deletions odim-controller/helmcharts/task/templates/deployment.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,14 @@ spec:
value: {{ .Values.odimra.haDeploymentEnabled | quote }}
- name: ODIM_NAMESPACE
value: {{ .Values.odimra.namespace | quote }}
- name: HOST_NAME
valueFrom:
fieldRef:
fieldPath: spec.nodeName
- name: POD_NAME
valueFrom:
fieldRef:
fieldPath: metadata.name
image: task:{{ .Values.odimra.taskImageTag }}
imagePullPolicy: IfNotPresent
ports:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,14 @@ spec:
value: {{ .Values.odimra.haDeploymentEnabled | quote }}
- name: ODIM_NAMESPACE
value: {{ .Values.odimra.namespace | quote }}
- name: HOST_NAME
valueFrom:
fieldRef:
fieldPath: spec.nodeName
- name: POD_NAME
valueFrom:
fieldRef:
fieldPath: metadata.name
image: telemetry:{{ .Values.odimra.telemetryImageTag }}
imagePullPolicy: IfNotPresent
ports:
Expand Down
8 changes: 8 additions & 0 deletions odim-controller/helmcharts/update/templates/deployment.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,14 @@ spec:
value: {{ .Values.odimra.haDeploymentEnabled | quote }}
- name: ODIM_NAMESPACE
value: {{ .Values.odimra.namespace | quote }}
- name: HOST_NAME
valueFrom:
fieldRef:
fieldPath: spec.nodeName
- name: POD_NAME
valueFrom:
fieldRef:
fieldPath: metadata.name
image: update:{{ .Values.odimra.updateImageTag }}
imagePullPolicy: IfNotPresent
ports:
Expand Down
5 changes: 3 additions & 2 deletions svc-account-session/account/create.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,13 @@ import (
"encoding/base64"
"encoding/json"
"fmt"
log "github.com/sirupsen/logrus"
"golang.org/x/crypto/sha3"
"net/http"
"regexp"
"strings"

log "github.com/ODIM-Project/ODIM/lib-utilities/logs"
"golang.org/x/crypto/sha3"

"github.com/ODIM-Project/ODIM/lib-utilities/common"
"github.com/ODIM-Project/ODIM/lib-utilities/config"
"github.com/ODIM-Project/ODIM/lib-utilities/errors"
Expand Down
3 changes: 2 additions & 1 deletion svc-account-session/account/delete.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,10 @@ package account
// IMPORT Section
// ---------------------------------------------------------------------------------------
import (
log "github.com/sirupsen/logrus"
"net/http"

log "github.com/ODIM-Project/ODIM/lib-utilities/logs"

"github.com/ODIM-Project/ODIM/lib-utilities/common"
"github.com/ODIM-Project/ODIM/lib-utilities/errors"
"github.com/ODIM-Project/ODIM/lib-utilities/response"
Expand Down
5 changes: 3 additions & 2 deletions svc-account-session/account/getaccounts.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,15 +19,16 @@ package account
// IMPORT Section
// ---------------------------------------------------------------------------------------
import (
"net/http"

"github.com/ODIM-Project/ODIM/lib-utilities/common"
"github.com/ODIM-Project/ODIM/lib-utilities/config"
"github.com/ODIM-Project/ODIM/lib-utilities/errors"
log "github.com/ODIM-Project/ODIM/lib-utilities/logs"
"github.com/ODIM-Project/ODIM/lib-utilities/response"
"github.com/ODIM-Project/ODIM/svc-account-session/asmodel"
"github.com/ODIM-Project/ODIM/svc-account-session/asresponse"
"github.com/ODIM-Project/ODIM/svc-account-session/auth"
log "github.com/sirupsen/logrus"
"net/http"
)

// GetAllAccounts defines the admin functionality of listing of all accounts.
Expand Down
5 changes: 3 additions & 2 deletions svc-account-session/account/update.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,16 +21,17 @@ package account
import (
"encoding/base64"
"encoding/json"
"net/http"

"github.com/ODIM-Project/ODIM/lib-utilities/common"
"github.com/ODIM-Project/ODIM/lib-utilities/errors"
log "github.com/ODIM-Project/ODIM/lib-utilities/logs"
accountproto "github.com/ODIM-Project/ODIM/lib-utilities/proto/account"
"github.com/ODIM-Project/ODIM/lib-utilities/response"
"github.com/ODIM-Project/ODIM/svc-account-session/asmodel"
"github.com/ODIM-Project/ODIM/svc-account-session/asresponse"
"github.com/ODIM-Project/ODIM/svc-account-session/auth"
log "github.com/sirupsen/logrus"
"golang.org/x/crypto/sha3"
"net/http"
)

// Update defines the updation of the account details. Every account details can be
Expand Down
3 changes: 2 additions & 1 deletion svc-account-session/auth/auth.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,11 @@
package auth

import (
log "github.com/sirupsen/logrus"
"net/http"
"time"

log "github.com/ODIM-Project/ODIM/lib-utilities/logs"

customLogs "github.com/ODIM-Project/ODIM/lib-utilities/logs"
authproto "github.com/ODIM-Project/ODIM/lib-utilities/proto/auth"
"github.com/ODIM-Project/ODIM/lib-utilities/response"
Expand Down
3 changes: 2 additions & 1 deletion svc-account-session/auth/session.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,11 @@ package auth

import (
"encoding/base64"
log "github.com/sirupsen/logrus"
"sync"
"time"

log "github.com/ODIM-Project/ODIM/lib-utilities/logs"

"github.com/ODIM-Project/ODIM/lib-utilities/config"
"github.com/ODIM-Project/ODIM/lib-utilities/errors"
"github.com/ODIM-Project/ODIM/svc-account-session/asmodel"
Expand Down
Loading