mirror of
https://github.com/cgrates/cgrates.git
synced 2026-02-11 18:16:24 +05:00
added error logger
This commit is contained in:
@@ -50,7 +50,19 @@ type Mediator struct {
|
||||
uuidIndex csvindex
|
||||
}
|
||||
|
||||
func NewMediator(connector timespans.Connector, loggerDb timespans.DataStorage, skipDb bool, outputDir, directionIndex, torIndex, tenantIndex, subjectIndex, accountIndex, destinationIndex, timeStartIndex, durationIndex, uuidIndex string) (*Mediator, error) {
|
||||
func NewMediator(connector timespans.Connector,
|
||||
loggerDb timespans.DataStorage,
|
||||
skipDb bool,
|
||||
outputDir,
|
||||
directionIndex,
|
||||
torIndex,
|
||||
tenantIndex,
|
||||
subjectIndex,
|
||||
accountIndex,
|
||||
destinationIndex,
|
||||
timeStartIndex,
|
||||
durationIndex,
|
||||
uuidIndex string) (*Mediator, error) {
|
||||
m := &Mediator{
|
||||
connector: connector,
|
||||
loggerDb: loggerDb,
|
||||
@@ -209,5 +221,10 @@ func (m *Mediator) GetCostsFromRater(record []string) (cc *timespans.CallCost, e
|
||||
TimeStart: t1,
|
||||
TimeEnd: t1.Add(d)}
|
||||
err = m.connector.GetCost(cd, cc)
|
||||
if err != nil {
|
||||
m.loggerDb.LogError(record[m.uuidIndex], err.Error())
|
||||
} else {
|
||||
m.loggerDb.LogCallCost(record[m.uuidIndex], cc)
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
@@ -26,13 +26,17 @@ import (
|
||||
)
|
||||
|
||||
const (
|
||||
ACTION_TIMING_PREFIX = "atm_"
|
||||
CALL_COST_LOG_PREFIX = "cco_"
|
||||
LOG_PREFIX = "log_"
|
||||
RATING_PROFILE_PREFIX = "rpf_"
|
||||
ACTION_PREFIX = "act_"
|
||||
USER_BALANCE_PREFIX = "ubl_"
|
||||
DESTINATION_PREFIX = "dst_"
|
||||
ACTION_TIMING_PREFIX = "atm_"
|
||||
RATING_PROFILE_PREFIX = "rpf_"
|
||||
ACTION_PREFIX = "act_"
|
||||
USER_BALANCE_PREFIX = "ubl_"
|
||||
DESTINATION_PREFIX = "dst_"
|
||||
LOG_CALL_COST_PREFIX = "cco_"
|
||||
LOG_ACTION_TIMMING_PREFIX = "ltm_"
|
||||
LOG_ACTION_TRIGGER_PREFIX = "ltr_"
|
||||
LOG_ERR = "ler_"
|
||||
// sources
|
||||
|
||||
)
|
||||
|
||||
/*
|
||||
@@ -53,9 +57,10 @@ type DataStorage interface {
|
||||
SetActionTimings(string, []*ActionTiming) error
|
||||
GetAllActionTimings() (map[string][]*ActionTiming, error)
|
||||
LogCallCost(uuid string, cc *CallCost) error
|
||||
GetCallCostLog(uuid string) (*CallCost, error)
|
||||
LogError(uuid, errstr string) error
|
||||
LogActionTrigger(ubId string, at *ActionTrigger, as []*Action) error
|
||||
LogActionTiming(at *ActionTiming, as []*Action) error
|
||||
GetCallCostLog(uuid string) (*CallCost, error)
|
||||
}
|
||||
|
||||
type Marshaler interface {
|
||||
@@ -137,7 +142,7 @@ func (mm *MyMarshaler) Marshal(v interface{}) (data []byte, err error) {
|
||||
return []byte(s.store()), nil
|
||||
}
|
||||
mm.buf.Reset()
|
||||
if err = gob.NewEncoder(&mm.buf).Encode(v); err == nil {
|
||||
if err = json.NewEncoder(&mm.buf).Encode(v); err == nil {
|
||||
data = mm.buf.Bytes()
|
||||
}
|
||||
return
|
||||
@@ -171,8 +176,7 @@ func (mm *MyMarshaler) Unmarshal(data []byte, v interface{}) (err error) {
|
||||
return nil
|
||||
|
||||
}
|
||||
// Logger.Info("Using default gob marshalling!")
|
||||
mm.buf.Reset()
|
||||
mm.buf.Write(data)
|
||||
return gob.NewDecoder(&mm.buf).Decode(v)
|
||||
return json.NewDecoder(&mm.buf).Decode(v)
|
||||
}
|
||||
|
||||
@@ -139,7 +139,7 @@ func (ms *MapStorage) GetAllActionTimings() (ats map[string][]*ActionTiming, err
|
||||
|
||||
func (ms *MapStorage) LogCallCost(uuid string, cc *CallCost) error {
|
||||
result, err := ms.ms.Marshal(cc)
|
||||
ms.dict[CALL_COST_LOG_PREFIX+uuid] = result
|
||||
ms.dict[LOG_CALL_COST_PREFIX+uuid] = result
|
||||
return err
|
||||
}
|
||||
|
||||
@@ -161,7 +161,7 @@ func (ms *MapStorage) LogActionTrigger(ubId string, at *ActionTrigger, as []*Act
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
ms.dict[LOG_PREFIX+time.Now().Format(time.RFC3339Nano)] = []byte(fmt.Sprintf("%s*%s*%s", ubId, string(mat), string(mas)))
|
||||
ms.dict[LOG_ACTION_TRIGGER_PREFIX+time.Now().Format(time.RFC3339Nano)] = []byte(fmt.Sprintf("%s*%s*%s", ubId, string(mat), string(mas)))
|
||||
return
|
||||
}
|
||||
|
||||
@@ -174,6 +174,11 @@ func (ms *MapStorage) LogActionTiming(at *ActionTiming, as []*Action) (err error
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
ms.dict[LOG_PREFIX+time.Now().Format(time.RFC3339Nano)] = []byte(fmt.Sprintf("%s*%s", string(mat), string(mas)))
|
||||
ms.dict[LOG_ACTION_TIMMING_PREFIX+time.Now().Format(time.RFC3339Nano)] = []byte(fmt.Sprintf("%s*%s", string(mat), string(mas)))
|
||||
return
|
||||
}
|
||||
|
||||
func (ms *MapStorage) LogError(uuid, errstr string) (err error) {
|
||||
ms.dict[LOG_ERR+uuid] = []byte(errstr)
|
||||
return nil
|
||||
}
|
||||
|
||||
@@ -112,6 +112,11 @@ type LogTriggerEntry struct {
|
||||
LogTime time.Time
|
||||
}
|
||||
|
||||
type LogErrEntry struct {
|
||||
Id string `bson:"_id,omitempty"`
|
||||
ErrStr string
|
||||
}
|
||||
|
||||
func (ms *MongoStorage) GetRatingProfile(key string) (rp *RatingProfile, err error) {
|
||||
rp = new(RatingProfile)
|
||||
err = ms.db.C("ratingprofiles").Find(bson.M{"_id": key}).One(&rp)
|
||||
@@ -193,3 +198,7 @@ func (ms *MongoStorage) LogActionTrigger(ubId string, at *ActionTrigger, as []*A
|
||||
func (ms *MongoStorage) LogActionTiming(at *ActionTiming, as []*Action) (err error) {
|
||||
return ms.db.C("actlog").Insert(&LogTimingEntry{at, as, time.Now()})
|
||||
}
|
||||
|
||||
func (ms *MongoStorage) LogError(uuid, errstr string) (err error) {
|
||||
return ms.db.C("errlog").Insert(&LogErrEntry{uuid, errstr})
|
||||
}
|
||||
|
||||
@@ -216,3 +216,4 @@ func (psl *PostgresStorage) LogActionTrigger(ubId string, at *ActionTrigger, as
|
||||
return
|
||||
}
|
||||
func (psl *PostgresStorage) LogActionTiming(at *ActionTiming, as []*Action) (err error) { return }
|
||||
func (psl *PostgresStorage) LogError(uuid, errstr string) (err error) { return }
|
||||
|
||||
@@ -151,7 +151,7 @@ func (rs *RedisStorage) LogCallCost(uuid string, cc *CallCost) (err error) {
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
return rs.db.Set(CALL_COST_LOG_PREFIX+uuid, result).Err
|
||||
return rs.db.Set(LOG_CALL_COST_PREFIX+uuid, result).Err
|
||||
}
|
||||
|
||||
func (rs *RedisStorage) GetCallCostLog(uuid string) (cc *CallCost, err error) {
|
||||
@@ -172,7 +172,7 @@ func (rs *RedisStorage) LogActionTrigger(ubId string, at *ActionTrigger, as []*A
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
rs.db.Set(LOG_PREFIX+time.Now().Format(time.RFC3339Nano), []byte(fmt.Sprintf("%s*%s*%s", ubId, string(mat), string(mas))))
|
||||
rs.db.Set(LOG_ACTION_TRIGGER_PREFIX+time.Now().Format(time.RFC3339Nano), []byte(fmt.Sprintf("%s*%s*%s", ubId, string(mat), string(mas))))
|
||||
return
|
||||
}
|
||||
|
||||
@@ -185,6 +185,10 @@ func (rs *RedisStorage) LogActionTiming(at *ActionTiming, as []*Action) (err err
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
rs.db.Set(LOG_PREFIX+time.Now().Format(time.RFC3339Nano), []byte(fmt.Sprintf("%s*%s", string(mat), string(mas))))
|
||||
rs.db.Set(LOG_ACTION_TIMMING_PREFIX+time.Now().Format(time.RFC3339Nano), []byte(fmt.Sprintf("%s*%s", string(mat), string(mas))))
|
||||
return
|
||||
}
|
||||
|
||||
func (rs *RedisStorage) LogError(uuid, errstr string) (err error) {
|
||||
return rs.db.Set(LOG_ERR+uuid, errstr).Err
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user