| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849 |
- package fslog
- import (
- "log"
- "os"
- "runtime/debug"
- )
- const (
- levelInfo = "INFO"
- levelDebug = "DEBUG"
- levelError = "ERROR"
- levelWarning = "WARNING"
- )
- const (
- logHeaderFormat = `[level=%s service=%s module=%s subject=%s object=%s operation=%s] %s`
- )
- func init() {
- log.SetOutput(os.Stdout)
- log.SetFlags(log.Ldate | log.Ltime)
- }
- func Info(serviceName string, moduleName string, subject string, object string,
- operation string, content string) {
- sendConsoleLog(levelInfo, serviceName, moduleName, subject, object, operation, content)
- }
- func Error(serviceName string, moduleName string, subject string,
- object string, operation string, content string) {
- sendConsoleLog(levelError, serviceName, moduleName, subject, object, operation,
- content+"\n"+string(debug.Stack()))
- }
- func Debug(serviceName string, moduleName string, subject string,
- object string, operation string, content string) {
- sendConsoleLog(levelDebug, serviceName, moduleName, subject, object, operation, content)
- }
- func Warning(serviceName string, moduleName string, subject string,
- object string, operation string, content string) {
- sendConsoleLog(levelWarning, serviceName, moduleName, subject, object, operation, content)
- }
- func sendConsoleLog(level string, serviceName string, moduleName string, subject string,
- object string, operation string, content string) {
- log.Printf(logHeaderFormat, level, serviceName, moduleName, subject, object, operation, content)
- }
|