2018-10-02 13:04:48 +02:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
"log"
|
|
|
|
"strings"
|
|
|
|
)
|
|
|
|
|
|
|
|
// Log an api error
|
2018-10-02 14:52:32 +02:00
|
|
|
func apiLogSourceError(module string, sourceId int, params ...interface{}) {
|
2018-10-02 13:04:48 +02:00
|
|
|
var err error
|
|
|
|
args := []string{}
|
|
|
|
|
2018-10-02 14:52:32 +02:00
|
|
|
// Get source configuration
|
|
|
|
source := AliceConfig.Sources[sourceId]
|
|
|
|
sourceName := "unknown"
|
|
|
|
if source != nil {
|
|
|
|
sourceName = source.Name
|
|
|
|
}
|
|
|
|
|
2018-10-02 13:04:48 +02:00
|
|
|
// Build args string and get error from params
|
|
|
|
for _, p := range params {
|
|
|
|
// We have our error
|
|
|
|
if e, ok := p.(error); ok {
|
|
|
|
err = e
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
|
|
|
|
args = append(args, fmt.Sprintf("%v", p))
|
|
|
|
}
|
|
|
|
|
|
|
|
if err != nil {
|
|
|
|
log.Println(fmt.Sprintf(
|
2018-10-02 15:52:46 +02:00
|
|
|
"API ERROR :: %s.%s(%s) :: %v",
|
2018-10-02 14:52:32 +02:00
|
|
|
sourceName, module, strings.Join(args, ", "), err,
|
2018-10-02 13:04:48 +02:00
|
|
|
))
|
|
|
|
} else {
|
|
|
|
log.Println(fmt.Sprintf(
|
2018-10-02 15:52:46 +02:00
|
|
|
"API ERROR :: %s.%s(%s)",
|
2018-10-02 14:52:32 +02:00
|
|
|
sourceName, module, strings.Join(args, ", "),
|
2018-10-02 13:04:48 +02:00
|
|
|
))
|
|
|
|
}
|
|
|
|
}
|