Skip to content

Commit a4b3ded

Browse files
committed
WIP
1 parent ff3132f commit a4b3ded

17 files changed

+141
-88
lines changed

.editorconfig

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
# Docs: http://editorconfig.org
2+
3+
root = true
4+
5+
[*]
6+
charset = utf-8
7+
end_of_line = lf
8+
insert_final_newline = true
9+
trim_trailing_whitespace = true

.github/workflows/go.yml

Lines changed: 27 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,18 @@
11
name: Go
22
on:
33
push:
4-
branches: [master]
4+
branches: [ main ]
5+
paths:
6+
- '**.go'
7+
- 'go.mod'
8+
- '.golangci.yml'
9+
- '.github/workflows/go.yml'
510
pull_request:
11+
paths:
12+
- '**.go'
13+
- 'go.mod'
14+
- '.golangci.yml'
15+
- '.github/workflows/go.yml'
616
env:
717
GOPROXY: "https://proxy.golang.org"
818

@@ -11,35 +21,36 @@ jobs:
1121
name: Lint
1222
runs-on: ubuntu-latest
1323
steps:
14-
- uses: actions/checkout@v2
24+
- name: Install Go
25+
uses: actions/setup-go@v3
26+
with:
27+
go-version: 1.20.x
28+
- name: Checkout code
29+
uses: actions/checkout@v3
1530
- name: Run golangci-lint
16-
uses: actions-contrib/golangci-lint@v1
31+
uses: golangci/golangci-lint-action@v3
32+
with:
33+
version: latest
34+
args: --timeout=30m
1735

1836
test:
1937
name: Test
2038
strategy:
2139
matrix:
22-
go-version: [1.14.x, 1.15.x]
23-
platform: [ubuntu-latest, macos-latest, windows-latest]
40+
go-version: [ 1.19.x, 1.20.x ]
41+
platform: [ ubuntu-latest, macos-latest, windows-latest ]
2442
runs-on: ${{ matrix.platform }}
2543
steps:
2644
- name: Install Go
27-
uses: actions/setup-go@v1
45+
uses: actions/setup-go@v3
2846
with:
2947
go-version: ${{ matrix.go-version }}
3048
- name: Checkout code
31-
uses: actions/checkout@v2
32-
- name: Run unit tests
49+
uses: actions/checkout@v3
50+
- name: Run tests with coverage
3351
run: go test -v -race -coverprofile=coverage -covermode=atomic ./...
3452
- name: Upload coverage report to Codecov
35-
uses: codecov/codecov-action@v1.0.6
53+
uses: codecov/codecov-action@v1.5.0
3654
with:
3755
file: ./coverage
3856
flags: unittests
39-
- name: Cache downloaded modules
40-
uses: actions/cache@v1
41-
with:
42-
path: ~/go/pkg/mod
43-
key: ${{ runner.os }}-go-${{ hashFiles('**/go.sum') }}
44-
restore-keys: |
45-
${{ runner.os }}-go-

.github/workflows/lsif.yml

Lines changed: 19 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,28 @@
11
name: LSIF
2-
on: [push]
2+
on:
3+
push:
4+
paths:
5+
- '**.go'
6+
- 'go.mod'
7+
- '.github/workflows/lsif.yml'
8+
env:
9+
GOPROXY: "https://proxy.golang.org"
10+
311
jobs:
4-
build:
12+
lsif-go:
13+
if: github.repository == 'go-clog/clog'
514
runs-on: ubuntu-latest
615
steps:
7-
- uses: actions/checkout@v1
16+
- uses: actions/checkout@v3
817
- name: Generate LSIF data
918
uses: sourcegraph/lsif-go-action@master
19+
- name: Upload LSIF data to sourcegraph.com
20+
continue-on-error: true
21+
uses: docker://sourcegraph/src-cli:latest
1022
with:
11-
verbose: 'true'
12-
- name: Upload LSIF data
13-
uses: sourcegraph/lsif-upload-action@master
23+
args: lsif upload -github-token=${{ secrets.GITHUB_TOKEN }}
24+
- name: Upload LSIF data to cs.unknwon.dev
1425
continue-on-error: true
26+
uses: docker://sourcegraph/src-cli:latest
1527
with:
16-
endpoint: https://sourcegraph.com
17-
github_token: ${{ secrets.GITHUB_TOKEN }}
28+
args: -endpoint=https://cs.unknwon.dev lsif upload -github-token=${{ secrets.GITHUB_TOKEN }}

.golangci.yml

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
linters-settings:
2+
nakedret:
3+
max-func-lines: 0 # Disallow any unnamed return statement
4+
5+
linters:
6+
enable:
7+
- unused
8+
- errcheck
9+
- gosimple
10+
- govet
11+
- ineffassign
12+
- staticcheck
13+
- typecheck
14+
- nakedret
15+
- gofmt
16+
- rowserrcheck
17+
- unconvert
18+
- goimports
19+
- unparam

README.md

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# Clog
1+
# Clog
22

33
[![GitHub Workflow Status](https://img.shields.io/github/workflow/status/go-clog/clog/Go?logo=github&style=for-the-badge)](https://github.com/go-clog/clog/actions?query=workflow%3AGo)
44
[![codecov](https://img.shields.io/codecov/c/github/go-clog/clog/master?logo=codecov&style=for-the-badge)](https://codecov.io/gh/go-clog/clog)
@@ -13,10 +13,10 @@ This package supports multiple loggers across different levels of logging. It us
1313

1414
## Installation
1515

16-
The minimum requirement of Go is **1.11**.
16+
The minimum requirement of Go is **1.19**.
1717

1818
go get unknwon.dev/clog/v2
19-
19+
2020
Please apply `-u` flag to update in the future.
2121

2222
## Getting Started
@@ -51,7 +51,7 @@ The code inside `init` function is equivalent to the following:
5151

5252
```go
5353
func init() {
54-
err := log.NewConsole(0,
54+
err := log.NewConsole(0,
5555
log.ConsoleConfig{
5656
Level: log.LevelTrace,
5757
},
@@ -66,7 +66,7 @@ Or expand further:
6666

6767
```go
6868
func init() {
69-
err := log.NewConsoleWithName(log.DefaultConsoleName, 0,
69+
err := log.NewConsoleWithName(log.DefaultConsoleName, 0,
7070
log.ConsoleConfig{
7171
Level: log.LevelTrace,
7272
},
@@ -85,7 +85,7 @@ In production, you may want to make log less verbose and be asynchronous:
8585

8686
```go
8787
func init() {
88-
// The buffer size mainly depends on number of logs could be produced at the same time,
88+
// The buffer size mainly depends on number of logs could be produced at the same time,
8989
// 100 is a good default.
9090
err := log.NewConsole(100,
9191
log.ConsoleConfig{
@@ -145,7 +145,7 @@ func main() {
145145

146146
### Caller Location
147147

148-
When using `log.Error` and `log.Fatal` functions, the caller location is written along with logs.
148+
When using `log.Error` and `log.Fatal` functions, the caller location is written along with logs.
149149

150150
```go
151151
func main() {
@@ -171,10 +171,10 @@ File logger is the single most powerful builtin logger, it has the ability to ro
171171

172172
```go
173173
func init() {
174-
err := log.NewFile(100,
174+
err := log.NewFile(100,
175175
log.FileConfig{
176176
Level: log.LevelInfo,
177-
Filename: "clog.log",
177+
Filename: "clog.log",
178178
FileRotationConfig: log.FileRotationConfig {
179179
Rotate: true,
180180
Daily: true,

clog.go

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ type Level int
1111

1212
// Available logging levels.
1313
const (
14-
LevelTrace Level = iota
14+
LevelDebug Level = iota
1515
LevelInfo
1616
LevelWarn
1717
LevelError
@@ -20,8 +20,8 @@ const (
2020

2121
func (l Level) String() string {
2222
switch l {
23-
case LevelTrace:
24-
return "TRACE"
23+
case LevelDebug:
24+
return "DEBUG"
2525
case LevelInfo:
2626
return "INFO"
2727
case LevelWarn:
@@ -36,9 +36,9 @@ func (l Level) String() string {
3636
}
3737
}
3838

39-
// Trace writes formatted log in Trace level.
40-
func Trace(format string, v ...interface{}) {
41-
mgr.write(LevelTrace, 0, format, v...)
39+
// Debug writes formatted log in Debug level.
40+
func Debug(format string, v ...interface{}) {
41+
mgr.write(LevelDebug, 0, format, v...)
4242
}
4343

4444
// Info writes formatted log in Info level.
@@ -85,9 +85,9 @@ func FatalDepth(skip int, format string, v ...interface{}) {
8585
exit()
8686
}
8787

88-
// TraceTo writes formatted log in Trace level to the logger with given name.
89-
func TraceTo(name, format string, v ...interface{}) {
90-
mgr.writeTo(name, LevelTrace, 0, format, v...)
88+
// DebugTo writes formatted log in Debug level to the logger with given name.
89+
func DebugTo(name, format string, v ...interface{}) {
90+
mgr.writeTo(name, LevelDebug, 0, format, v...)
9191
}
9292

9393
// InfoTo writes formatted log in Info level to the logger with given name.

clog_test.go

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ func chanLoggerIniter(name string, level Level) Initer {
6262

6363
func Test_chanLogger(t *testing.T) {
6464
test1 := "mode1"
65-
test1Initer := chanLoggerIniter(test1, LevelTrace)
65+
test1Initer := chanLoggerIniter(test1, LevelDebug)
6666

6767
test2 := "mode2"
6868
test2Initer := chanLoggerIniter(test2, LevelError)
@@ -87,8 +87,8 @@ func Test_chanLogger(t *testing.T) {
8787
}{
8888
{
8989
name: "trace",
90-
fn: Trace,
91-
containsStr1: "[TRACE] log message",
90+
fn: Debug,
91+
containsStr1: "[DEBUG] log message",
9292
containsStr2: "",
9393
},
9494
{
@@ -133,10 +133,10 @@ func Test_chanLogger(t *testing.T) {
133133

134134
func Test_writeToNamedLogger(t *testing.T) {
135135
test1 := "alice"
136-
test1Initer := chanLoggerIniter(test1, LevelTrace)
136+
test1Initer := chanLoggerIniter(test1, LevelDebug)
137137

138138
test2 := "bob"
139-
test2Initer := chanLoggerIniter(test2, LevelTrace)
139+
test2Initer := chanLoggerIniter(test2, LevelDebug)
140140

141141
c1 := make(chan string)
142142
c2 := make(chan string)
@@ -158,8 +158,8 @@ func Test_writeToNamedLogger(t *testing.T) {
158158
}{
159159
{
160160
name: "trace",
161-
fn: TraceTo,
162-
containsStr1: "[TRACE] log message",
161+
fn: DebugTo,
162+
containsStr1: "[DEBUG] log message",
163163
containsStr2: "",
164164
},
165165
{

console.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import (
88

99
// consoleColors is the color set for different levels.
1010
var consoleColors = []func(a ...interface{}) string{
11-
color.New(color.FgBlue).SprintFunc(), // Trace
11+
color.New(color.FgBlue).SprintFunc(), // Debug
1212
color.New(color.FgGreen).SprintFunc(), // Info
1313
color.New(color.FgYellow).SprintFunc(), // Warn
1414
color.New(color.FgRed).SprintFunc(), // Error

console_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,5 +47,5 @@ func Test_consoleLogger(t *testing.T) {
4747
assert.Equal(t, DefaultConsoleName, mgr.loggers[0].Name())
4848
assert.Equal(t, LevelInfo, mgr.loggers[0].Level())
4949
assert.Equal(t, testName, mgr.loggers[1].Name())
50-
assert.Equal(t, LevelTrace, mgr.loggers[1].Level())
50+
assert.Equal(t, LevelDebug, mgr.loggers[1].Level())
5151
}

discord.go

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ import (
66
"errors"
77
"fmt"
88
"io"
9-
"io/ioutil"
109
"net/http"
1110
"strings"
1211
"time"
@@ -28,15 +27,15 @@ type (
2827

2928
var (
3029
discordTitles = []string{
31-
"Trace",
30+
"Debug",
3231
"Information",
3332
"Warning",
3433
"Error",
3534
"Fatal",
3635
}
3736

3837
discordColors = []int{
39-
0, // Trace
38+
0, // Debug
4039
3843043, // Info
4140
16761600, // Warn
4241
13041721, // Error
@@ -54,10 +53,10 @@ type DiscordConfig struct {
5453
// Leave empty to use default as set in the Discord.
5554
Username string
5655
// Title for different levels, must have exact 5 elements in the order of
57-
// Trace, Info, Warn, Error, and Fatal.
56+
// Debug, Info, Warn, Error, and Fatal.
5857
Titles []string
5958
// Colors for different levels, must have exact 5 elements in the order of
60-
// Trace, Info, Warn, Error, and Fatal.
59+
// Debug, Info, Warn, Error, and Fatal.
6160
Colors []int
6261
}
6362

@@ -117,7 +116,7 @@ func (l *discordLogger) postMessage(r io.Reader) (int64, error) {
117116

118117
return rateLimitMsg.RetryAfter, nil
119118
} else if resp.StatusCode/100 != 2 {
120-
data, err := ioutil.ReadAll(resp.Body)
119+
data, err := io.ReadAll(resp.Body)
121120
if err != nil {
122121
return -1, fmt.Errorf("read HTTP response body: %v", err)
123122
}

0 commit comments

Comments
 (0)