Skip to content

Commit

Permalink
Merge pull request #7 for v0.6 lib-log Release
Browse files Browse the repository at this point in the history
  • Loading branch information
jeevatkm authored Jun 1, 2017
2 parents 3b9231d + f32cca0 commit 336897b
Show file tree
Hide file tree
Showing 10 changed files with 53 additions and 5 deletions.
1 change: 0 additions & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ branches:
- /^v[0-9]\.[0-9]/

go:
- 1.7.x
- 1.8
- 1.8.x
- tip
Expand Down
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
# log - aah framework
[![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)
[![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)
[![Version](https://img.shields.io/badge/version-0.4-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)
[![License](https://img.shields.io/github/license/go-aah/log.svg)](LICENSE)

***v0.3.2 [released](https://github.com/go-aah/log/releases/latest) and tagged on May 17, 2017***
***v0.4 [released](https://github.com/go-aah/log/releases/latest) and tagged on Jun 01, 2017***

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

Expand Down
5 changes: 5 additions & 0 deletions console_receiver.go
Original file line number Diff line number Diff line change
Expand Up @@ -91,3 +91,8 @@ func (c *ConsoleReceiver) Log(entry *Entry) {
_, _ = c.out.Write(resetColor)
}
}

// Writer method returns the current log writer.
func (c *ConsoleReceiver) Writer() io.Writer {
return c.out
}
1 change: 1 addition & 0 deletions console_receiver_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -121,4 +121,5 @@ func testConsoleLogger(t *testing.T, cfgStr string) {
logger.Error("Yes, yes, yes - finally an error")
logger.Errorf("Yes, yes, yes - %v", "finally an error")

assert.NotNil(t, logger.ToGoLogger())
}
12 changes: 12 additions & 0 deletions default.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ package log

import (
"fmt"
"io"
slog "log"
"os"

"aahframework.org/config.v0"
Expand Down Expand Up @@ -123,6 +125,16 @@ func Panicln(format string, v ...interface{}) {
panic(fmt.Sprintf(format, v...))
}

// Writer method returns the writer of default logger.
func Writer() io.Writer {
return std.receiver.Writer()
}

// ToGoLogger method wraps the current log writer into Go Logger instance.
func ToGoLogger() *slog.Logger {
return std.ToGoLogger()
}

// SetDefaultLogger method sets the given logger instance as default logger.
func SetDefaultLogger(l *Logger) {
std = l
Expand Down
12 changes: 11 additions & 1 deletion discard_receiver.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,12 @@

package log

import "aahframework.org/config.v0"
import (
"io"
"io/ioutil"

"aahframework.org/config.v0"
)

var _ Receiver = &DiscardReceiver{}

Expand All @@ -31,3 +36,8 @@ func (d *DiscardReceiver) IsCallerInfo() bool {
// Log method writes the buf to
func (d *DiscardReceiver) Log(_ *Entry) {
}

// Writer method returns the current log writer.
func (d *DiscardReceiver) Writer() io.Writer {
return ioutil.Discard
}
5 changes: 5 additions & 0 deletions file_receiver.go
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,11 @@ func (f *FileReceiver) Log(entry *Entry) {
f.stats.lines++
}

// Writer method returns the current log writer.
func (f *FileReceiver) Writer() io.Writer {
return f.out
}

//‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾
// FileReceiver Unexported methods
//___________________________________
Expand Down
2 changes: 2 additions & 0 deletions file_receiver_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ func TestFileLoggerRotation(t *testing.T) {
}
`
testFileLogger(t, fileConfigStrJSON, 1000)

cleaupFiles("*.log")
}

Expand Down Expand Up @@ -156,4 +157,5 @@ func testFileLogger(t *testing.T, cfgStr string, loop int) {
logger.Errorf("Yes, yes, yes - %v", "finally an error")
}

assert.NotNil(t, logger.ToGoLogger())
}
10 changes: 9 additions & 1 deletion log.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ package log
import (
"errors"
"fmt"
"io"
slog "log"
"os"
"strings"
"sync"
Expand Down Expand Up @@ -65,7 +67,7 @@ const (

var (
// Version no. of aahframework.org/log library
Version = "0.3.2"
Version = "0.4"

// FmtFlags is the list of log format flags supported by aah/log library
// Usage of flag order is up to format composition.
Expand Down Expand Up @@ -113,6 +115,7 @@ type (
Init(cfg *config.Config) error
SetPattern(pattern string) error
IsCallerInfo() bool
Writer() io.Writer
Log(e *Entry)
}

Expand Down Expand Up @@ -203,6 +206,11 @@ func (l *Logger) SetReceiver(receiver Receiver) error {
return l.receiver.Init(l.cfg)
}

// ToGoLogger method wraps the current log writer into Go Logger instance.
func (l *Logger) ToGoLogger() *slog.Logger {
return slog.New(l.receiver.Writer(), "", slog.LstdFlags)
}

//‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾
// Logger logging methods
//_______________________________________
Expand Down
6 changes: 6 additions & 0 deletions log_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -72,10 +72,16 @@ func TestMisc(t *testing.T) {
discard.Log(&Entry{})
_ = discard.SetPattern("nothing")
assert.False(t, discard.IsCallerInfo())
assert.NotNil(t, discard.Writer())

// util
assert.Nil(t, getReceiverByName("SMTP"))
assert.Equal(t, "", formatTime(time.Time{}))

stdLogger := ToGoLogger()
assert.NotNil(t, stdLogger)
assert.NotNil(t, Writer())
stdLogger.Print("This is aah logger binds go logger")
}

func testPanic(logger *Logger, method, msg string) {
Expand Down

0 comments on commit 336897b

Please sign in to comment.