forked from IBAX-io/go-ibax
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
115 changed files
with
9,276 additions
and
9,364 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,60 +1,66 @@ | ||
/*--------------------------------------------------------------------------------------------- | ||
* Copyright (c) IBAX. All rights reserved. | ||
* See LICENSE in the project root for license information. | ||
*--------------------------------------------------------------------------------------------*/ | ||
|
||
package log | ||
|
||
import ( | ||
"path" | ||
"runtime" | ||
"strings" | ||
"time" | ||
|
||
"github.com/IBAX-io/go-ibax/packages/conf" | ||
|
||
"github.com/sirupsen/logrus" | ||
) | ||
|
||
// ContextHook storing nothing but behavior | ||
type ContextHook struct{} | ||
|
||
// Levels returns all log levels | ||
func (hook ContextHook) Levels() []logrus.Level { | ||
return logrus.AllLevels | ||
} | ||
|
||
// Fire the log entry | ||
func (hook ContextHook) Fire(entry *logrus.Entry) error { | ||
var pc []uintptr | ||
if _, skip := entry.Data["nocontext"]; skip { | ||
delete(entry.Data, "nocontext") | ||
return nil | ||
} | ||
if conf.Config.Log.LogLevel == "DEBUG" { | ||
pc = make([]uintptr, 15, 15) | ||
} else { | ||
pc = make([]uintptr, 4, 4) | ||
} | ||
cnt := runtime.Callers(6, pc) | ||
|
||
count := 0 | ||
for i := 0; i < cnt; i++ { | ||
fu := runtime.FuncForPC(pc[i] - 1) | ||
name := fu.Name() | ||
if !strings.Contains(name, "github.com/sirupsen/logrus") { | ||
file, line := fu.FileLine(pc[i] - 1) | ||
if count == 0 { | ||
entry.Data["file"] = path.Base(file) | ||
entry.Data["func"] = path.Base(name) | ||
entry.Data["line"] = line | ||
entry.Data["time"] = time.Now().Format(time.RFC3339) | ||
if conf.Config.Log.LogLevel != "DEBUG" { | ||
break | ||
entry.Data["from"] = append(entry.Data["from"].([]string), path.Base(name)) | ||
} | ||
count += 1 | ||
} | ||
} | ||
return nil | ||
} | ||
/*--------------------------------------------------------------------------------------------- | ||
* Copyright (c) IBAX. All rights reserved. | ||
* See LICENSE in the project root for license information. | ||
*--------------------------------------------------------------------------------------------*/ | ||
|
||
package log | ||
|
||
import ( | ||
"path" | ||
"runtime" | ||
"strings" | ||
"time" | ||
|
||
"github.com/IBAX-io/go-ibax/packages/conf" | ||
|
||
"github.com/sirupsen/logrus" | ||
) | ||
|
||
// ContextHook storing nothing but behavior | ||
type ContextHook struct{} | ||
|
||
// Levels returns all log levels | ||
func (hook ContextHook) Levels() []logrus.Level { | ||
return logrus.AllLevels | ||
} | ||
|
||
// Fire the log entry | ||
func (hook ContextHook) Fire(entry *logrus.Entry) error { | ||
var pc []uintptr | ||
if _, skip := entry.Data["nocontext"]; skip { | ||
delete(entry.Data, "nocontext") | ||
return nil | ||
} | ||
if conf.Config.Log.LogLevel == "DEBUG" { | ||
pc = make([]uintptr, 15, 15) | ||
} else { | ||
pc = make([]uintptr, 4, 4) | ||
} | ||
cnt := runtime.Callers(6, pc) | ||
|
||
count := 0 | ||
for i := 0; i < cnt; i++ { | ||
fu := runtime.FuncForPC(pc[i] - 1) | ||
name := fu.Name() | ||
if !strings.Contains(name, "github.com/sirupsen/logrus") { | ||
file, line := fu.FileLine(pc[i] - 1) | ||
if count == 0 { | ||
entry.Data["file"] = path.Base(file) | ||
entry.Data["func"] = path.Base(name) | ||
entry.Data["line"] = line | ||
entry.Data["time"] = time.Now().Format(time.RFC3339) | ||
if conf.Config.Log.LogLevel != "DEBUG" { | ||
break | ||
} | ||
} | ||
if count >= 1 { | ||
if count == 1 { | ||
entry.Data["from"] = []string{} | ||
} | ||
entry.Data["from"] = append(entry.Data["from"].([]string), path.Base(name)) | ||
} | ||
count += 1 | ||
} | ||
} | ||
return nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,22 +1,29 @@ | ||
/*--------------------------------------------------------------------------------------------- | ||
* Copyright (c) IBAX. All rights reserved. | ||
* See LICENSE in the project root for license information. | ||
*--------------------------------------------------------------------------------------------*/ | ||
|
||
package log | ||
|
||
|
||
// Levels returns all log levels | ||
func (hook HexHook) Levels() []logrus.Level { | ||
return logrus.AllLevels | ||
} | ||
|
||
// Fire the log entry | ||
func (hook HexHook) Fire(entry *logrus.Entry) error { | ||
for i := range entry.Data { | ||
if b, ok := entry.Data[i].([]byte); ok { | ||
entry.Data[i] = hex.EncodeToString(b) | ||
} | ||
} | ||
return nil | ||
} | ||
/*--------------------------------------------------------------------------------------------- | ||
* Copyright (c) IBAX. All rights reserved. | ||
* See LICENSE in the project root for license information. | ||
*--------------------------------------------------------------------------------------------*/ | ||
|
||
package log | ||
|
||
import ( | ||
"encoding/hex" | ||
|
||
"github.com/sirupsen/logrus" | ||
) | ||
|
||
type HexHook struct{} | ||
|
||
// Levels returns all log levels | ||
func (hook HexHook) Levels() []logrus.Level { | ||
return logrus.AllLevels | ||
} | ||
|
||
// Fire the log entry | ||
func (hook HexHook) Fire(entry *logrus.Entry) error { | ||
for i := range entry.Data { | ||
if b, ok := entry.Data[i].([]byte); ok { | ||
entry.Data[i] = hex.EncodeToString(b) | ||
} | ||
} | ||
return nil | ||
} |
Oops, something went wrong.