1
0
mirror of https://github.com/beego/bee.git synced 2024-11-26 01:11:30 +00:00

Acquire lock when logging

This commit is contained in:
Faissal Elamraoui 2016-11-15 12:25:37 +01:00
parent deacdaa667
commit 21fc177551
2 changed files with 5 additions and 3 deletions

View File

@ -558,8 +558,7 @@ func createapi(cmd *Command, args []string) int {
apppath, packpath, err := checkEnv(args[0]) apppath, packpath, err := checkEnv(args[0])
if err != nil { if err != nil {
fmt.Println(err) logger.Fatalf("%s", err)
os.Exit(2)
} }
if driver == "" { if driver == "" {
driver = "mysql" driver = "mysql"

View File

@ -61,7 +61,6 @@ type LogRecord struct {
var ( var (
logRecordTemplate *template.Template logRecordTemplate *template.Template
debugLogRecordTemplate *template.Template debugLogRecordTemplate *template.Template
debugLogFormat string
) )
func init() { func init() {
@ -141,6 +140,10 @@ func (l *BeeLogger) getColorLevel(level int) string {
// mustLog logs the message according to the specified level and arguments. // mustLog logs the message according to the specified level and arguments.
// It panics in case of an error. // It panics in case of an error.
func (l *BeeLogger) mustLog(level int, message string, args ...interface{}) { func (l *BeeLogger) mustLog(level int, message string, args ...interface{}) {
// Acquire the lock
l.mu.Lock()
defer l.mu.Unlock()
// Create the logging record and pass into the output // Create the logging record and pass into the output
record := LogRecord{ record := LogRecord{
ID: fmt.Sprintf("%04d", atomic.AddUint64(&sequenceNo, 1)), ID: fmt.Sprintf("%04d", atomic.AddUint64(&sequenceNo, 1)),