Skip to content

Commit 1da418b

Browse files
committed
WIP
1 parent ff3132f commit 1da418b

File tree

9 files changed

+95
-41
lines changed

9 files changed

+95
-41
lines changed

.editorconfig

+9
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

+27-16
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

+19-8
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

+19
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

+9-9
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,

discord.go

+1-2
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"
@@ -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
}

file.go

+1-2
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ import (
44
"bytes"
55
"fmt"
66
"io"
7-
"io/ioutil"
87
"log"
98
"os"
109
"path/filepath"
@@ -121,7 +120,7 @@ func (l *fileLogger) initRotation() error {
121120

122121
// If there is any content in the file, count the number of lines.
123122
if l.rotationConfig.MaxLines > 0 && l.currentSize > 0 {
124-
data, err := ioutil.ReadFile(l.filename)
123+
data, err := os.ReadFile(l.filename)
125124
if err != nil {
126125
return fmt.Errorf("read file %q: %v", l.filename, err)
127126
}

go.mod

+9-2
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,17 @@
11
module unknwon.dev/clog/v2
22

3-
go 1.11
3+
go 1.19
44

55
require (
66
github.com/fatih/color v1.7.0
7+
github.com/stretchr/testify v1.4.0
8+
)
9+
10+
require (
11+
github.com/davecgh/go-spew v1.1.0 // indirect
712
github.com/mattn/go-colorable v0.1.4 // indirect
813
github.com/mattn/go-isatty v0.0.10 // indirect
9-
github.com/stretchr/testify v1.4.0
14+
github.com/pmezard/go-difflib v1.0.0 // indirect
15+
golang.org/x/sys v0.0.0-20191008105621-543471e840be // indirect
16+
gopkg.in/yaml.v2 v2.2.2 // indirect
1017
)

slack.go

+1-2
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
)
1211

@@ -73,7 +72,7 @@ func (l *slackLogger) postMessage(r io.Reader) error {
7372
defer resp.Body.Close()
7473

7574
if resp.StatusCode/100 != 2 {
76-
data, err := ioutil.ReadAll(resp.Body)
75+
data, err := io.ReadAll(resp.Body)
7776
if err != nil {
7877
return fmt.Errorf("read HTTP response body: %v", err)
7978
}

0 commit comments

Comments
 (0)