mirror of
https://github.com/opencloud-eu/opencloud.git
synced 2026-05-05 19:09:56 -05:00
committed by
Ralf Haferkamp
parent
f280a00b7c
commit
e63ce368ed
@@ -13,7 +13,7 @@ require (
|
||||
github.com/coreos/go-oidc v2.2.1+incompatible
|
||||
github.com/coreos/go-oidc/v3 v3.7.0
|
||||
github.com/cs3org/go-cs3apis v0.0.0-20231023073225-7748710e0781
|
||||
github.com/cs3org/reva/v2 v2.16.1-0.20231127154323-1e3027b83df5
|
||||
github.com/cs3org/reva/v2 v2.16.1-0.20231128104331-ea8d1336afc9
|
||||
github.com/dhowden/tag v0.0.0-20230630033851-978a0926ee25
|
||||
github.com/disintegration/imaging v1.6.2
|
||||
github.com/dutchcoders/go-clamd v0.0.0-20170520113014-b970184f4d9e
|
||||
|
||||
@@ -1017,8 +1017,8 @@ github.com/crewjam/saml v0.4.14 h1:g9FBNx62osKusnFzs3QTN5L9CVA/Egfgm+stJShzw/c=
|
||||
github.com/crewjam/saml v0.4.14/go.mod h1:UVSZCf18jJkk6GpWNVqcyQJMD5HsRugBPf4I1nl2mME=
|
||||
github.com/cs3org/go-cs3apis v0.0.0-20231023073225-7748710e0781 h1:BUdwkIlf8IS2FasrrPg8gGPHQPOrQ18MS1Oew2tmGtY=
|
||||
github.com/cs3org/go-cs3apis v0.0.0-20231023073225-7748710e0781/go.mod h1:UXha4TguuB52H14EMoSsCqDj7k8a/t7g4gVP+bgY5LY=
|
||||
github.com/cs3org/reva/v2 v2.16.1-0.20231127154323-1e3027b83df5 h1:+R3E25HVI3Ms9fzgPy8QNkby3u8x7oKpRerB/A9l5iM=
|
||||
github.com/cs3org/reva/v2 v2.16.1-0.20231127154323-1e3027b83df5/go.mod h1:zcrrYVsBv/DwhpyO2/W5hoSZ/k6az6Z2EYQok65uqZY=
|
||||
github.com/cs3org/reva/v2 v2.16.1-0.20231128104331-ea8d1336afc9 h1:5vKQcL1hPHEZKu9e8C9rl0ap3ofMBznmoSgi4lRYXec=
|
||||
github.com/cs3org/reva/v2 v2.16.1-0.20231128104331-ea8d1336afc9/go.mod h1:zcrrYVsBv/DwhpyO2/W5hoSZ/k6az6Z2EYQok65uqZY=
|
||||
github.com/cyberdelia/templates v0.0.0-20141128023046-ca7fffd4298c/go.mod h1:GyV+0YP4qX0UQ7r2MoYZ+AvYDp12OF5yg4q8rGnyNh4=
|
||||
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
|
||||
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
|
||||
|
||||
+2
-79
@@ -20,7 +20,6 @@ package runtime
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"io"
|
||||
"log"
|
||||
"net"
|
||||
"os"
|
||||
@@ -43,9 +42,8 @@ import (
|
||||
|
||||
// Run runs a reva server with the given config file and pid file.
|
||||
func Run(mainConf map[string]interface{}, pidFile, logLevel string) {
|
||||
logConf := parseLogConfOrDie(mainConf["log"], logLevel)
|
||||
logger := initLogger(logConf)
|
||||
RunWithOptions(mainConf, pidFile, WithLogger(logger))
|
||||
log := logger.InitLoggerOrDie(mainConf["log"], logLevel)
|
||||
RunWithOptions(mainConf, pidFile, WithLogger(log))
|
||||
}
|
||||
|
||||
// RunWithOptions runs a reva server with the given config file, pid file and options.
|
||||
@@ -180,15 +178,6 @@ func initCPUCount(conf *coreConf, log *zerolog.Logger) {
|
||||
log.Info().Msgf("running on %d cpus", ncpus)
|
||||
}
|
||||
|
||||
func initLogger(conf *logConf) *zerolog.Logger {
|
||||
log, err := newLogger(conf)
|
||||
if err != nil {
|
||||
fmt.Fprintf(os.Stderr, "error creating logger, exiting ...")
|
||||
os.Exit(1)
|
||||
}
|
||||
return log
|
||||
}
|
||||
|
||||
func handlePIDFlag(l *zerolog.Logger, pidFile string, gracefulShutdownTimeout int) (*grace.Watcher, error) {
|
||||
w := grace.NewWatcher(grace.WithPIDFile(pidFile),
|
||||
grace.WithLogger(l.With().Str("pkg", "grace").Logger()),
|
||||
@@ -222,46 +211,6 @@ func start(mainConf map[string]interface{}, servers map[string]grace.Server, lis
|
||||
watcher.TrapSignals()
|
||||
}
|
||||
|
||||
func newLogger(conf *logConf) (*zerolog.Logger, error) {
|
||||
// TODO(labkode): use debug level rather than info as default until reaching a stable version.
|
||||
// Helps having smaller development files.
|
||||
if conf.Level == "" {
|
||||
conf.Level = zerolog.DebugLevel.String()
|
||||
}
|
||||
|
||||
var opts []logger.Option
|
||||
opts = append(opts, logger.WithLevel(conf.Level))
|
||||
|
||||
w, err := getWriter(conf.Output)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
opts = append(opts, logger.WithWriter(w, logger.Mode(conf.Mode)))
|
||||
|
||||
l := logger.New(opts...)
|
||||
sub := l.With().Int("pid", os.Getpid()).Logger()
|
||||
return &sub, nil
|
||||
}
|
||||
|
||||
func getWriter(out string) (io.Writer, error) {
|
||||
if out == "stderr" || out == "" {
|
||||
return os.Stderr, nil
|
||||
}
|
||||
|
||||
if out == "stdout" {
|
||||
return os.Stdout, nil
|
||||
}
|
||||
|
||||
fd, err := os.OpenFile(out, os.O_APPEND|os.O_CREATE|os.O_WRONLY, 0o644)
|
||||
if err != nil {
|
||||
err = errors.Wrap(err, "error creating log file: "+out)
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return fd, nil
|
||||
}
|
||||
|
||||
func getGRPCServer(conf interface{}, l *zerolog.Logger, tp trace.TracerProvider) (*rgrpc.Server, error) {
|
||||
sub := l.With().Str("pkg", "rgrpc").Logger()
|
||||
s, err := rgrpc.NewServer(conf, sub, tp)
|
||||
@@ -348,32 +297,6 @@ func parseSharedConfOrDie(v interface{}) {
|
||||
}
|
||||
}
|
||||
|
||||
func parseLogConfOrDie(v interface{}, logLevel string) *logConf {
|
||||
c := &logConf{}
|
||||
if err := mapstructure.Decode(v, c); err != nil {
|
||||
fmt.Fprintf(os.Stderr, "error decoding log config: %s\n", err.Error())
|
||||
os.Exit(1)
|
||||
}
|
||||
|
||||
// if mode is not set, we use console mode, easier for devs
|
||||
if c.Mode == "" {
|
||||
c.Mode = "console"
|
||||
}
|
||||
|
||||
// Give priority to the log level passed through the command line.
|
||||
if logLevel != "" {
|
||||
c.Level = logLevel
|
||||
}
|
||||
|
||||
return c
|
||||
}
|
||||
|
||||
type logConf struct {
|
||||
Output string `mapstructure:"output"`
|
||||
Mode string `mapstructure:"mode"`
|
||||
Level string `mapstructure:"level"`
|
||||
}
|
||||
|
||||
func isEnabledHTTP(conf map[string]interface{}) bool {
|
||||
return isEnabled("http", conf)
|
||||
}
|
||||
|
||||
+77
@@ -19,10 +19,13 @@
|
||||
package logger
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"io"
|
||||
"os"
|
||||
"time"
|
||||
|
||||
"github.com/mitchellh/mapstructure"
|
||||
"github.com/pkg/errors"
|
||||
"github.com/rs/zerolog"
|
||||
)
|
||||
|
||||
@@ -85,3 +88,77 @@ func parseLevel(v string) zerolog.Level {
|
||||
|
||||
return lvl
|
||||
}
|
||||
|
||||
func InitLoggerOrDie(v interface{}, logLevel string) *zerolog.Logger {
|
||||
conf := ParseLogConfOrDie(v, logLevel)
|
||||
log, err := FromConfig(conf)
|
||||
if err != nil {
|
||||
fmt.Fprintf(os.Stderr, "error creating logger, exiting ...")
|
||||
os.Exit(1)
|
||||
}
|
||||
return log
|
||||
}
|
||||
|
||||
func ParseLogConfOrDie(v interface{}, logLevel string) *LogConf {
|
||||
c := &LogConf{}
|
||||
if err := mapstructure.Decode(v, c); err != nil {
|
||||
fmt.Fprintf(os.Stderr, "error decoding log config: %s\n", err.Error())
|
||||
os.Exit(1)
|
||||
}
|
||||
|
||||
// if mode is not set, we use console mode, easier for devs
|
||||
if c.Mode == "" {
|
||||
c.Mode = "console"
|
||||
}
|
||||
|
||||
// Give priority to the log level passed through the command line.
|
||||
if logLevel != "" {
|
||||
c.Level = logLevel
|
||||
}
|
||||
|
||||
return c
|
||||
}
|
||||
|
||||
type LogConf struct {
|
||||
Output string `mapstructure:"output"`
|
||||
Mode string `mapstructure:"mode"`
|
||||
Level string `mapstructure:"level"`
|
||||
}
|
||||
|
||||
func FromConfig(conf *LogConf) (*zerolog.Logger, error) {
|
||||
if conf.Level == "" {
|
||||
conf.Level = zerolog.DebugLevel.String()
|
||||
}
|
||||
|
||||
var opts []Option
|
||||
opts = append(opts, WithLevel(conf.Level))
|
||||
|
||||
w, err := getWriter(conf.Output)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
opts = append(opts, WithWriter(w, Mode(conf.Mode)))
|
||||
|
||||
l := New(opts...)
|
||||
sub := l.With().Int("pid", os.Getpid()).Logger()
|
||||
return &sub, nil
|
||||
}
|
||||
|
||||
func getWriter(out string) (io.Writer, error) {
|
||||
if out == "stderr" || out == "" {
|
||||
return os.Stderr, nil
|
||||
}
|
||||
|
||||
if out == "stdout" {
|
||||
return os.Stdout, nil
|
||||
}
|
||||
|
||||
fd, err := os.OpenFile(out, os.O_APPEND|os.O_CREATE|os.O_WRONLY, 0o644)
|
||||
if err != nil {
|
||||
err = errors.Wrap(err, "error creating log file: "+out)
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return fd, nil
|
||||
}
|
||||
|
||||
Generated
Vendored
+12
-8
@@ -224,17 +224,21 @@ func Get(ctx context.Context, id string, lu *lookup.Lookup, tp Tree, fsRoot stri
|
||||
}
|
||||
|
||||
ctx = ctxpkg.ContextSetUser(ctx, u)
|
||||
// TODO configure the logger the same way ... store and add traceid in file info
|
||||
|
||||
var opts []logger.Option
|
||||
opts = append(opts, logger.WithLevel(info.Storage["LogLevel"]))
|
||||
opts = append(opts, logger.WithWriter(os.Stderr, logger.ConsoleMode))
|
||||
l := logger.New(opts...)
|
||||
|
||||
sub := l.With().Int("pid", os.Getpid()).Logger()
|
||||
|
||||
// restore logger from file info
|
||||
log, err := logger.FromConfig(&logger.LogConf{
|
||||
Output: "stderr", // TODO use config from decomposedfs
|
||||
Mode: "json", // TODO use config from decomposedfs
|
||||
Level: info.Storage["LogLevel"],
|
||||
})
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
sub := log.With().Int("pid", os.Getpid()).Logger()
|
||||
ctx = appctx.WithLogger(ctx, &sub)
|
||||
|
||||
// TODO store and add traceid in file info
|
||||
|
||||
up := buildUpload(ctx, info, info.Storage["BinPath"], infoPath, lu, tp, pub, async, tknopts)
|
||||
up.versionsPath = info.MetaData["versionsPath"]
|
||||
up.SizeDiff, _ = strconv.ParseInt(info.MetaData["sizeDiff"], 10, 64)
|
||||
|
||||
Vendored
+1
-1
@@ -357,7 +357,7 @@ github.com/cs3org/go-cs3apis/cs3/storage/provider/v1beta1
|
||||
github.com/cs3org/go-cs3apis/cs3/storage/registry/v1beta1
|
||||
github.com/cs3org/go-cs3apis/cs3/tx/v1beta1
|
||||
github.com/cs3org/go-cs3apis/cs3/types/v1beta1
|
||||
# github.com/cs3org/reva/v2 v2.16.1-0.20231127154323-1e3027b83df5
|
||||
# github.com/cs3org/reva/v2 v2.16.1-0.20231128104331-ea8d1336afc9
|
||||
## explicit; go 1.20
|
||||
github.com/cs3org/reva/v2/cmd/revad/internal/grace
|
||||
github.com/cs3org/reva/v2/cmd/revad/runtime
|
||||
|
||||
Reference in New Issue
Block a user