Skip to content

Commit ffe98a7

Browse files
committed
Initial commit
1 parent d06ea2e commit ffe98a7

30 files changed

+3434
-1
lines changed

.github/codecov.yml

+25
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
coverage:
2+
status:
3+
project:
4+
default:
5+
informational: true
6+
patch:
7+
default:
8+
informational: true
9+
ignore:
10+
# All 'pb.go's.
11+
- "**/*.pb.go"
12+
# Tests and test related files.
13+
- "**/test"
14+
- "**/testdata"
15+
- "**/testutils"
16+
- "benchmark"
17+
- "interop"
18+
# Other submodules.
19+
- "cmd"
20+
- "examples"
21+
- "gcp"
22+
- "security"
23+
- "stats/opencensus"
24+
comment:
25+
layout: "header, diff, files"

.github/dependabot.yml

+18
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
# To get started with Dependabot version updates, you'll need to specify which
2+
# package ecosystems to update and where the package manifests are located.
3+
# Please see the documentation for all configuration options:
4+
# https://docs.github.com/github/administering-a-repository/configuration-options-for-dependency-updates
5+
6+
version: 2
7+
updates:
8+
- package-ecosystem: "github-actions"
9+
directory: "/"
10+
schedule:
11+
interval: "monthly"
12+
groups:
13+
github-actions:
14+
patterns:
15+
- "*"
16+
ignore:
17+
- dependency-name: "*"
18+
update-types: ["version-update:semver-major"]

.github/workflows/ci.yml

+62
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
name: Workflow for CI
2+
on: [ push, pull_request ]
3+
jobs:
4+
run:
5+
runs-on: ubuntu-latest
6+
strategy:
7+
matrix:
8+
go-version: [ '1.22.x' ]
9+
steps:
10+
- name: Checkout
11+
uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # v4.1.1
12+
with:
13+
fetch-depth: 0
14+
15+
- name: Setup Go ${{ matrix.go-version }}
16+
uses: actions/setup-go@0c52d547c9bc32b1aa3301fd7a9cb496313a4491 # v5.0.0
17+
with:
18+
go-version: ${{ matrix.go-version }}
19+
20+
- name: Ensure the Go module is nice and tidy
21+
run: |
22+
go mod tidy && git diff --exit-code go.mod go.sum
23+
# We set the shell explicitly, here, and in other golang test actions,
24+
# as by default multi-line shell scripts do not error out on the first
25+
# failed command. Since we want an error reported if any of the lines
26+
# fail, we set the shell explicitly:
27+
# https://docs.github.com/en/actions/using-workflows/workflow-syntax-for-github-actions?ref=cloudtechsimplified.com#exit-codes-and-error-action-preference
28+
shell: bash
29+
30+
- name: Install Tools
31+
run: |
32+
pushd "$(mktemp -d)"
33+
go mod init example.com/m # fake module
34+
go install github.com/onsi/ginkgo/v2/[email protected]
35+
go install honnef.co/go/tools/cmd/[email protected]
36+
popd
37+
shell: bash
38+
39+
- name: Verify Go Modules Setup
40+
run: go mod verify
41+
shell: bash
42+
43+
- name: Build
44+
run: go build -v ./...
45+
shell: bash
46+
47+
- name: Sanity Check (staticcheck)
48+
run: staticcheck ./...
49+
shell: bash
50+
51+
- name: Test
52+
run: ginkgo -v -race -coverprofile=coverage.out -coverpkg=./... ./...
53+
shell: bash
54+
55+
- name: Upload coverage to Codecov
56+
uses: codecov/codecov-action@54bcd8715eee62d40e33596ef5e8f0f48dbbccab # v4.1.0
57+
with:
58+
token: ${{ secrets.CODECOV_TOKEN }}
59+
slug: maguro/gslog
60+
flags: smart-tests
61+
verbose: true
62+

.github/workflows/codeql-analysis.yml

+37
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
name: "CodeQL"
2+
3+
on:
4+
push:
5+
branches: [ master ]
6+
schedule:
7+
- cron: '24 20 * * 3'
8+
9+
permissions:
10+
contents: read
11+
12+
jobs:
13+
analyze:
14+
name: Analyze
15+
runs-on: ubuntu-latest
16+
timeout-minutes: 30
17+
18+
permissions:
19+
security-events: write
20+
pull-requests: read
21+
actions: read
22+
23+
strategy:
24+
fail-fast: false
25+
26+
steps:
27+
- name: Checkout repository
28+
uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # v4.1.1
29+
30+
# Initializes the CodeQL tools for scanning.
31+
- name: Initialize CodeQL
32+
uses: github/codeql-action/init@928ff8c822d966a999092a6a35e32177899afb7c # v2.24.6
33+
with:
34+
languages: go
35+
36+
- name: Perform CodeQL Analysis
37+
uses: github/codeql-action/analyze@928ff8c822d966a999092a6a35e32177899afb7c # v2.24.6

README.md

+6-1
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,7 @@
11
# gslog
2-
An slog Handler for Google Cloud Logging
2+
3+
[![Documentation](https://godoc.org/github.com/maguro/gslog?status.svg)](http://godoc.org/github.com/maguro/gslog)
4+
[![Go Report Card](https://goreportcard.com/badge/github.com/maguro/gslog)](https://goreportcard.com/report/github.com/maguro/gslog)
5+
[![codecov](https://codecov.io/gh/maguro/gslog/graph/badge.svg?token=3FAJJ2SIZB)](https://codecov.io/gh/maguro/gslog)
6+
7+
A Google Cloud Logging [Handler](https://pkg.go.dev/log/slog#Handler) implementation for [slog](https://go.dev/blog/slog).

attr.go

+44
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
// Copyright 2024 The original author or authors.
2+
//
3+
// Licensed under the Apache License, Version 2.0 (the "License");
4+
// you may not use this file except in compliance with the License.
5+
// You may obtain a copy of the License at
6+
//
7+
// http://www.apache.org/licenses/LICENSE-2.0
8+
//
9+
// Unless required by applicable law or agreed to in writing, software
10+
// distributed under the License is distributed on an "AS IS" BASIS,
11+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
// See the License for the specific language governing permissions and
13+
// limitations under the License.
14+
15+
package gslog
16+
17+
import (
18+
"log/slog"
19+
)
20+
21+
// AttrMapper is called to rewrite each non-group attribute before it is logged.
22+
// The attribute's value has been resolved (see [Value.Resolve]).
23+
// If replaceAttr returns a zero Attr, the attribute is discarded.
24+
//
25+
// The built-in attribute with key "message" is passed to this function.
26+
//
27+
// The first argument is a list of currently open groups that contain the
28+
// Attr. It must not be retained or modified. replaceAttr is never called
29+
// for Group attributes, only their contents. For example, the attribute
30+
// list
31+
//
32+
// Int("a", 1), Group("g", Int("b", 2)), Int("c", 3)
33+
//
34+
// results in consecutive calls to replaceAttr with the following arguments:
35+
//
36+
// nil, Int("a", 1)
37+
// []string{"g"}, Int("b", 2)
38+
// nil, Int("c", 3)
39+
//
40+
// AttrMapper can be used to change the default keys of the built-in
41+
// attributes, convert types (for example, to replace a `time.Time` with the
42+
// integer seconds since the Unix epoch), sanitize personal information, or
43+
// remove attributes from the output.
44+
type AttrMapper func(groups []string, a slog.Attr) slog.Attr

doc.go

+16
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
// Copyright 2024 The original author or authors.
2+
//
3+
// Licensed under the Apache License, Version 2.0 (the "License");
4+
// you may not use this file except in compliance with the License.
5+
// You may obtain a copy of the License at
6+
//
7+
// http://www.apache.org/licenses/LICENSE-2.0
8+
//
9+
// Unless required by applicable law or agreed to in writing, software
10+
// distributed under the License is distributed on an "AS IS" BASIS,
11+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
// See the License for the specific language governing permissions and
13+
// limitations under the License.
14+
15+
// Package gslog contains a GCP logging implementation of slog.Handler.
16+
package gslog

go.mod

+47
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
module m4o.io/gslog
2+
3+
go 1.22
4+
5+
require (
6+
cloud.google.com/go/logging v1.9.0
7+
github.com/golang/protobuf v1.5.3
8+
github.com/magiconair/properties v1.8.7
9+
github.com/onsi/ginkgo/v2 v2.17.1
10+
github.com/onsi/gomega v1.32.0
11+
github.com/stretchr/testify v1.9.0
12+
go.opentelemetry.io/otel/trace v1.24.0
13+
google.golang.org/protobuf v1.33.0
14+
)
15+
16+
require (
17+
cloud.google.com/go v0.110.8 // indirect
18+
cloud.google.com/go/compute v1.23.1 // indirect
19+
cloud.google.com/go/compute/metadata v0.2.3 // indirect
20+
cloud.google.com/go/longrunning v0.5.2 // indirect
21+
github.com/davecgh/go-spew v1.1.1 // indirect
22+
github.com/go-logr/logr v1.4.1 // indirect
23+
github.com/go-task/slim-sprig v0.0.0-20230315185526-52ccab3ef572 // indirect
24+
github.com/golang/groupcache v0.0.0-20210331224755-41bb18bfe9da // indirect
25+
github.com/google/go-cmp v0.6.0 // indirect
26+
github.com/google/pprof v0.0.0-20210407192527-94a9f03dee38 // indirect
27+
github.com/google/s2a-go v0.1.7 // indirect
28+
github.com/googleapis/enterprise-certificate-proxy v0.3.2 // indirect
29+
github.com/googleapis/gax-go/v2 v2.12.0 // indirect
30+
github.com/pmezard/go-difflib v1.0.0 // indirect
31+
go.opencensus.io v0.24.0 // indirect
32+
go.opentelemetry.io/otel v1.24.0 // indirect
33+
golang.org/x/crypto v0.18.0 // indirect
34+
golang.org/x/net v0.20.0 // indirect
35+
golang.org/x/oauth2 v0.13.0 // indirect
36+
golang.org/x/sync v0.6.0 // indirect
37+
golang.org/x/sys v0.16.0 // indirect
38+
golang.org/x/text v0.14.0 // indirect
39+
golang.org/x/tools v0.17.0 // indirect
40+
google.golang.org/api v0.149.0 // indirect
41+
google.golang.org/appengine v1.6.7 // indirect
42+
google.golang.org/genproto v0.0.0-20231016165738-49dd2c1f3d0b // indirect
43+
google.golang.org/genproto/googleapis/api v0.0.0-20231016165738-49dd2c1f3d0b // indirect
44+
google.golang.org/genproto/googleapis/rpc v0.0.0-20231016165738-49dd2c1f3d0b // indirect
45+
google.golang.org/grpc v1.59.0 // indirect
46+
gopkg.in/yaml.v3 v3.0.1 // indirect
47+
)

0 commit comments

Comments
 (0)