Some checks failed
go: build dev binaries / cleanup (push) Successful in 4s
Codespell / Check for spelling errors (push) Failing after 3s
docker: build dev containers / build-rust-binaries (amd64, x86_64-unknown-linux-musl) (push) Failing after 3s
docker: build dev containers / build-dev-containers (push) Has been skipped
docker: build dev containers / build-rust-binaries (arm64, true, aarch64-unknown-linux-musl) (push) Failing after 3s
End to End / FUSE Mount (push) Failing after 2s
EC Integration Tests / EC Integration Tests (push) Failing after 30s
FUSE DLM Integration Tests / FUSE DLM Integration Tests (push) Failing after 3s
FUSE Volume Server Failover Tests / FUSE Volume Server Failover (push) Failing after 3s
FUSE Integration Tests / FUSE Integration Testing (push) Failing after 2s
FUSE P2P Peer Chunk Sharing Integration Tests / FUSE P2P Peer Chunk Sharing (push) Failing after 3s
go: build binary / Go Vet (push) Failing after 2s
go: build binary / Go Vet 32-bit (push) Failing after 3s
go: build binary / Build (push) Failing after 4s
go: build binary / Build cross-platform (freebsd/amd64) (push) Failing after 3s
go: build binary / Build cross-platform (windows/amd64) (push) Failing after 3s
go: build binary / Build cross-platform (darwin/arm64) (push) Failing after 3s
go: build binary / Build cross-platform (windows/arm64) (push) Failing after 3s
go: build binary / Test (push) Failing after 2s
go: build binary / Test 32-bit (push) Failing after 3s
helm: lint and test charts / lint-test (push) Failing after 3s
Java Client Integration Tests / Java Integration Tests (11) (push) Failing after 3s
Java Client Integration Tests / Java Integration Tests (17) (push) Failing after 3s
go: build dev binaries / build_dev_linux_windows (amd64, linux) (push) Failing after 2s
go: build dev binaries / build_dev_linux_windows (amd64, windows) (push) Failing after 3s
go: build dev binaries / build_dev_darwin (amd64, darwin) (push) Has been skipped
go: build dev binaries / build_dev_darwin (arm64, darwin) (push) Has been skipped
Java Client Unit Tests / Java Unit Tests (11) (push) Failing after 3s
Java Client Unit Tests / Java Unit Tests (17) (push) Failing after 2s
Java Client Unit Tests / Java Unit Tests (21) (push) Failing after 3s
Java Client Unit Tests / Java Unit Tests (8) (push) Failing after 3s
Kafka Quick Test (Load Test with Schema Registry) / Kafka Client Load Test (Quick) (push) Failing after 3s
Kafka Gateway Tests / Kafka Unit Tests (unit-tests-1) (push) Failing after 11s
Kafka Gateway Tests / Kafka Integration Tests (Critical) (integration-1) (push) Failing after 3s
Kafka Gateway Tests / Kafka End-to-End Tests (with SMQ) (e2e-1) (push) Failing after 3s
Kafka Gateway Tests / Kafka Consumer Group Tests (Highly Isolated) (consumer-group-1) (push) Failing after 2s
Kafka Gateway Tests / Kafka Client Compatibility (with SMQ) (client-compat-1) (push) Failing after 3s
Kafka Gateway Tests / Kafka SMQ Integration Tests (Full Stack) (smq-integration-1) (push) Failing after 3s
Kafka Gateway Tests / Kafka Protocol Tests (Isolated) (protocol-1) (push) Failing after 3s
KMS Tests / KMS Provider Integration Tests (push) Failing after 2s
KMS Tests / S3 KMS End-to-End Tests (push) Failing after 3s
Master Cold Start Tests / Master Cold Start Tests (push) Failing after 4s
Metadata Subscribe Integration Tests / Metadata Subscribe Integration Tests (push) Failing after 3s
Multi-Master Tests / Multi-Master Failover Tests (push) Failing after 3s
Performance / CPU and Heap Profile (push) Failing after 2s
Performance / S3 Read/Write Benchmark (rust volume) (push) Failing after 3s
pjdfstest POSIX Compliance / pjdfstest (push) Failing after 2s
Plugin Worker Integration Tests / Plugin Worker: erasure_coding (push) Failing after 3s
Plugin Worker Integration Tests / Plugin Worker: vacuum (push) Failing after 3s
Rust Volume Server Tests / Rust Integration Tests (push) Failing after 3s
Rust Volume Server Tests / Go Tests with Rust Volume (grpc - Shard 1) (push) Failing after 2s
Rust Volume Server Tests / Go Tests with Rust Volume (http - Shard 1) (push) Failing after 3s
Rust Volume Server Tests / Go Tests with Rust Volume (grpc - Shard 2) (push) Failing after 3s
Rust Volume Server Tests / Go Tests with Rust Volume (http - Shard 2) (push) Failing after 3s
Rust Volume Server Tests / Go Tests with Rust Volume (grpc - Shard 3) (push) Failing after 3s
S3 IAM Integration Tests / S3 IAM Distributed Tests (push) Failing after 2s
S3 IAM Integration Tests / S3 IAM Performance Tests (push) Failing after 3s
Performance / Throughput Benchmark (go volume) (push) Failing after 3s
Performance / Throughput Benchmark (rust volume) (push) Failing after 2s
Performance / S3 Read/Write Benchmark (go volume) (push) Failing after 3s
Plugin Worker Integration Tests / Plugin Worker: volume_balance (push) Failing after 3s
PostgreSQL Gateway Tests / PostgreSQL Basic Tests (push) Failing after 3s
Rust Volume Server Tests / Rust Unit Tests (push) Failing after 2s
Rust Volume Server Tests / Go Tests with Rust Volume (http - Shard 3) (push) Failing after 3s
Rust Plugin Worker Tests / Rust Plugin Worker Build and Unit Tests (push) Failing after 3s
rust: build dev volume server binaries / cleanup (push) Successful in 3s
S3 ETag and ACL Tests / S3 ETag + ACL Integration Tests (push) Failing after 3s
S3 IAM Integration Tests / IAM Unit Tests (push) Failing after 3s
S3 IAM Integration Tests / S3 IAM Integration Tests (advanced) (push) Failing after 3s
S3 IAM Integration Tests / S3 IAM Integration Tests (basic) (push) Failing after 2s
S3 IAM Integration Tests / S3 IAM Integration Tests (group) (push) Failing after 3s
S3 IAM Integration Tests / S3 IAM Integration Tests (policy-enforcement) (push) Failing after 2s
S3 IAM Integration Tests / S3 IAM Integration Tests (sts) (push) Failing after 4s
S3 Keycloak Integration Tests / S3 Keycloak Integration Tests (push) Failing after 3s
S3 PyArrow Parquet Tests / PyArrow Parquet Tests (Python 3.11) (push) Failing after 3s
S3 PyArrow Parquet Tests / Go Unit Tests (Implicit Directory) (push) Has been cancelled
S3 PyArrow Parquet Tests / PyArrow Parquet Tests (Python 3.12) (push) Has been cancelled
rust: build dev volume server binaries / build-rust-volume-dev-darwin (darwin-amd64, x86_64-apple-darwin) (push) Has been cancelled
rust: build dev volume server binaries / build-rust-volume-dev-darwin (darwin-arm64, aarch64-apple-darwin) (push) Has been cancelled
rust: build dev volume server binaries / build-rust-volume-dev-linux (linux-amd64, x86_64-unknown-linux-gnu) (push) Has been cancelled
S3 PyArrow Parquet Tests / PyArrow Parquet Tests (Python 3.9) (push) Has been cancelled
S3 Proxy Signature Tests / S3 Proxy Signature Verification Tests (push) Has been cancelled
S3 SDK V2 Route Disambiguation Tests / S3 SDK V2 Routing Tests (push) Has been cancelled
S3 SSE Tests / S3 SSE Integration Tests (quick) (push) Has been cancelled
S3 SSE Tests / S3 SSE Compatibility Test (push) Has been cancelled
S3 SSE Tests / S3 SSE Metadata Persistence Test (push) Has been cancelled
S3 SSE Tests / S3 SSE Copy Operations Test (push) Has been cancelled
S3 SSE Tests / S3 SSE Multipart Upload Test (push) Has been cancelled
S3 SSE Tests / S3 SSE Performance Test (push) Has been cancelled
S3 SSE Tests / S3 Volume Encryption Test (push) Has been cancelled
S3 SSE Tests / S3 SSE Integration Tests (comprehensive) (push) Has been cancelled
Spark Integration Tests / Spark Integration Tests (push) Failing after 2s
Telemetry Integration Tests / telemetry-integration-test (push) Failing after 3s
Volume Server Integration Tests / Volume Server Integration Tests (grpc - Shard 1) (push) Failing after 3s
Volume Server Integration Tests / Volume Server Integration Tests (http - Shard 1) (push) Failing after 3s
Ceph S3 tests / Basic S3 tests (KV store) (push) Has been cancelled
Ceph S3 tests / S3 Versioning & Object Lock tests (push) Has been cancelled
S3 Policy Integration Tests / S3 Policy Unit Tests (push) Failing after 3s
Ceph S3 tests / S3 CORS tests (push) Has been cancelled
Ceph S3 tests / SeaweedFS Custom S3 Copy tests (push) Has been cancelled
Ceph S3 tests / Basic S3 tests (SQL store) (push) Has been cancelled
test s3 over https using aws-cli / awscli-tests (push) Has been cancelled
TLS Rotation Integration Tests / TLS Rotation Integration Tests (push) Has been cancelled
Vacuum Integration Tests / Vacuum Integration Tests (push) Has been cancelled
S3 Policy Integration Tests / S3 Policy Variables Integration Tests (push) Failing after 3s
S3 Policy Integration Tests / S3 Policy Enforcement Integration Tests (advanced-policy) (push) Failing after 3s
S3 Policy Integration Tests / S3 Policy Enforcement Integration Tests (basic-policy) (push) Failing after 2s
S3 Policy Integration Tests / S3 Policy Enforcement Integration Tests (contextual-policy) (push) Failing after 4s
S3 Policy Integration Tests / Trusted Proxy Detection Tests (push) Failing after 2s
S3 Policy Integration Tests / S3 Policy Shell Integration Tests (push) Failing after 3s
Samba on FUSE Integration / samba-integration (push) Failing after 2s
SFTP Integration Tests / SFTP Integration Testing (push) Failing after 3s
terraform: validate and test modules / fmt, validate, plan-level tests (push) Failing after 3s
terraform: validate and test modules / local cluster smoke test (real weed) (push) Failing after 2s
Volume Server Integration Tests / Volume Server Integration Tests (grpc - Shard 3) (push) Failing after 3s
Volume Server Integration Tests / Volume Server Integration Tests (grpc - Shard 2) (push) Failing after 3s
Volume Server Integration Tests / Volume Server Integration Tests (http - Shard 2) (push) Failing after 2s
Volume Server Integration Tests / Volume Server Integration Tests (http - Shard 3) (push) Failing after 5s
mount: windows conformance / WinFsp conformance (push) Has been cancelled
mount: windows / Mount on Windows (push) Has been cancelled
216 lines
6.6 KiB
Go
216 lines
6.6 KiB
Go
// Go support for leveled logs, analogous to https://code.google.com/p/google-glog/
|
|
//
|
|
// Copyright 2013 Google Inc. All Rights Reserved.
|
|
//
|
|
// Licensed under the Apache License, Version 2.0 (the "License");
|
|
// you may not use this file except in compliance with the License.
|
|
// You may obtain a copy of the License at
|
|
//
|
|
// http://www.apache.org/licenses/LICENSE-2.0
|
|
//
|
|
// Unless required by applicable law or agreed to in writing, software
|
|
// distributed under the License is distributed on an "AS IS" BASIS,
|
|
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
// See the License for the specific language governing permissions and
|
|
// limitations under the License.
|
|
|
|
// File I/O for logs.
|
|
|
|
package glog
|
|
|
|
import (
|
|
"errors"
|
|
"fmt"
|
|
"os"
|
|
"os/user"
|
|
"path/filepath"
|
|
"sort"
|
|
"strings"
|
|
"sync"
|
|
"time"
|
|
|
|
flag "github.com/seaweedfs/seaweedfs/weed/util/fla9"
|
|
)
|
|
|
|
// MaxSize is the maximum size of a log file in bytes.
|
|
// It is initialized from the --log_max_size_mb flag when the first log file is created.
|
|
var MaxSize uint64 = 1024 * 1024 * 1800
|
|
|
|
// MaxFileCount is the maximum number of log files retained per severity level.
|
|
// It is initialized from the --log_max_files flag when the first log file is created.
|
|
var MaxFileCount = 5
|
|
|
|
// logDirs lists the candidate directories for new log files.
|
|
var logDirs []string
|
|
|
|
// If non-empty, overrides the choice of directory in which to write logs.
|
|
// See createLogDirs for the full list of possible destinations.
|
|
var logDir = flag.String("logdir", "", "If non-empty, write log files in this directory")
|
|
|
|
// logMaxSizeMB controls the maximum size of each log file in megabytes.
|
|
// When a log file reaches this size it is closed and a new file is created.
|
|
// Defaults to 1800 MB. Set to 0 to use the compiled-in default.
|
|
var logMaxSizeMB = flag.Uint64("log_max_size_mb", 1800, "Maximum size in megabytes of each log file before it is rotated (0 = use default of 1800 MB)")
|
|
|
|
// logMaxFiles controls how many log files are kept per severity level.
|
|
// Older files are deleted when the limit is exceeded.
|
|
// Defaults to 5.
|
|
var logMaxFiles = flag.Int("log_max_files", 5, "Maximum number of log files to keep per severity level before older ones are deleted (0 = use default of 5)")
|
|
|
|
// logRotateHours controls time-based log rotation.
|
|
// When non-zero, each log file is rotated after the given number of hours
|
|
// regardless of its size. This prevents log files from accumulating in
|
|
// long-running deployments even when log volume is low.
|
|
// The default is 168 hours (7 days). Set to 0 to disable time-based rotation.
|
|
var logRotateHours = flag.Int("log_rotate_hours", 168, "Rotate log files after this many hours (default: 168 = 7 days, 0 = disabled)")
|
|
|
|
// logJSON enables JSON-formatted log output (one JSON object per line).
|
|
// Useful for integration with ELK, Loki, Datadog, and other log aggregation systems.
|
|
var logJSON = flag.Bool("log_json", false, "Output logs in JSON format instead of glog text format")
|
|
|
|
// logCompress enables gzip compression of rotated log files.
|
|
// Compressed files get a .gz suffix. Compression runs in the background.
|
|
var logCompress = flag.Bool("log_compress", false, "Gzip-compress rotated log files to save disk space")
|
|
|
|
func createLogDirs() {
|
|
// Apply flag values now that flags have been parsed.
|
|
if *logMaxSizeMB > 0 {
|
|
MaxSize = *logMaxSizeMB * 1024 * 1024
|
|
}
|
|
if *logMaxFiles > 0 {
|
|
MaxFileCount = *logMaxFiles
|
|
}
|
|
|
|
if *logCompress {
|
|
SetCompressRotated(true)
|
|
}
|
|
|
|
if *logDir != "" {
|
|
logDirs = append(logDirs, *logDir)
|
|
} else {
|
|
logDirs = append(logDirs, os.TempDir())
|
|
}
|
|
}
|
|
|
|
// LogRotateHours returns the configured time-based rotation interval.
|
|
// This is used by syncBuffer to decide when to rotate open log files.
|
|
func LogRotateHours() int {
|
|
return *logRotateHours
|
|
}
|
|
|
|
var (
|
|
pid = os.Getpid()
|
|
program = filepath.Base(os.Args[0])
|
|
host = "unknownhost"
|
|
userName = "unknownuser"
|
|
)
|
|
|
|
func init() {
|
|
h, err := os.Hostname()
|
|
if err == nil {
|
|
host = shortHostname(h)
|
|
}
|
|
|
|
current, err := user.Current()
|
|
if err == nil {
|
|
userName = current.Username
|
|
}
|
|
|
|
// Sanitize userName since it may contain filepath separators on Windows.
|
|
userName = strings.Replace(userName, `\`, "_", -1)
|
|
}
|
|
|
|
// shortHostname returns its argument, truncating at the first period.
|
|
// For instance, given "www.google.com" it returns "www".
|
|
func shortHostname(hostname string) string {
|
|
if i := strings.Index(hostname, "."); i >= 0 {
|
|
return hostname[:i]
|
|
}
|
|
return hostname
|
|
}
|
|
|
|
// logName returns a new log file name containing tag, with start time t, and
|
|
// the name for the symlink for tag.
|
|
func logName(tag string, t time.Time) (name, link string) {
|
|
name = fmt.Sprintf("%s.%s.%s.log.%s.%04d%02d%02d-%02d%02d%02d.%d",
|
|
program,
|
|
host,
|
|
userName,
|
|
tag,
|
|
t.Year(),
|
|
t.Month(),
|
|
t.Day(),
|
|
t.Hour(),
|
|
t.Minute(),
|
|
t.Second(),
|
|
pid)
|
|
return name, program + "." + tag
|
|
}
|
|
|
|
func prefix(tag string) string {
|
|
return fmt.Sprintf("%s.%s.%s.log.%s.",
|
|
program,
|
|
host,
|
|
userName,
|
|
tag,
|
|
)
|
|
}
|
|
|
|
var onceLogDirs sync.Once
|
|
|
|
// create creates a new log file and returns the file and its filename, which
|
|
// contains tag ("INFO", "FATAL", etc.) and t. If the file is created
|
|
// successfully, create also attempts to update the symlink for that tag, ignoring
|
|
// errors.
|
|
func create(tag string, t time.Time) (f *os.File, filename string, err error) {
|
|
onceLogDirs.Do(createLogDirs)
|
|
if len(logDirs) == 0 {
|
|
return nil, "", errors.New("log: no log dirs")
|
|
}
|
|
name, link := logName(tag, t)
|
|
logPrefix := prefix(tag)
|
|
var lastErr error
|
|
for _, dir := range logDirs {
|
|
|
|
// remove old logs (including .gz compressed rotated files)
|
|
// Deduplicate .log/.log.gz pairs so concurrent compression
|
|
// doesn't cause double-counting against MaxFileCount.
|
|
entries, _ := os.ReadDir(dir)
|
|
previousLogs := make(map[string][]string) // bare name -> actual file names
|
|
for _, entry := range entries {
|
|
name := entry.Name()
|
|
bare := strings.TrimSuffix(name, ".gz")
|
|
if strings.HasPrefix(bare, logPrefix) {
|
|
previousLogs[bare] = append(previousLogs[bare], name)
|
|
}
|
|
}
|
|
if len(previousLogs) >= MaxFileCount {
|
|
var keys []string
|
|
for bare := range previousLogs {
|
|
keys = append(keys, bare)
|
|
}
|
|
sort.Strings(keys)
|
|
for i, bare := range keys {
|
|
if i > len(keys)-MaxFileCount {
|
|
break
|
|
}
|
|
for _, name := range previousLogs[bare] {
|
|
os.Remove(filepath.Join(dir, name))
|
|
}
|
|
}
|
|
}
|
|
|
|
// create new log file
|
|
fname := filepath.Join(dir, name)
|
|
f, err := os.Create(fname)
|
|
if err == nil {
|
|
symlink := filepath.Join(dir, link)
|
|
os.Remove(symlink) // ignore err
|
|
os.Symlink(name, symlink) // ignore err
|
|
return f, fname, nil
|
|
}
|
|
lastErr = err
|
|
}
|
|
return nil, "", fmt.Errorf("log: cannot create log: %w", lastErr)
|
|
}
|