Skip to content

Commit 57b8b70

Browse files
author
Oleg Sklyar
committed
Transferring log to github
1 parent d6f4da7 commit 57b8b70

File tree

16 files changed

+180
-125
lines changed

16 files changed

+180
-125
lines changed

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
.idea/
2+
vendor/
3+
Gopkg.lock

.travis.yml

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
language: go
2+
3+
go:
4+
- 1.8
5+
6+
before_install:
7+
- go get
8+
- touch coverage.txt
9+
- pip install --user codecov
10+
11+
script:
12+
- go test -coverprofile=coverage-log.txt -covermode=atomic github.com/teris-io/log && touch coverage-log.txt
13+
- go test -coverprofile=coverage-log-apex.txt -covermode=atomic github.com/teris-io/log/apex && touch coverage-log-apex.txt
14+
- go test -coverprofile=coverage-log-std.txt -covermode=atomic github.com/teris-io/log/std && touch coverage-log-std.txt
15+
- cat coverage-log.txt coverage-log-apex.txt coverage-log-std.txt > coverage.txt
16+
17+
after_success:
18+
- codecov
19+

Gopkg.toml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
[[constraint]]
2+
name = "github.com/apex/log"
3+
version = "1.0.0"
4+
5+
[[constraint]]
6+
name = "github.com/pkg/errors"
7+
version = "0.8.0"

LICENSE

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
MIT License
2+
3+
Permission is hereby granted, free of charge, to any person obtaining a copy of this
4+
software and associated documentation files (the "Software"), to deal in the Software
5+
without restriction, including without limitation the rights to use, copy, modify,
6+
merge, publish, distribute, sublicense, and/or sell copies of the Software, and to
7+
permit persons to whom the Software is furnished to do so, subject to the following
8+
conditions:
9+
10+
The above copyright notice and this permission notice shall be included in all copies
11+
or substantial portions of the Software.
12+
13+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
14+
INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A
15+
PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
16+
HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
17+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
18+
SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

README.md

Lines changed: 24 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,22 @@
1-
# Structured leveled log interface
1+
[![Build status][buildimage]][build] [![Coverage][codecovimage]][codecov] [![GoReportCard][cardimage]][card] [![API documentation][docsimage]][docs]
22

3-
Package `log` decouples the logger backend from your application. It defines
3+
# Structured log interface
4+
5+
Package `log` provides the separation of the logging interface from its
6+
implementation and decouples the logger backend from your application. It defines
47
a simple, lightweight and comprehensive `Logger` and `Factory` interfaces which
58
can be used through your applications without any knowledge of the particular
69
implemeting backend and can be configured at the application wiring point to
710
bind a particular backend, such as Go's standard logger, `apex/log`, `logrus`,
811
with ease.
912

10-
To complement the facade, the package `code.teris.io/util/log/std` provides an
13+
To complement the facade, the package `github.com/teris-io/log/std` provides an
1114
implementation using the standard Go logger. The default log formatter for
1215
this implementation uses colour coding for log levels and logs the date
1316
leaving out the month and the year on the timestamp. However, the formatter
1417
is fully configurable.
1518

16-
Similarly, the package `code.teris.io/util/log/apex` provides and implementation
19+
Similarly, the package `github.com/teris-io/log/apex` provides and implementation
1720
using the `apex/log` logger backend.
1821

1922

@@ -26,7 +29,7 @@ type Logger interface {
2629
Level(lvl LogLevel) Logger
2730
Field(k string, v interface{}) Logger
2831
Fields(data map[string]interface{}) Logger
29-
WithError(err error) Logger
32+
Error(err error) Logger
3033
Log(msg string) Tracer
3134
Logf(format string, v ...interface{}) Tracer
3235
}
@@ -52,19 +55,19 @@ The log can be used both statically by binding a particular logger factory:
5255

5356
```go
5457
func init() {
55-
std.Use(os.Stderr, log.Info, std.DefaultFmtFun)
58+
std.Use(os.Stderr, log.InfoLevel, std.DefaultFmtFun)
5659
}
5760

5861
// elsewhere
59-
logger := log.Level(log.Info).Field("key", "value")
62+
logger := log.Level(log.InfoLevel).Field("key", "value")
6063
logger.Log("message")
6164
```
6265

6366
and dynamically by always going via a factory:
6467

6568
```go
66-
factory := std.NewFactory(os.Stderr, log.Info, std.DefaultFmtFun)
67-
logger := factory.Level(log.Info).Field("key", "value")
69+
factory := std.NewFactory(os.Stderr, log.InfoLevel, std.DefaultFmtFun)
70+
logger := factory.Level(log.InfoLevel).Field("key", "value")
6871
logger.Log("message")
6972
```
7073

@@ -76,7 +79,7 @@ To simplify debugging with execution time tracing, the `Log` and `Logf` methods
7679
return a tracer that can be used to measure and log the execution time:
7780

7881
```go
79-
logger := log.Level(log.Debug).Field("key", "value")
82+
logger := log.Level(log.DebugLevel).Field("key", "value")
8083

8184
defer logger.Log("start").Trace()
8285
// code to trace the execution time of
@@ -88,25 +91,19 @@ the selected `Debug` level (her for the default formatter of the `std` logger):
8891
08 16:31:42.023798 DBG start {key: value}
8992
08 16:31:45.127619 DBG traced {duration: 3.103725832}, {key: value}
9093

91-
# License and copyright
94+
### License and copyright
95+
96+
Copyright (c) 2017. Oleg Sklyar and teris.io. MIT license applies. All rights reserved.
9297

93-
Copyright (c) 2017 Oleg Sklyar & teris.io
9498

95-
MIT License
99+
[build]: https://travis-ci.org/teris-io/log
100+
[buildimage]: https://travis-ci.org/teris-io/log.svg?branch=master
96101

97-
Permission is hereby granted, free of charge, to any person obtaining a copy of this
98-
software and associated documentation files (the "Software"), to deal in the Software
99-
without restriction, including without limitation the rights to use, copy, modify,
100-
merge, publish, distribute, sublicense, and/or sell copies of the Software, and to
101-
permit persons to whom the Software is furnished to do so, subject to the following
102-
conditions:
102+
[codecov]: https://codecov.io/github/teris-io/log?branch=master
103+
[codecovimage]: https://codecov.io/github/teris-io/log/coverage.svg?branch=master
103104

104-
The above copyright notice and this permission notice shall be included in all copies
105-
or substantial portions of the Software.
105+
[card]: http://goreportcard.com/report/teris-io/log
106+
[cardimage]: https://goreportcard.com/badge/github.com/teris-io/log
106107

107-
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
108-
INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A
109-
PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
110-
HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
111-
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
112-
SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
108+
[docs]: https://godoc.org/github.com/teris-io/log
109+
[docsimage]: http://img.shields.io/badge/godoc-reference-blue.svg?style=flat

apex/factory.go

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,15 @@
1-
// Copyright (c) 2017 Oleg Sklyar & teris.io.
1+
// Copyright (c) 2017. Oleg Sklyar & teris.io. All rights reserved.
2+
// See the LICENSE file in the project root for licensing information.
23

34
package apex
45

56
import (
6-
"code.teris.io/util/log"
77
alog "github.com/apex/log"
8+
"github.com/teris-io/log"
89
)
910

1011
func NewFactory(root *alog.Logger) log.Factory {
11-
return &factory{root: root, min: log.Unset}
12+
return &factory{root: root, min: log.UnsetLevel}
1213
}
1314

1415
func Use(root *alog.Logger) log.Factory {
@@ -19,15 +20,15 @@ func Use(root *alog.Logger) log.Factory {
1920

2021
type factory struct {
2122
root *alog.Logger
22-
min log.LogLevel
23+
min log.LoggerLevel
2324
}
2425

2526
var _ log.Factory = (*factory)(nil)
2627

2728
func (f *factory) New() log.Logger {
28-
return &logger{factory: f, lvl: log.Unset, ctx: alog.NewEntry(f.root)}
29+
return &logger{factory: f, lvl: log.UnsetLevel, ctx: alog.NewEntry(f.root)}
2930
}
3031

31-
func (f *factory) Threshold(min log.LogLevel) {
32+
func (f *factory) Threshold(min log.LoggerLevel) {
3233
f.min = min
3334
}

apex/logger.go

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
// Copyright (c) 2017 Oleg Sklyar & teris.io
1+
// Copyright (c) 2017. Oleg Sklyar & teris.io. All rights reserved.
2+
// See the LICENSE file in the project root for licensing information.
23

34
// Package apex provides a logger implementation using the github.com/apex/log backends.
45
package apex
@@ -7,19 +8,19 @@ import (
78
"fmt"
89
"time"
910

10-
"code.teris.io/util/log"
1111
alog "github.com/apex/log"
12+
"github.com/teris-io/log"
1213
)
1314

1415
var _ log.Logger = (*logger)(nil)
1516

1617
type logger struct {
1718
*factory
18-
lvl log.LogLevel
19+
lvl log.LoggerLevel
1920
ctx *alog.Entry
2021
}
2122

22-
func (l *logger) Level(lvl log.LogLevel) log.Logger {
23+
func (l *logger) Level(lvl log.LoggerLevel) log.Logger {
2324
return &logger{factory: l.factory, lvl: lvl, ctx: l.ctx}
2425
}
2526

@@ -35,18 +36,18 @@ func (l *logger) Fields(data map[string]interface{}) log.Logger {
3536
return &logger{factory: l.factory, lvl: l.lvl, ctx: l.ctx.WithFields(fields)}
3637
}
3738

38-
func (l *logger) WithError(err error) log.Logger {
39+
func (l *logger) Error(err error) log.Logger {
3940
return &logger{factory: l.factory, lvl: l.lvl, ctx: l.ctx.WithError(err)}
4041
}
4142

4243
func (l *logger) Log(msg string) log.Tracer {
4344
if l.lvl >= l.factory.min {
4445
switch {
45-
case l.lvl <= log.Debug:
46+
case l.lvl <= log.DebugLevel:
4647
l.ctx.Debug(msg)
47-
case l.lvl == log.Info:
48+
case l.lvl == log.InfoLevel:
4849
l.ctx.Info(msg)
49-
case l.lvl >= log.Error:
50+
case l.lvl >= log.ErrorLevel:
5051
l.ctx.Error(msg)
5152
}
5253
}

doc.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
// Copyright (c) 2017 Oleg Sklyar & teris.io.
1+
// Copyright (c) 2017. Oleg Sklyar & teris.io. All rights reserved.
2+
// See the LICENSE file in the project root for licensing information.
23

34
// Package log defines the Logger interface for a structured leveled log, the Factory
45
// interface to create instances of the Logger and the Tracer interface used to trace

logger.go

Lines changed: 18 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,20 @@
1-
// Copyright (c) 2017 Oleg Sklyar & teris.io
1+
// Copyright (c) 2017. Oleg Sklyar & teris.io. All rights reserved.
2+
// See the LICENSE file in the project root for licensing information.
23

34
package log
45

5-
// LogLevel defines level markers for log entries.
6-
type LogLevel int
6+
// LoggerLevel defines level markers for log entries.
7+
type LoggerLevel int
78

89
const (
9-
// Unset level should not be output by logger implementation.
10-
Unset = iota - 2
11-
// Debug level marks detailed output for design purposes.
12-
Debug
13-
// Info level is the default log output marker.
14-
Info
15-
// Error level marks an error output.
16-
Error
10+
// UnsetLevel should not be output by logger implementation.
11+
UnsetLevel = iota - 2
12+
// DebugLevel marks detailed output for design purposes.
13+
DebugLevel
14+
// InfoLevel is the default log output marker.
15+
InfoLevel
16+
// ErrorLevel marks an error output.
17+
ErrorLevel
1718
)
1819

1920
// Factory defines a utility to create new loggers and set the log level threshold.
@@ -22,25 +23,25 @@ type Factory interface {
2223
//New creates a new logger.
2324
New() Logger
2425

25-
// Threshold sets the minimum log level threshold for messages to be output.
26-
Threshold(min LogLevel)
26+
// Threshold sets the minimum logger level threshold for messages to be output.
27+
Threshold(min LoggerLevel)
2728
}
2829

2930
// Logger defines the logger interface.
3031
type Logger interface {
3132

3233
// Level creates a new logger instance from the current one setting its log level to the value supplied.
33-
Level(lvl LogLevel) Logger
34+
Level(lvl LoggerLevel) Logger
3435

3536
// Field creates a new logger instance from the current one adding a new field value.
3637
Field(k string, v interface{}) Logger
3738

3839
// Fields creates a new logger instance from the current one adding a collection of field values.
3940
Fields(data map[string]interface{}) Logger
4041

41-
// WithError creates a new logger instance from the current one adding an error
42-
// and setting the level to Error.
43-
WithError(err error) Logger
42+
// Error creates a new logger instance from the current one adding an error
43+
// and setting the level to ErrorLevel.
44+
Error(err error) Logger
4445

4546
// Log outputs the log structure along with a message if the logger level is above or matching
4647
// the threshold set in the factory.

noop.go

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
// Copyright (c) 2017 Oleg Sklyar & teris.io.
1+
// Copyright (c) 2017. Oleg Sklyar & teris.io. All rights reserved.
2+
// See the LICENSE file in the project root for licensing information.
23

34
package log
45

@@ -17,10 +18,10 @@ func (n *noop) New() Logger {
1718
return &noop{}
1819
}
1920

20-
func (n *noop) Threshold(lvl LogLevel) {
21+
func (n *noop) Threshold(lvl LoggerLevel) {
2122
}
2223

23-
func (n *noop) Level(lvl LogLevel) Logger {
24+
func (n *noop) Level(lvl LoggerLevel) Logger {
2425
return n
2526
}
2627

@@ -32,7 +33,7 @@ func (n *noop) Fields(data map[string]interface{}) Logger {
3233
return n
3334
}
3435

35-
func (n *noop) WithError(err error) Logger {
36+
func (n *noop) Error(err error) Logger {
3637
return n
3738
}
3839

0 commit comments

Comments
 (0)