-
Notifications
You must be signed in to change notification settings - Fork 63
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
Damon Zhao
committed
Jul 12, 2017
1 parent
ca71291
commit fa101b2
Showing
10 changed files
with
99 additions
and
24 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
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
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
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
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
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 |
---|---|---|
@@ -0,0 +1,52 @@ | ||
package loghub | ||
|
||
import ( | ||
"log" | ||
"os" | ||
"time" | ||
) | ||
|
||
var ( | ||
AnalysisLogFormat = "%s %15s:%4d - %s" | ||
AnalysisLogFlag = log.LstdFlags | log.Lmicroseconds | ||
AnalysisLogger *Logger | ||
) | ||
|
||
type AnalysisLogHub struct { | ||
logger *log.Logger | ||
logFd *os.File | ||
BufferLog | ||
} | ||
|
||
func init() { | ||
logger := openLogWithFd(os.Stderr, AnalysisLogFlag) | ||
hub := &AnalysisLogHub{logger: logger} | ||
hub.InitBuffer(200) | ||
AnalysisLogger = NewLogger("", hub, DEBUG) | ||
} | ||
|
||
func InitAnalysisLog(path string, level int, bufferSize int) (err error) { | ||
if analysisLog, analysisFd, err := openLog(path, AnalysisLogFlag); err == nil { | ||
hub := &AnalysisLogHub{logger: analysisLog, logFd: analysisFd} | ||
hub.InitBuffer(bufferSize) | ||
AnalysisLogger.Hub = hub | ||
AnalysisLogger.SetLevel(level) | ||
} else { | ||
log.Fatalf("open log error, path=[%s], err=[%s]", path, err.Error()) | ||
} | ||
return | ||
} | ||
|
||
func (hub *AnalysisLogHub) Log(name string, level int, file string, line int, msg string) { | ||
hub.logger.Printf(AnalysisLogFormat, levelString[level], file, line, msg) | ||
bufline := &BufferLine{time.Now(), level, file, line, msg} | ||
hub.Add(bufline) | ||
hub.Last[level] = bufline | ||
if level == FATAL { | ||
os.Exit(1) | ||
} | ||
} | ||
|
||
func (hub *AnalysisLogHub) Reopen(path string) (err error) { | ||
return reopenLogger(&hub.logger, &hub.logFd, path, AnalysisLogFlag) | ||
} |
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
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
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
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