Skip to content

Commit 2c5c742

Browse files
committed
Merge remote-tracking branch 'origin/main'
2 parents a035316 + c5a341b commit 2c5c742

File tree

4 files changed

+24
-7
lines changed

4 files changed

+24
-7
lines changed

.github/workflows/builder.yml

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,6 @@ on:
77
- 'main'
88
tags:
99
- 'v*.*.*'
10-
# release:
11-
# types:
12-
# - published
1310

1411
# permissions are needed if pushing to ghcr.io
1512
permissions:
@@ -49,7 +46,9 @@ jobs:
4946
nanoandrew4/ngcplogs
5047
# Docker tags based on the following events/attributes
5148
tags: |
49+
type=raw,value=latest,enable={{is_default_branch}}
50+
type=ref,event=tag
5251
type=semver,pattern={{raw}}
5352
- name: Build all supported architectures
5453
run: |
55-
make push PLUGIN_TAG=${{ steps.docker_meta_tag_step.outputs.tags }}
54+
make push PLUGIN_TAG=${{ steps.docker_meta_tag_step.outputs.version }} PLUGIN_NAME=nanoandrew4/ngcplogs

Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
PLUGIN_NAME=nanoandrew4/ngcplogs
1+
PLUGIN_NAME?=nanoandrew4/ngcplogs
22
PLUGIN_TAG?=latest
33
PLUGIN_DIR=./ngcplogs-plugin
44
PLUGIN_SUPPORTED_ARCHS=linux/amd64 linux/arm64

README.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,7 @@ The following [log-opts](https://docs.docker.com/config/containers/logging/confi
130130
| extract-json-message | true | Enables unmarshalling JSON messages and sending the jsonPayload as the unmarshalled map. Kind of the whole point of this plugin, but you can disable it so it behaves just like the `gcplogs` plugin if you wish |
131131
| local-logging | false | Enables logging to a local file, so logs can be viewed with the `docker logs` command. If false, the command will show no output |
132132
| extract-severity | true | Extracts the severity from JSON logs to set them for the log that will be sent to GCP. It will be removed from the jsonPayload section, since it is set at the root level. Currently the supported severity field names to extract are the following: `severity`, `level` |
133+
| extract-msg | true | Extracts the msg field from JSON logs to set the message field GCP expects. It will be removed from the jsonPayload section, since it is set at the root level. Fields named msg are produced for example by the golang log/slog package. |
133134
| exclude-timestamp | false | Excludes timestamp fields from the final jsonPayload, since docker sends its own nanosecond precision timestamp for each log. Currently it can remove fields with the following names: `timestamp`, `time`, `ts` |
134135
| sleep-interval | 500 | Milliseconds to sleep when there are no logs to send before checking again. The higher the value, the lower the CPU usage will be |
135136
| credentials-file | | Absolute path to the GCP credentials JSON file to use when authenticating (only necessary when running the plugin outside of GCP) |
@@ -142,4 +143,4 @@ If you want to build the plugin yourself, use the makefile with the following co
142143
make all
143144
```
144145

145-
See the Makefile for other build targets
146+
See the Makefile for other build targets

ngcplogger.go

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,12 @@ import (
55
"encoding/json"
66
"errors"
77
"fmt"
8-
"google.golang.org/api/option"
98
"sync"
109
"sync/atomic"
1110
"time"
1211

12+
"google.golang.org/api/option"
13+
1314
"github.com/docker/docker/daemon/logger"
1415

1516
"cloud.google.com/go/compute/metadata"
@@ -77,6 +78,7 @@ type nGCPLogger struct {
7778
extractJsonMessage bool
7879
extractSeverity bool
7980
excludeTimestamp bool
81+
extractMsg bool
8082
}
8183

8284
type dockerLogEntry struct {
@@ -201,6 +203,7 @@ func New(info logger.Info) (logger.Logger, error) {
201203
extractJsonMessage: true,
202204
extractSeverity: true,
203205
excludeTimestamp: false,
206+
extractMsg: true,
204207
}
205208

206209
if info.Config[logCmdKey] == "true" {
@@ -216,6 +219,9 @@ func New(info logger.Info) (logger.Logger, error) {
216219
if info.Config["exclude-timestamp"] == "true" {
217220
l.excludeTimestamp = true
218221
}
222+
if info.Config["extract-msg"] == "false" {
223+
l.extractMsg = false
224+
}
219225

220226
if instanceResource != nil {
221227
l.instance = instanceResource
@@ -269,6 +275,7 @@ func (l *nGCPLogger) Log(lMsg *logger.Message) error {
269275
} else {
270276
severity = l.extractSeverityFromPayload(m)
271277
l.excludeTimestampFromPayload(m)
278+
l.extractMsgFromPayload(m)
272279
m["instance"] = l.instance
273280
m["container"] = l.container
274281
payload = m
@@ -328,6 +335,16 @@ func (l *nGCPLogger) excludeTimestampFromPayload(m map[string]any) {
328335
}
329336
}
330337

338+
func (l *nGCPLogger) extractMsgFromPayload(m map[string]any) {
339+
340+
if l.extractMsg {
341+
if msg, exists := m["msg"]; exists {
342+
m["message"] = msg
343+
delete(m, "msg")
344+
}
345+
}
346+
}
347+
331348
func (l *nGCPLogger) Close() error {
332349
err := l.logger.Flush()
333350
if err != nil {

0 commit comments

Comments
 (0)