Log to cloud object storage for golang. Zap extension.

cos-logger

Log to cloud object storage for golang implemented as io.Writer.

Use it as a plugin/extension to uber-go/zap logger

Configure logger and add a multi write syncer for zap as follows,

package cos_logger
import (
	"fmt"
	"os"
	"os/signal"
	"syscall"
	
	"go.uber.org/zap"
	"go.uber.org/zap/zapcore"
    cl "github.com/scrapcodes/cos-logger"
)

func initializeLogger() {

	loggerConfig := cl.ObjectStoreLogConfig{}
	objectStoreLogger := cl.Logger{
		MaxSize: 1024 * 100, // After reaching this size the buffer syncs with object store.
	}
    
	// Provide all the configuration.
	loggerConfig.AccessKey = "key"
	loggerConfig.SecretKey = "key_secret"
	loggerConfig.Region = "us-south"
	loggerConfig.ServiceEndpoint = "<url>"
	loggerConfig.DefaultBucketName = "<bucket_name>"
	loggerConfig.CreateBucket = false // If the bucket already exists.

	_ = objectStoreLogger.LoadDefaults(loggerConfig)
	// setup a multi sync writer as follows,
	w := zapcore.NewMultiWriteSyncer(
		zapcore.AddSync(os.Stdout),
		zapcore.AddSync(&objectStoreLogger),
	)
	core := zapcore.NewCore(
		zapcore.NewJSONEncoder(zap.NewProductionEncoderConfig()),
		w,
		zap.InfoLevel,
	)
	logger := zap.New(core)
	logger.Info("First log msg with object store logger.")
}

// If you wish to sync with object store before shutdown.
func shutdownHook() {
	// set up SIGHUP to send logs to object store before shutdown.
	signal.Ignore(syscall.SIGHUP, syscall.SIGTERM, syscall.SIGINT)
	c := make(chan os.Signal, 3)
	signal.Notify(c, syscall.SIGTERM)
	signal.Notify(c, syscall.SIGINT)
	signal.Notify(c, syscall.SIGHUP)

	go func() {
		for {
			<-c
			err := objectStoreLogger.Close()
			fmt.Printf("Synced with object store... %v", err)
			os.Exit(0)
		}
	}()
}
Similar Resources

Logger - A thin wrapper of uber-go/zap logger for personal project

a thin wraper of uber-go/zap logger for personal project 0. thanks uber-go/zap B

Sep 17, 2022

A logrus.Hook that logs with a zap.Logger

zaprus Ever had a 3rd-party dependency requiring a logrus, but you're using zap? zaprus provides a logrus.Hook that makes a logrus.(Entry|Logger) repl

Feb 27, 2022

Zapctx: an encapsulation of zap, adding WithContext to the logger

Abstract zapctx is an encapsulation of zap, adding WithContext to the logger. Fe

Oct 14, 2022

a golang log lib supports level and multi handlers

go-log a golang log lib supports level and multi handlers Use import "github.com/siddontang/go-log/log" //log with different level log.Info("hello wo

Dec 29, 2022

Simple log parser written in Golang

Simple log parser written in Golang

Oct 31, 2021

Self-use log encapsulation for golang

package app import "github.com/restoflife/log" func Init() { log.Ne

Dec 29, 2021

Go-logging-logrus - Learn how to log management in golang with logrus

Learn how to logging in golang with logrus How to run this project git clone htt

Jan 19, 2022

Tlog - Golang log but via telegram bot support

tlog golang log but via telegram bot support how to use tlog.LinkBot("token", "c

Nov 25, 2022

Third party extension interface for sillyGirl.

Third party extension interface for sillyGirl.

tb_fanli qq交流群:418353744 线报群:263723430 Third party extension interface for sillyGirl. 1 you need a account of taobao Union, 2 you need a account of di

Nov 29, 2022
Rzap - Log rotate for uber-zap

rzap Log rotate for uber-zap How to install go get github.com/winking324/rzap Ho

Jan 26, 2022
Package zaperations provides a Google Cloud operations suite (formerly Stackdriver) compatible config for the uber-go/zap logger.

Package zaperations provides a Google Cloud Operations (formerly Stackdriver) compatible config for the excellent uber-go/zap logger. Example This exa

Nov 6, 2021
An golang log lib, supports tracking and level, wrap by standard log lib

Logex An golang log lib, supports tracing and level, wrap by standard log lib How To Get shell go get gopkg.in/logex.v1 source code import "gopkg.in/

Nov 27, 2022
Distributed-Log-Service - Distributed Log Service With Golang
Distributed-Log-Service - Distributed Log Service With Golang

Distributed Log Service This project is essentially a result of my attempt to un

Jun 1, 2022
Log-analyzer - Log analyzer with golang

Log Analyzer what do we have here? Objective Installation and Running Applicatio

Jan 27, 2022
Nginx-Log-Analyzer is a lightweight (simplistic) log analyzer for Nginx.
Nginx-Log-Analyzer is a lightweight (simplistic) log analyzer for Nginx.

Nginx-Log-Analyzer is a lightweight (simplistic) log analyzer, used to analyze Nginx access logs for myself.

Nov 29, 2022
Hook for sending events zap logger to telegram.

zaptelegram Hook for sending events to telegram for zap logger. Install: go get -u github.com/strpc/zaptelegram Basic usage: package main import ( "

Oct 15, 2022
logger wraps uber/zap and trace with opentelemetry

logger 特性 支持 uber/zap 日志 支持 log rolling,使用 lumberjace 支持日志追踪 支持debug、info、warn、e

Sep 17, 2022
Go starter project with Gin, Viper, postgres , redis, zap, prometheus metrics etc setup

Go REST Service Starter/Boilerplate Easily extendible REST API Service boilerplate aiming to follow idiomatic go and best practice. Any feedback and p

Jun 23, 2022
Alternative logging through zap.

wzap Alternative logging through zap Usage Start using it Download and install it: go get github.com/wyy-go/wzap Import it in your code: import "githu

Jan 8, 2022