Skip to content

Commit

Permalink
fix open too many files
Browse files Browse the repository at this point in the history
  • Loading branch information
alex cai committed Nov 8, 2016
1 parent 9e78292 commit 950a60f
Showing 1 changed file with 3 additions and 2 deletions.
5 changes: 3 additions & 2 deletions log.go
Original file line number Diff line number Diff line change
Expand Up @@ -213,8 +213,6 @@ func (lf *LogFile) appendCache(msg string) {

// 同步缓存到文件中
func (lf *LogFile) flush() error {
lf.writeMutex.Lock()
defer lf.writeMutex.Unlock()

lf.sync.status = statusDoing
defer func() {
Expand Down Expand Up @@ -308,6 +306,9 @@ func (lf *LogFile) openFile() (*os.File, error) {
// 打开日志文件(不缓存句柄)
func (lf *LogFile) openFileNoCache() (*os.File, error) {
logFilename := lf.filename + "." + lf.getFilenameSuffix()

lf.writeMutex.Lock()
defer lf.writeMutex.Unlock()
file, err := os.OpenFile(logFilename, fileFlag, fileOpenMode)
if err != nil {
// 重试
Expand Down

0 comments on commit 950a60f

Please sign in to comment.