Compare commits
117 Commits
Author | SHA1 | Date | |
---|---|---|---|
5a9dd890c9 | |||
19cd5176ff | |||
b91363711d | |||
4b742c9cd7 | |||
ea99cc8198 | |||
3da95653e2 | |||
6c908ebd69 | |||
|
3e418b76e0 | ||
5bb762d9b5 | |||
|
9966e75492 | ||
486ea127f2 | |||
|
7b15b140e4 | ||
d02a482045 | |||
|
fc7a00cc38 | ||
a509265564 | |||
|
50540e4133 | ||
e106f5a4c2 | |||
|
5dce459146 | ||
46868f0eed | |||
|
fabff66844 | ||
8156019ff9 | |||
|
692ca035eb | ||
418361cd61 | |||
|
621b2dd0bb | ||
191adb95dd | |||
|
1d0a53d572 | ||
|
33e14d9b85 | ||
5a5b36930b | |||
|
207cbc314b | ||
|
0fa560ef7c | ||
|
9032a0266a | ||
97a5cfe33f | |||
|
36ff574d1e | ||
ed6f4be73e | |||
|
ea38c28ba9 | ||
25157bc9dc | |||
|
1977881f51 | ||
fdd0bacb41 | |||
|
40d51a67f9 | ||
1ef45cff33 | |||
|
9ede0f70f2 | ||
cb7c8b45c6 | |||
|
2c9104668a | ||
a1e4130dbd | |||
|
688a9a5cb9 | ||
e5cfd521fe | |||
|
3006854e7c | ||
|
edae451dbc | ||
eaf4ac9dbc | |||
|
da9a34c1cb | ||
|
f0a8bf12ce | ||
|
0c315d2142 | ||
e1623bf563 | |||
5affde888c | |||
|
3179852f9d | ||
|
9e393a99c2 | ||
|
b488a82f6f | ||
4294b71aac | |||
|
9b16be3466 | ||
afcca7ae36 | |||
|
714535523d | ||
|
7bd30c1c81 | ||
|
213ce28161 | ||
b2ad97e5a6 | |||
|
b5b85b0c3b | ||
|
939823eb3b | ||
|
0f615e6701 | ||
b7ecb64878 | |||
|
c3e569132c | ||
b380947034 | |||
|
b7f5cb955c | ||
60028ac953 | |||
|
cf9453b598 | ||
3f520903ed | |||
|
aea25a80d7 | ||
8d60a03ebd | |||
|
e5db4473d8 | ||
d8bfab1c70 | |||
|
2404a7ebb9 | ||
1bbbdf8ea6 | |||
|
2180be4f3f | ||
0bfb2385db | |||
79cb510588 | |||
|
eadecfaa73 | ||
|
0be0050b64 | ||
afdd0fb738 | |||
dbd3fe46ab | |||
25787fb5ab | |||
6cf7d92904 | |||
|
d61bd2730f | ||
93f51a5daf | |||
|
4a7f8e0421 | ||
279dd3c355 | |||
|
c75978840e | ||
1b56f23e8a | |||
|
bd258bbb01 | ||
3c4ad27014 | |||
|
491c167bde | ||
307e05b57d | |||
37ae3ae741 | |||
c770f3ed21 | |||
|
7fc6abfd5b | ||
568809917d | |||
|
8a8faf6ed9 | ||
5d5678c53f | |||
|
6298114470 | ||
e4c79f2e69 | |||
|
887bb21c2c | ||
8b48ac4ef2 | |||
|
59fa763a50 | ||
2fc2e03512 | |||
|
6f9e9d3baf | ||
190a78fd70 | |||
|
9e9554b4db | ||
ca301c9777 | |||
|
0ca3f8e709 | ||
f4c8a9d18c |
20
.github/workflows/autoapprove.yml
vendored
Normal file
20
.github/workflows/autoapprove.yml
vendored
Normal file
@ -0,0 +1,20 @@
|
||||
name: "autoapprove"
|
||||
|
||||
on:
|
||||
pull_request_target:
|
||||
types: [assigned, opened, synchronize, reopened]
|
||||
|
||||
permissions:
|
||||
pull-requests: write
|
||||
contents: write
|
||||
|
||||
jobs:
|
||||
autoapprove:
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- name: approve
|
||||
uses: hmarr/auto-approve-action@v3
|
||||
if: github.actor == 'vtolstov' || github.actor == 'dependabot[bot]'
|
||||
id: approve
|
||||
with:
|
||||
github-token: ${{ secrets.GITHUB_TOKEN }}
|
21
.github/workflows/automerge.yml
vendored
Normal file
21
.github/workflows/automerge.yml
vendored
Normal file
@ -0,0 +1,21 @@
|
||||
name: "automerge"
|
||||
|
||||
on:
|
||||
pull_request_target:
|
||||
types: [assigned, opened, synchronize, reopened]
|
||||
|
||||
permissions:
|
||||
pull-requests: write
|
||||
contents: write
|
||||
|
||||
jobs:
|
||||
automerge:
|
||||
runs-on: ubuntu-latest
|
||||
if: github.actor == 'vtolstov'
|
||||
steps:
|
||||
- name: merge
|
||||
id: merge
|
||||
run: gh pr merge --auto --merge "$PR_URL"
|
||||
env:
|
||||
PR_URL: ${{github.event.pull_request.html_url}}
|
||||
GITHUB_TOKEN: ${{secrets.TOKEN}}
|
13
.github/workflows/build.yml
vendored
13
.github/workflows/build.yml
vendored
@ -3,19 +3,20 @@ on:
|
||||
push:
|
||||
branches:
|
||||
- master
|
||||
- v3
|
||||
jobs:
|
||||
test:
|
||||
name: test
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- name: setup
|
||||
uses: actions/setup-go@v2
|
||||
uses: actions/setup-go@v3
|
||||
with:
|
||||
go-version: 1.16
|
||||
go-version: 1.17
|
||||
- name: checkout
|
||||
uses: actions/checkout@v2
|
||||
uses: actions/checkout@v3
|
||||
- name: cache
|
||||
uses: actions/cache@v2
|
||||
uses: actions/cache@v3
|
||||
with:
|
||||
path: ~/go/pkg/mod
|
||||
key: ${{ runner.os }}-go-${{ hashFiles('**/go.sum') }}
|
||||
@ -31,9 +32,9 @@ jobs:
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- name: checkout
|
||||
uses: actions/checkout@v2
|
||||
uses: actions/checkout@v3
|
||||
- name: lint
|
||||
uses: golangci/golangci-lint-action@v2
|
||||
uses: golangci/golangci-lint-action@v3.4.0
|
||||
continue-on-error: true
|
||||
with:
|
||||
# Required: the version of golangci-lint is required and must be specified without patch version: we always use the latest patch version.
|
||||
|
12
.github/workflows/codeql-analysis.yml
vendored
12
.github/workflows/codeql-analysis.yml
vendored
@ -43,14 +43,14 @@ jobs:
|
||||
|
||||
steps:
|
||||
- name: checkout
|
||||
uses: actions/checkout@v2
|
||||
uses: actions/checkout@v3
|
||||
- name: setup
|
||||
uses: actions/setup-go@v2
|
||||
uses: actions/setup-go@v3
|
||||
with:
|
||||
go-version: 1.16
|
||||
go-version: 1.17
|
||||
# Initializes the CodeQL tools for scanning.
|
||||
- name: init
|
||||
uses: github/codeql-action/init@v1
|
||||
uses: github/codeql-action/init@v2
|
||||
with:
|
||||
languages: ${{ matrix.language }}
|
||||
# If you wish to specify custom queries, you can do so here or in a config file.
|
||||
@ -61,7 +61,7 @@ jobs:
|
||||
# Autobuild attempts to build any compiled languages (C/C++, C#, or Java).
|
||||
# If this step fails, then you should remove it and run the build manually (see below)
|
||||
- name: autobuild
|
||||
uses: github/codeql-action/autobuild@v1
|
||||
uses: github/codeql-action/autobuild@v2
|
||||
|
||||
# ℹ️ Command-line programs to run using the OS shell.
|
||||
# 📚 https://git.io/JvXDl
|
||||
@ -75,4 +75,4 @@ jobs:
|
||||
# make release
|
||||
|
||||
- name: analyze
|
||||
uses: github/codeql-action/analyze@v1
|
||||
uses: github/codeql-action/analyze@v2
|
||||
|
14
.github/workflows/dependabot-automerge.yml
vendored
14
.github/workflows/dependabot-automerge.yml
vendored
@ -1,4 +1,4 @@
|
||||
name: "prautomerge"
|
||||
name: "dependabot-automerge"
|
||||
|
||||
on:
|
||||
pull_request_target:
|
||||
@ -9,21 +9,17 @@ permissions:
|
||||
contents: write
|
||||
|
||||
jobs:
|
||||
dependabot:
|
||||
automerge:
|
||||
runs-on: ubuntu-latest
|
||||
if: ${{ github.actor == 'dependabot[bot]' }}
|
||||
if: github.actor == 'dependabot[bot]'
|
||||
steps:
|
||||
- name: metadata
|
||||
id: metadata
|
||||
uses: dependabot/fetch-metadata@v1.1.1
|
||||
uses: dependabot/fetch-metadata@v1.3.6
|
||||
with:
|
||||
github-token: "${{ secrets.TOKEN }}"
|
||||
- name: approve
|
||||
run: gh pr review --approve "$PR_URL"
|
||||
env:
|
||||
PR_URL: ${{github.event.pull_request.html_url}}
|
||||
GITHUB_TOKEN: ${{secrets.TOKEN}}
|
||||
- name: merge
|
||||
id: merge
|
||||
if: ${{contains(steps.metadata.outputs.dependency-names, 'go.unistack.org')}}
|
||||
run: gh pr merge --auto --merge "$PR_URL"
|
||||
env:
|
||||
|
13
.github/workflows/pr.yml
vendored
13
.github/workflows/pr.yml
vendored
@ -3,19 +3,20 @@ on:
|
||||
pull_request:
|
||||
branches:
|
||||
- master
|
||||
- v3
|
||||
jobs:
|
||||
test:
|
||||
name: test
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- name: setup
|
||||
uses: actions/setup-go@v2
|
||||
uses: actions/setup-go@v3
|
||||
with:
|
||||
go-version: 1.16
|
||||
go-version: 1.17
|
||||
- name: checkout
|
||||
uses: actions/checkout@v2
|
||||
uses: actions/checkout@v3
|
||||
- name: cache
|
||||
uses: actions/cache@v2
|
||||
uses: actions/cache@v3
|
||||
with:
|
||||
path: ~/go/pkg/mod
|
||||
key: ${{ runner.os }}-go-${{ hashFiles('**/go.sum') }}
|
||||
@ -31,9 +32,9 @@ jobs:
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- name: checkout
|
||||
uses: actions/checkout@v2
|
||||
uses: actions/checkout@v3
|
||||
- name: lint
|
||||
uses: golangci/golangci-lint-action@v2
|
||||
uses: golangci/golangci-lint-action@v3.4.0
|
||||
continue-on-error: true
|
||||
with:
|
||||
# Required: the version of golangci-lint is required and must be specified without patch version: we always use the latest patch version.
|
||||
|
5
go.mod
5
go.mod
@ -3,6 +3,7 @@ module go.unistack.org/micro-logger-zerolog/v3
|
||||
go 1.16
|
||||
|
||||
require (
|
||||
github.com/rs/zerolog v1.25.0
|
||||
go.unistack.org/micro/v3 v3.8.7
|
||||
github.com/rs/zerolog v1.29.0
|
||||
go.unistack.org/micro/v3 v3.10.19
|
||||
golang.org/x/sys v0.0.0-20211216021012-1d35b9e2eb4e // indirect
|
||||
)
|
||||
|
60
go.sum
60
go.sum
@ -1,48 +1,22 @@
|
||||
github.com/coreos/go-systemd/v22 v22.3.2/go.mod h1:Y58oyj3AT4RCenI/lSvhwexgC+NSVTIJ3seZv2GcEnc=
|
||||
github.com/ef-ds/deque v1.0.4/go.mod h1:gXDnTC3yqvBcHbq2lcExjtAcVrOnJCbMcZXmuj8Z4tg=
|
||||
github.com/coreos/go-systemd/v22 v22.3.3-0.20220203105225-a9a7ef127534/go.mod h1:Y58oyj3AT4RCenI/lSvhwexgC+NSVTIJ3seZv2GcEnc=
|
||||
github.com/godbus/dbus/v5 v5.0.4/go.mod h1:xhWf0FNVPg57R7Z0UbKHbJfkEywrmjJnf7w5xrFpKfA=
|
||||
github.com/golang-jwt/jwt/v4 v4.1.0/go.mod h1:/xlHOz8bRuivTWchD4jCa+NbatV+wEUSzwAxVc6locg=
|
||||
github.com/golang/protobuf v1.5.0/go.mod h1:FsONVRAS9T7sI+LIUmWTfcYkHO4aIWwzhcaSAoJOfIk=
|
||||
github.com/google/go-cmp v0.5.5/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
|
||||
github.com/imdario/mergo v0.3.12/go.mod h1:jmQim1M+e3UYxmgPu/WyfjB3N3VflVyUjjjwH0dnCYA=
|
||||
github.com/imdario/mergo v0.3.14/go.mod h1:WBLT9ZmE3lPoWsEzCh9LPo3TiwVN+ZKEjmz+hD27ysY=
|
||||
github.com/mattn/go-colorable v0.1.12 h1:jF+Du6AlPIjs2BiUiQlKOX0rt3SujHxPnksPKZbaA40=
|
||||
github.com/mattn/go-colorable v0.1.12/go.mod h1:u5H1YNBxpqRaxsYJYSkiCWKzEfiAb1Gb520KVy5xxl4=
|
||||
github.com/mattn/go-isatty v0.0.14 h1:yVuAays6BHfxijgZPzw+3Zlu5yQgKGP2/hcQbHb7S9Y=
|
||||
github.com/mattn/go-isatty v0.0.14/go.mod h1:7GGIvUiUoEMVVmxf/4nioHXj79iQHKdU27kJ6hsGG94=
|
||||
github.com/patrickmn/go-cache v2.1.0+incompatible/go.mod h1:3Qf8kWWT7OJRJbdiICTKqZju1ZixQ/KpMGzzAfe6+WQ=
|
||||
github.com/pkg/errors v0.9.1 h1:FEBLx1zS214owpjy7qsBeixbURkuhQAwrK5UwLGTwt4=
|
||||
github.com/pkg/errors v0.9.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
|
||||
github.com/rs/xid v1.3.0/go.mod h1:trrq9SKmegXys3aeAKXMUTdJsYXVwGY3RLcfgqegfbg=
|
||||
github.com/rs/zerolog v1.25.0 h1:Rj7XygbUHKUlDPcVdoLyR91fJBsduXj5fRxyqIQj/II=
|
||||
github.com/rs/zerolog v1.25.0/go.mod h1:7KHcEGe0QZPOm2IE4Kpb5rTh6n1h2hIgS5OOnu1rUaI=
|
||||
github.com/silas/dag v0.0.0-20210626123444-3804bac2d6d4/go.mod h1:7RTUFBdIRC9nZ7/3RyRNH1bdqIShrDejd1YbLwgPS+I=
|
||||
github.com/yuin/goldmark v1.3.5/go.mod h1:mwnBkeHKe2W/ZEtQ+71ViKU8L12m81fl3OWwC1Zlc8k=
|
||||
go.unistack.org/micro-proto/v3 v3.1.0/go.mod h1:DpRhYCBXlmSJ/AAXTmntvlh7kQkYU6eFvlmYAx4BQS8=
|
||||
go.unistack.org/micro/v3 v3.8.7 h1:k1zOpJ3uS8MxdhK8annRsa5J/LW7MpqPjwYuekW61wE=
|
||||
go.unistack.org/micro/v3 v3.8.7/go.mod h1:KMMmOmbgo/D52/rCAbqeKbBsgEEbSKM69he54J3ZIuA=
|
||||
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
|
||||
golang.org/x/crypto v0.0.0-20191011191535-87dc89f01550/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI=
|
||||
golang.org/x/mod v0.4.2/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA=
|
||||
golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg=
|
||||
golang.org/x/net v0.0.0-20190620200207-3b0461eec859/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=
|
||||
golang.org/x/net v0.0.0-20210405180319-a5a99cb37ef4/go.mod h1:p54w0d4576C0XHj96bSt6lcn1PtDYWL6XObtHCRCNQM=
|
||||
golang.org/x/net v0.0.0-20210928044308-7d9f5e0b762b/go.mod h1:9nx3DQGgdP8bBQD5qxJ1jj9UTztislL4KSBs9R2vV5Y=
|
||||
golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
|
||||
golang.org/x/sync v0.0.0-20210220032951-036812b2e83c/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
|
||||
golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
|
||||
golang.org/x/sys v0.0.0-20190412213103-97732733099d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||
golang.org/x/sys v0.0.0-20201119102817-f84b799fce68/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||
golang.org/x/sys v0.0.0-20210330210617-4fbd30eecc44/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||
golang.org/x/sys v0.0.0-20210423082822-04245dca01da/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||
golang.org/x/sys v0.0.0-20210510120138-977fb7262007/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
||||
golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo=
|
||||
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
|
||||
golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
|
||||
golang.org/x/text v0.3.6/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
|
||||
golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
|
||||
golang.org/x/tools v0.0.0-20191119224855-298f0cb1881e/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo=
|
||||
golang.org/x/tools v0.1.5/go.mod h1:o0xws9oXOQQZyjljx8fwUC0k7L1pTE6eaCbjGeHmOkk=
|
||||
golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
|
||||
golang.org/x/xerrors v0.0.0-20191011141410-1b5146add898/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
|
||||
golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
|
||||
golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
|
||||
google.golang.org/protobuf v1.26.0-rc.1/go.mod h1:jlhhOSvTdKEhbULTjvd4ARK9grFBp09yW+WbY/TyQbw=
|
||||
google.golang.org/protobuf v1.27.1/go.mod h1:9q0QmTI4eRPtz6boOQmLYwt+qCgq0jsYwAQnmE0givc=
|
||||
github.com/rs/xid v1.4.0/go.mod h1:trrq9SKmegXys3aeAKXMUTdJsYXVwGY3RLcfgqegfbg=
|
||||
github.com/rs/zerolog v1.29.0 h1:Zes4hju04hjbvkVkOhdl2HpZa+0PmVwigmo8XoORE5w=
|
||||
github.com/rs/zerolog v1.29.0/go.mod h1:NILgTygv/Uej1ra5XxGf82ZFSLk58MFGAUS2o6usyD0=
|
||||
github.com/silas/dag v0.0.0-20211117232152-9d50aa809f35/go.mod h1:7RTUFBdIRC9nZ7/3RyRNH1bdqIShrDejd1YbLwgPS+I=
|
||||
go.unistack.org/micro/v3 v3.10.19 h1:JtPacglETxHyb+GiuMdfxqGtnWSTYXPQm6PlDQfNIl8=
|
||||
go.unistack.org/micro/v3 v3.10.19/go.mod h1:XIArw29f0b3uvF4cq96X/nQt2f0J2OGnjh8J+DBbC0s=
|
||||
golang.org/x/sys v0.0.0-20210630005230-0f9fa26af87c/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
||||
golang.org/x/sys v0.0.0-20210927094055-39ccf1dd6fa6/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
||||
golang.org/x/sys v0.0.0-20211216021012-1d35b9e2eb4e h1:fLOSk5Q00efkSvAm+4xcoXD+RRmLmmulPn5I3Y9F2EM=
|
||||
golang.org/x/sys v0.0.0-20211216021012-1d35b9e2eb4e/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
||||
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
|
||||
gopkg.in/yaml.v2 v2.3.0/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
|
||||
gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
|
||||
|
47
zerolog.go
47
zerolog.go
@ -25,15 +25,21 @@ type zeroLogger struct {
|
||||
opts Options
|
||||
}
|
||||
|
||||
func (l *zeroLogger) Name() string {
|
||||
return l.opts.Name
|
||||
}
|
||||
|
||||
func (l *zeroLogger) Level(lvl logger.Level) {
|
||||
}
|
||||
|
||||
func (l *zeroLogger) Clone(opts ...logger.Option) logger.Logger {
|
||||
nl := &zeroLogger{zLog: l.zLog, opts: l.opts}
|
||||
options := l.opts
|
||||
fields := options.Fields
|
||||
for _, o := range opts {
|
||||
o(&nl.opts.Options)
|
||||
o(&options.Options)
|
||||
}
|
||||
|
||||
options.Fields = append(fields, options.Fields...)
|
||||
nl := &zeroLogger{opts: options}
|
||||
_ = nl.Init()
|
||||
return nl
|
||||
}
|
||||
@ -73,7 +79,7 @@ func (l *zeroLogger) Init(opts ...logger.Option) error {
|
||||
// RESET
|
||||
zerolog.TimeFieldFormat = time.RFC3339
|
||||
zerolog.ErrorStackMarshaler = nil
|
||||
zerolog.CallerSkipFrameCount = 4
|
||||
zerolog.CallerSkipFrameCount = l.opts.Options.CallerSkipCount
|
||||
|
||||
switch l.opts.Mode {
|
||||
case Development:
|
||||
@ -126,7 +132,11 @@ func (l *zeroLogger) Init(opts ...logger.Option) error {
|
||||
if l.opts.Fields != nil {
|
||||
data := make(map[string]interface{}, len(l.opts.Fields)/2)
|
||||
for i := 0; i < len(l.opts.Fields); i += 2 {
|
||||
data[l.opts.Fields[i].(string)] = l.opts.Fields[i+1]
|
||||
fld, ok := l.opts.Fields[i].(string)
|
||||
if !ok {
|
||||
return fmt.Errorf("field type invalid %T not string", l.opts.Fields[i])
|
||||
}
|
||||
data[fld] = l.opts.Fields[i+1]
|
||||
}
|
||||
l.zLog = l.zLog.With().Fields(data).Logger()
|
||||
}
|
||||
@ -140,16 +150,11 @@ func (l *zeroLogger) Init(opts ...logger.Option) error {
|
||||
}
|
||||
|
||||
func (l *zeroLogger) Fields(fields ...interface{}) logger.Logger {
|
||||
data := make(map[string]interface{}, len(fields)/2)
|
||||
for i := 0; i < len(fields); i += 2 {
|
||||
data[fields[i].(string)] = fields[i+1]
|
||||
}
|
||||
l.zLog = l.zLog.With().Fields(data).Logger()
|
||||
return l
|
||||
return l.Clone(logger.WithFields(fields...))
|
||||
}
|
||||
|
||||
func (l *zeroLogger) V(level logger.Level) bool {
|
||||
return l.zLog.GetLevel() >= loggerToZerologLevel(level)
|
||||
return l.zLog.GetLevel() <= loggerToZerologLevel(level)
|
||||
}
|
||||
|
||||
func (l *zeroLogger) Info(ctx context.Context, args ...interface{}) {
|
||||
@ -209,17 +214,35 @@ func (l *zeroLogger) Log(ctx context.Context, level logger.Level, args ...interf
|
||||
return
|
||||
}
|
||||
|
||||
var attrs []interface{}
|
||||
for _, fn := range l.opts.Options.ContextAttrFuncs {
|
||||
attrs = append(attrs, fn(ctx)...)
|
||||
}
|
||||
|
||||
msg := fmt.Sprint(args...)
|
||||
if len(attrs) > 0 {
|
||||
l.zLog.WithLevel(loggerToZerologLevel(level)).Fields(attrs).Msg(msg)
|
||||
} else {
|
||||
l.zLog.WithLevel(loggerToZerologLevel(level)).Msg(msg)
|
||||
}
|
||||
}
|
||||
|
||||
func (l *zeroLogger) Logf(ctx context.Context, level logger.Level, format string, args ...interface{}) {
|
||||
if !l.V(level) {
|
||||
return
|
||||
}
|
||||
|
||||
var attrs []interface{}
|
||||
for _, fn := range l.opts.Options.ContextAttrFuncs {
|
||||
attrs = append(attrs, fn(ctx)...)
|
||||
}
|
||||
|
||||
if len(attrs) > 0 {
|
||||
l.zLog.WithLevel(loggerToZerologLevel(level)).Fields(attrs).Msgf(format, args...)
|
||||
} else {
|
||||
l.zLog.WithLevel(loggerToZerologLevel(level)).Msgf(format, args...)
|
||||
}
|
||||
}
|
||||
|
||||
func (l *zeroLogger) String() string {
|
||||
return "zerolog"
|
||||
|
@ -1,6 +1,7 @@
|
||||
package zerolog
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"context"
|
||||
"errors"
|
||||
"os"
|
||||
@ -11,6 +12,38 @@ import (
|
||||
"go.unistack.org/micro/v3/logger"
|
||||
)
|
||||
|
||||
func TestFields(t *testing.T) {
|
||||
ctx := context.TODO()
|
||||
buf := bytes.NewBuffer(nil)
|
||||
l := NewLogger(logger.WithLevel(logger.TraceLevel), logger.WithOutput(buf))
|
||||
if err := l.Init(); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
nl := l.Fields("key", "val")
|
||||
nl.Infof(ctx, "message")
|
||||
if !bytes.Contains(buf.Bytes(), []byte(`"key":"val"`)) {
|
||||
t.Fatalf("logger fields not works, buf contains: %s", buf.Bytes())
|
||||
}
|
||||
buf.Reset()
|
||||
mnl := nl.Fields("key1", "val1")
|
||||
mnl.Infof(ctx, "message")
|
||||
if !bytes.Contains(buf.Bytes(), []byte(`"key1":"val1"`)) || !bytes.Contains(buf.Bytes(), []byte(`"key":"val"`)) {
|
||||
t.Fatalf("logger fields not works, buf contains: %s", buf.Bytes())
|
||||
}
|
||||
}
|
||||
|
||||
func TestOutput(t *testing.T) {
|
||||
buf := bytes.NewBuffer(nil)
|
||||
l := NewLogger(logger.WithOutput(buf))
|
||||
if err := l.Init(); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
l.Infof(context.TODO(), "test logger name: %s", "name")
|
||||
if !bytes.Contains(buf.Bytes(), []byte(`test logger name`)) {
|
||||
t.Fatalf("log not redirected: %s", buf.Bytes())
|
||||
}
|
||||
}
|
||||
|
||||
func TestName(t *testing.T) {
|
||||
l := NewLogger()
|
||||
l.Init()
|
||||
|
Loading…
x
Reference in New Issue
Block a user