Skip to content

Commit 3b9231d

Browse files
authored
Merge pull request #6 for v0.3.2 Release
2 parents 1580ce2 + 87488f8 commit 3b9231d

File tree

10 files changed

+17
-75
lines changed

10 files changed

+17
-75
lines changed

README.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,19 @@
11
# log - aah framework
22
[![Build Status](https://travis-ci.org/go-aah/log.svg?branch=master)](https://travis-ci.org/go-aah/log) [![codecov](https://codecov.io/gh/go-aah/log/branch/master/graph/badge.svg)](https://codecov.io/gh/go-aah/log/branch/master) [![Go Report Card](https://goreportcard.com/badge/aahframework.org/log.v0)](https://goreportcard.com/report/aahframework.org/log.v0)
3-
[![Version](https://img.shields.io/badge/version-0.3.1-blue.svg)](https://github.com/go-aah/log/releases/latest) [![GoDoc](https://godoc.org/aahframework.org/log.v0?status.svg)](https://godoc.org/aahframework.org/log.v0)
3+
[![Version](https://img.shields.io/badge/version-0.3.2-blue.svg)](https://github.com/go-aah/log/releases/latest) [![GoDoc](https://godoc.org/aahframework.org/log.v0?status.svg)](https://godoc.org/aahframework.org/log.v0)
44
[![License](https://img.shields.io/github/license/go-aah/log.svg)](LICENSE)
55

6-
***v0.3.1 [released](https://github.com/go-aah/log/releases/latest) and tagged on May 16, 2017***
6+
***v0.3.2 [released](https://github.com/go-aah/log/releases/latest) and tagged on May 17, 2017***
77

88
Simple, flexible & powerful `Go` logger inspired by standard logger & Google glog. aah framework utilizes `log` library across.
99

1010
*`log` developed for aah framework. However, it's an independent library, can be used separately with any `Go` language project. Feel free to use it.*
1111

1212
# Installation
13-
#### Stable - Version
13+
#### Stable Version - Production Ready
1414
```sh
1515
# install the library
1616
go get -u aahframework.org/log.v0
1717
```
1818

19-
See official page [TODO]
19+
Visit official website https://aahframework.org to learn more.

console_receiver.go

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ import (
99
"io"
1010
"os"
1111
"runtime"
12-
"sync"
1312

1413
"aahframework.org/config.v0"
1514
)
@@ -33,7 +32,6 @@ var (
3332
// ConsoleReceiver writes the log entry into os.Stderr.
3433
// For non-windows it writes with color.
3534
type ConsoleReceiver struct {
36-
rw *sync.RWMutex
3735
out io.Writer
3836
formatter string
3937
flags *[]FlagPart
@@ -60,8 +58,6 @@ func (c *ConsoleReceiver) Init(cfg *config.Config) error {
6058

6159
// SetPattern method initializes the logger format pattern.
6260
func (c *ConsoleReceiver) SetPattern(pattern string) error {
63-
c.rw.Lock()
64-
defer c.rw.Unlock()
6561
flags, err := parseFlag(pattern)
6662
if err != nil {
6763
return err
@@ -81,8 +77,6 @@ func (c *ConsoleReceiver) IsCallerInfo() bool {
8177

8278
// Log method writes the log entry into os.Stderr.
8379
func (c *ConsoleReceiver) Log(entry *Entry) {
84-
c.rw.RLock()
85-
defer c.rw.RUnlock()
8680
if c.isColor {
8781
_, _ = c.out.Write(levelToColor[entry.Level])
8882
}

console_receiver_test.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -121,5 +121,4 @@ func testConsoleLogger(t *testing.T, cfgStr string) {
121121
logger.Error("Yes, yes, yes - finally an error")
122122
logger.Errorf("Yes, yes, yes - %v", "finally an error")
123123

124-
waitToDrain(logger)
125124
}

default.go

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -138,12 +138,6 @@ func SetPattern(pattern string) error {
138138
return std.SetPattern(pattern)
139139
}
140140

141-
// IsBufferEmpty returns true if logger buffer is empty otherwise false.
142-
// This method can be used to ensure all the log entry is written successfully.
143-
func IsBufferEmpty() bool {
144-
return std.IsBufferEmpty()
145-
}
146-
147141
func init() {
148142
cfg, _ := config.ParseString("log { }")
149143
std, _ = New(cfg)

default_test.go

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,6 @@ func TestDefaultLogger(t *testing.T) {
4242
testStdPanic("panicf", "this is panicf")
4343
testStdPanic("panicln", "this is panicln")
4444

45-
waitToDrain(std)
4645
}
4746

4847
func TestDefaultLoggerMisc(t *testing.T) {
@@ -55,7 +54,6 @@ func TestDefaultLoggerMisc(t *testing.T) {
5554

5655
assert.Nil(t, SetLevel("trace"))
5756
assert.Nil(t, SetPattern("%level:-5 %message"))
58-
waitToDrain(std)
5957
}
6058

6159
func testStdPanic(method, msg string) {

file_receiver.go

Lines changed: 3 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,10 @@
55
package log
66

77
import (
8-
"errors"
98
"fmt"
109
"io"
1110
"os"
1211
"path/filepath"
13-
"sync"
1412
"time"
1513

1614
"aahframework.org/config.v0"
@@ -21,7 +19,6 @@ var _ Receiver = &FileReceiver{}
2119

2220
// FileReceiver writes the log entry into file.
2321
type FileReceiver struct {
24-
rw *sync.RWMutex
2522
filename string
2623
out io.Writer
2724
formatter string
@@ -44,10 +41,6 @@ type FileReceiver struct {
4441
func (f *FileReceiver) Init(cfg *config.Config) error {
4542
// File
4643
f.filename = cfg.StringDefault("log.file", "")
47-
if ess.IsStrEmpty(f.filename) {
48-
return errors.New("log: file value is required")
49-
}
50-
5144
if err := f.openFile(); err != nil {
5245
return err
5346
}
@@ -76,8 +69,6 @@ func (f *FileReceiver) Init(cfg *config.Config) error {
7669

7770
// SetPattern method initializes the logger format pattern.
7871
func (f *FileReceiver) SetPattern(pattern string) error {
79-
f.rw.Lock()
80-
defer f.rw.Unlock()
8172
flags, err := parseFlag(pattern)
8273
if err != nil {
8374
return err
@@ -101,8 +92,6 @@ func (f *FileReceiver) IsCallerInfo() bool {
10192

10293
// Log method logs the given entry values into file.
10394
func (f *FileReceiver) Log(entry *Entry) {
104-
f.rw.RLock()
105-
defer f.rw.RUnlock()
10695
if f.isRotate() {
10796
_ = f.rotateFile()
10897
}
@@ -180,11 +169,10 @@ func (f *FileReceiver) openFile() error {
180169
}
181170

182171
func (f *FileReceiver) close() {
183-
if f.isClosed {
184-
return
172+
if !f.isClosed {
173+
ess.CloseQuietly(f.out)
174+
f.isClosed = true
185175
}
186-
ess.CloseQuietly(f.out)
187-
f.isClosed = true
188176
}
189177

190178
func (f *FileReceiver) backupFileName() string {

file_receiver_test.go

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -71,21 +71,17 @@ func TestFileLoggerRotation(t *testing.T) {
7171
cleaupFiles("*.log")
7272
}
7373

74-
func TestFileLoggerFileRequired(t *testing.T) {
74+
func TestFileLoggerFileOpenError(t *testing.T) {
7575
fileConfigStr := `
7676
log {
7777
receiver = "file"
78-
level = "debug"
79-
pattern = "%utctime:2006-01-02 15:04:05.000 %level:-5 %longfile %line %custom:- %message"
80-
rotate {
81-
policy = "daily"
82-
}
78+
file = ""
8379
}
8480
`
8581
cfg, _ := config.ParseString(fileConfigStr)
8682
logger, err := New(cfg)
8783
assert.Nil(t, logger)
88-
assert.Equal(t, "log: file value is required", err.Error())
84+
assert.Equal(t, "open : no such file or directory", err.Error())
8985
}
9086

9187
func TestFileLoggerUnsupportedFormat(t *testing.T) {
@@ -160,5 +156,4 @@ func testFileLogger(t *testing.T, cfgStr string, loop int) {
160156
logger.Errorf("Yes, yes, yes - %v", "finally an error")
161157
}
162158

163-
waitToDrain(logger)
164159
}

log.go

Lines changed: 5 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ const (
6565

6666
var (
6767
// Version no. of aahframework.org/log library
68-
Version = "0.3.1"
68+
Version = "0.3.2"
6969

7070
// FmtFlags is the list of log format flags supported by aah/log library
7171
// Usage of flag order is up to format composition.
@@ -124,7 +124,6 @@ type (
124124
m *sync.Mutex
125125
level Level
126126
receiver Receiver
127-
ec chan *Entry
128127
}
129128
)
130129

@@ -156,9 +155,6 @@ func New(cfg *config.Config) (*Logger, error) {
156155
return nil, err
157156
}
158157

159-
logger.ec = make(chan *Entry, 1000) // TODO make it configurable
160-
go logger.listenToEntry()
161-
162158
return logger, nil
163159
}
164160

@@ -186,6 +182,8 @@ func (l *Logger) SetLevel(level string) error {
186182

187183
// SetPattern methods sets the log format pattern.
188184
func (l *Logger) SetPattern(pattern string) error {
185+
l.m.Lock()
186+
defer l.m.Unlock()
189187
if l.receiver == nil {
190188
return ErrLogReceiverIsNil
191189
}
@@ -205,12 +203,6 @@ func (l *Logger) SetReceiver(receiver Receiver) error {
205203
return l.receiver.Init(l.cfg)
206204
}
207205

208-
// IsBufferEmpty returns true if logger buffer is empty otherwise false.
209-
// This method can be used to ensure all the log entry is written successfully.
210-
func (l *Logger) IsBufferEmpty() bool {
211-
return len(l.ec) == 0
212-
}
213-
214206
//‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾
215207
// Logger logging methods
216208
//_______________________________________
@@ -333,6 +325,7 @@ func (l *Logger) output(level Level, calldepth int, format *string, v ...interfa
333325
}
334326

335327
entry := getEntry()
328+
defer putEntry(entry)
336329
entry.Time = time.Now()
337330
entry.Level = level
338331
if format == nil {
@@ -345,14 +338,5 @@ func (l *Logger) output(level Level, calldepth int, format *string, v ...interfa
345338
entry.File, entry.Line = fetchCallerInfo(calldepth)
346339
}
347340

348-
l.ec <- entry
349-
}
350-
351-
// listenToEntry method listens to entry channel and log the entry into receiver.
352-
func (l Logger) listenToEntry() {
353-
for {
354-
entry := <-l.ec
355-
l.receiver.Log(entry)
356-
putEntry(entry)
357-
}
341+
l.receiver.Log(entry)
358342
}

log_test.go

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,6 @@ func TestLogDefault(t *testing.T) {
3333
testPanic(logger, "panic", "this is panic")
3434
testPanic(logger, "panicf", "this is panicf")
3535
testPanic(logger, "panicln", "this is panicln")
36-
waitToDrain(logger)
3736
}
3837

3938
func TestMisc(t *testing.T) {
@@ -120,11 +119,3 @@ func cleaupFiles(match string) {
120119
}
121120
}
122121
}
123-
124-
func waitToDrain(l *Logger) {
125-
for {
126-
if l.IsBufferEmpty() {
127-
break
128-
}
129-
}
130-
}

util.go

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ package log
77
import (
88
"runtime"
99
"strings"
10-
"sync"
1110
"time"
1211
)
1312

@@ -80,9 +79,9 @@ func isCallerInfo(flags *[]FlagPart) bool {
8079

8180
func getReceiverByName(name string) Receiver {
8281
if name == "FILE" {
83-
return &FileReceiver{rw: &sync.RWMutex{}}
82+
return &FileReceiver{}
8483
} else if name == "CONSOLE" {
85-
return &ConsoleReceiver{rw: &sync.RWMutex{}}
84+
return &ConsoleReceiver{}
8685
}
8786
return nil
8887
}

0 commit comments

Comments
 (0)