Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(worker,ui): send and view all logs #5247

Merged
merged 3 commits into from
Jun 11, 2020
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion engine/api/test/test.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ var (
)

func init() {
log.Initialize(&log.Conf{Level: "debug"})
log.Initialize(context.TODO(), &log.Conf{Level: "debug"})
}

type Bootstrapf func(context.Context, sdk.DefaultValues, func() *gorp.DbMap) error
Expand Down
4 changes: 1 addition & 3 deletions engine/cmd_start.go
Original file line number Diff line number Diff line change
Expand Up @@ -268,10 +268,8 @@ See $ engine config command for more details.
GraylogFieldCDSArch: sdk.GOARCH,
GraylogFieldCDSServiceName: strings.Join(names, "_"),
GraylogFieldCDSServiceType: strings.Join(types, "_"),
Ctx: ctx,
}
// TODO Logger: each service should have it own logger
log.Initialize(&logConf)
log.Initialize(ctx, &logConf)

// Sort the slice of services we have to start to be sure to start the API au first
sort.Slice(serviceConfs, func(i, j int) bool {
Expand Down
2 changes: 1 addition & 1 deletion engine/hatchery/serve.go
Original file line number Diff line number Diff line change
Expand Up @@ -193,7 +193,7 @@ func (c *Common) getPanicDumpListHandler() service.Handler {
func (c *Common) InitServiceLogger() error {
var signer jose.Signer
if c.Common.ServiceInstance.LogServerAdress != "" {
logger, err := log.New(c.Common.ServiceInstance.LogServerAdress)
logger, _, err := log.New(context.Background(), c.Common.ServiceInstance.LogServerAdress)
if err != nil {
return sdk.WithStack(err)
}
Expand Down
2 changes: 1 addition & 1 deletion engine/worker/cmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ func initFromFlags(cmd *cobra.Command, w *internal.CurrentWorker) {
basedir = os.TempDir()
}

log.Initialize(&log.Conf{
log.Initialize(context.Background(), &log.Conf{
Level: FlagString(cmd, flagLogLevel),
GraylogProtocol: FlagString(cmd, flagGraylogProtocol),
GraylogHost: FlagString(cmd, flagGraylogHost),
Expand Down
42 changes: 23 additions & 19 deletions engine/worker/internal/action/test_helper.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package action

import (
"bytes"
"context"
"fmt"
"os"
Expand All @@ -26,63 +27,66 @@ type TestWorker struct {
keyDirectory *afero.BasePathFile
client cdsclient.WorkerInterface
Params []sdk.Parameter
logBuffer bytes.Buffer
}

func (w TestWorker) WorkingDirectory() *afero.BasePathFile {
func (w *TestWorker) WorkingDirectory() *afero.BasePathFile {
return w.workingDirectory
}

func (w TestWorker) KeyDirectory() *afero.BasePathFile {
func (w *TestWorker) KeyDirectory() *afero.BasePathFile {
return w.keyDirectory
}

func (w TestWorker) Blur(i interface{}) error {
func (w *TestWorker) Blur(i interface{}) error {
w.t.Log("Blur")
return nil
}

func (w TestWorker) Parameters() []sdk.Parameter {
func (w *TestWorker) Parameters() []sdk.Parameter {
return w.Params
}

func (w TestWorker) Client() cdsclient.WorkerInterface {
func (w *TestWorker) Client() cdsclient.WorkerInterface {
return w.client
}

func (_ TestWorker) Environ() []string {
func (_ *TestWorker) Environ() []string {
return os.Environ()
}

func (_ TestWorker) HTTPPort() int32 {
func (_ *TestWorker) HTTPPort() int32 {
return 0
}

func (_ TestWorker) Name() string {
func (_ *TestWorker) Name() string {
return "test"
}

func (wk TestWorker) BaseDir() afero.Fs {
return wk.workspace
}

func (_ TestWorker) Register(ctx context.Context) error {
func (_ *TestWorker) Register(ctx context.Context) error {
return nil
}
func (_ TestWorker) Take(ctx context.Context, job sdk.WorkflowNodeJobRun) error {
func (_ *TestWorker) Take(ctx context.Context, job sdk.WorkflowNodeJobRun) error {
return nil
}
func (_ TestWorker) ProcessJob(job sdk.WorkflowNodeJobRunData) sdk.Result {
func (_ *TestWorker) ProcessJob(job sdk.WorkflowNodeJobRunData) sdk.Result {
return sdk.Result{}
}
func (w TestWorker) SendLog(ctx context.Context, level workerruntime.Level, format string) {
w.t.Log("SendLog> [" + string(level) + "] " + format)

func (w *TestWorker) SendLog(ctx context.Context, level workerruntime.Level, format string) {
s := "SendLog> [" + string(level) + "] " + format
w.t.Log(s)
_, err := w.logBuffer.WriteString(s)
require.NoError(w.t, err)
}
func (_ TestWorker) Unregister(ctx context.Context) error {
func (_ *TestWorker) Unregister(ctx context.Context) error {
return nil
}

func (w TestWorker) InstallKey(key sdk.Variable) (*workerruntime.KeyResponse, error) {
func (w *TestWorker) InstallKey(key sdk.Variable) (*workerruntime.KeyResponse, error) {
installedKeyPath := path.Join(w.keyDirectory.Name(), key.Name)
err := vcs.CleanAllSSHKeys(w.BaseDir(), w.keyDirectory.Name())
require.NoError(w.t, err)
Expand All @@ -101,7 +105,7 @@ func (w TestWorker) InstallKey(key sdk.Variable) (*workerruntime.KeyResponse, er
}, nil
}

func (w TestWorker) InstallKeyTo(key sdk.Variable, destinationPath string) (*workerruntime.KeyResponse, error) {
func (w *TestWorker) InstallKeyTo(key sdk.Variable, destinationPath string) (*workerruntime.KeyResponse, error) {
var installedKeyPath string

w.t.Logf("InstallKey> destination : %s", destinationPath)
Expand All @@ -120,7 +124,7 @@ func (w TestWorker) InstallKeyTo(key sdk.Variable, destinationPath string) (*wor

var _ workerruntime.Runtime = new(TestWorker)

func SetupTest(t *testing.T) (TestWorker, context.Context) {
func SetupTest(t *testing.T) (*TestWorker, context.Context) {
fs := afero.NewOsFs()
basedir := "test-" + test.GetTestName(t) + "-" + sdk.RandomString(10) + "-" + fmt.Sprintf("%d", time.Now().Unix())
log.Debug("creating basedir %s", basedir)
Expand Down Expand Up @@ -151,5 +155,5 @@ func SetupTest(t *testing.T) (TestWorker, context.Context) {
ctx = workerruntime.SetKeysDirectory(ctx, wk.keyDirectory)
ctx = workerruntime.SetJobID(ctx, 666)

return wk, ctx
return &wk, ctx
}
9 changes: 5 additions & 4 deletions engine/worker/internal/run.go
Original file line number Diff line number Diff line change
Expand Up @@ -224,10 +224,11 @@ func (w *CurrentWorker) runAction(ctx context.Context, a sdk.Action, jobID int64
//If the action if a edge of the action tree; run it
switch a.Type {
case sdk.BuiltinAction:
return w.runBuiltin(ctx, a, secrets)
res := w.runBuiltin(ctx, a, secrets)
return res
case sdk.PluginAction:
//Run the plugin
return w.runGRPCPlugin(ctx, a)
res := w.runGRPCPlugin(ctx, a)
return res
}

// There is is no children actions (action is empty) to do, success !
Expand Down Expand Up @@ -512,7 +513,7 @@ func (w *CurrentWorker) ProcessJob(jobInfo sdk.WorkflowNodeJobRunData) (res sdk.
ctx = workerruntime.SetStepOrder(ctx, 0)

// start logger routine with a large buffer
w.logger.logChan = make(chan sdk.Log, 100000)
w.logger.logChan = make(chan sdk.Log)
go func() {
if err := w.logProcessor(ctx, jobInfo.NodeJobRun.ID); err != nil {
log.Error(ctx, "processJob> Logs processor error: %v", err)
Expand Down
8 changes: 5 additions & 3 deletions engine/worker/internal/take.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,12 +46,14 @@ func (w *CurrentWorker) Take(ctx context.Context, job sdk.WorkflowNodeJobRun) er
}

if info.GelfServiceAddr != "" {
log.Info(ctx, "Setup step logger")
logger, err := log.New(info.GelfServiceAddr)
log.Info(ctx, "Setup step logger %s", info.GelfServiceAddr)
l, h, err := log.New(ctx, info.GelfServiceAddr)
if err != nil {
return sdk.WithStack(err)
}
w.logger.stepLogger = logger
w.logger.gelfLogger = new(logger)
w.logger.gelfLogger.logger = l
w.logger.gelfLogger.hook = h
}

start := time.Now()
Expand Down
14 changes: 10 additions & 4 deletions engine/worker/internal/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import (
"github.com/ovh/cds/sdk/cdsclient"
"github.com/ovh/cds/sdk/jws"
"github.com/ovh/cds/sdk/log"
loghook "github.com/ovh/cds/sdk/log/hook"
)

const (
Expand All @@ -28,6 +29,11 @@ const (
CDSApiUrl = "CDS_API_URL"
)

type logger struct {
hook *loghook.Hook
logger *logrus.Logger
}

type CurrentWorker struct {
id string
model sdk.Model
Expand All @@ -36,7 +42,7 @@ type CurrentWorker struct {
logger struct {
logChan chan sdk.Log
llist *list.List
stepLogger *logrus.Logger
gelfLogger *logger
}
httpPort int32
register struct {
Expand Down Expand Up @@ -96,7 +102,7 @@ func (wk *CurrentWorker) SendLog(ctx context.Context, level workerruntime.Level,

jobID, _ := workerruntime.JobID(ctx)
stepOrder, err := workerruntime.StepOrder(ctx)
if wk.logger.stepLogger == nil {
if wk.logger.gelfLogger == nil {
if !strings.HasSuffix(s, "\n") {
s += "\n"
}
Expand Down Expand Up @@ -134,8 +140,8 @@ func (wk *CurrentWorker) SendLog(ctx context.Context, level workerruntime.Level,
if err != nil {
log.Error(ctx, "unable to sign logs: %v", err)
}
wk.logger.stepLogger.WithField(log.ExtraFieldSignature, signature).Log(logLevel, s)

wk.logger.gelfLogger.logger.WithField(log.ExtraFieldSignature, signature).Log(logLevel, s)
wk.logger.gelfLogger.hook.Flush()
}

func (wk *CurrentWorker) Name() string {
Expand Down
8 changes: 3 additions & 5 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,6 @@ require (
github.com/inconshreveable/mousetrap v1.0.0 // indirect
github.com/itsjamie/gin-cors v0.0.0-20160420130702-97b4a9da7933
github.com/jefferai/jsonx v0.0.0-20160721235117-9cc31c3135ee // indirect
github.com/jstemmer/go-junit-report v0.9.1 // indirect
github.com/jtolds/gls v4.2.1+incompatible // indirect
github.com/juju/errors v0.0.0-20190207033735-e65537c515d7 // indirect
github.com/juju/loggo v0.0.0-20190526231331-6e530bcce5d8 // indirect
Expand All @@ -103,10 +102,10 @@ require (
github.com/keybase/go-crypto v0.0.0-20181127160227-255a5089e85a
github.com/keybase/go-keychain v0.0.0-20190828020956-aa639f275ae1
github.com/keybase/go.dbus v0.0.0-20190710215703-a33a09c8a604
github.com/konsorten/go-windows-terminal-sequences v1.0.2 // indirect
github.com/kr/pty v1.1.8 // indirect
github.com/kylelemons/godebug v1.1.0 // indirect
github.com/lib/pq v1.0.0
github.com/lytics/logrus v0.0.0-20170528191427-4389a17ed024 // indirect
github.com/magiconair/properties v1.8.1 // indirect
github.com/mailru/easyjson v0.0.0-20171120080333-32fa128f234d // indirect
github.com/marstr/guid v1.1.0 // indirect
Expand Down Expand Up @@ -161,7 +160,7 @@ require (
github.com/sethgrid/pester v0.0.0-20171127025028-760f8913c048 // indirect
github.com/sguiheux/go-coverage v0.0.0-20190710153556-287b082a7197
github.com/shirou/gopsutil v0.0.0-20170406131756-e49a95f3d5f8
github.com/sirupsen/logrus v1.4.2
github.com/sirupsen/logrus v1.6.0
github.com/smartystreets/assertions v0.0.0-20170213163019-15adfb6b24e2 // indirect
github.com/smartystreets/goconvey v0.0.0-20180222194500-ef6db91d284a // indirect
github.com/spf13/afero v1.2.2
Expand All @@ -181,7 +180,6 @@ require (
github.com/xanzy/go-gitlab v0.15.0
github.com/xi2/xz v0.0.0-20171230120015-48954b6210f8 // indirect
github.com/yesnault/go-toml v0.0.0-20191205182532-f5ef6cee7945
github.com/yesnault/gorp v2.0.0+incompatible // indirect
github.com/yuin/gluare v0.0.0-20170607022532-d7c94f1a80ed
github.com/yuin/gopher-lua v0.0.0-20170901023928-8c2befcd3908
github.com/ziutek/mymysql v1.5.4 // indirect
Expand Down Expand Up @@ -211,7 +209,7 @@ require (
gopkg.in/stomp.v1 v1.0.1 // indirect
gopkg.in/vmihailenco/msgpack.v2 v2.9.1 // indirect
gopkg.in/yaml.v2 v2.2.4
gotest.tools v2.1.0+incompatible
gotest.tools v2.1.0+incompatible // indirect
k8s.io/api v0.0.0-20181204000039-89a74a8d264d
k8s.io/apimachinery v0.0.0-20190223094358-dcb391cde5ca
k8s.io/client-go v10.0.0+incompatible
Expand Down
14 changes: 4 additions & 10 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -138,8 +138,6 @@ github.com/frankban/quicktest v1.6.0 h1:Cd62nl66vQsx8Uv1t8M0eICyxIwZG7MxiAOrdnnU
github.com/frankban/quicktest v1.6.0/go.mod h1:jaStnuzAqU1AJdCO0l53JDCJrVDKcS03DbaAcR7Ks/o=
github.com/fsamin/go-dump v1.0.9 h1:3MAneAJLnGfKTJtFEAdgrD+QqqK2Hwj7EJUQMQZcDls=
github.com/fsamin/go-dump v1.0.9/go.mod h1:ZgKd2aOXAFFbbFuUgvQhu7mwTlI3d3qnTICMWdvAa9o=
github.com/fsamin/go-repo v0.1.6 h1:2ZEljhqi6Iscwe0lC2nXsI4b5AxOToZ+kVfuItSoQsQ=
github.com/fsamin/go-repo v0.1.6/go.mod h1:JRLbo6sPXvAwwGs5RgifFk1pXiefeGf0hyHifEg1Vw4=
github.com/fsamin/go-repo v0.1.7 h1:cQ+ALKxDzxuNAqbvn8gT7yQSb9iO7ax15QgTGLfFaU8=
github.com/fsamin/go-repo v0.1.7/go.mod h1:JRLbo6sPXvAwwGs5RgifFk1pXiefeGf0hyHifEg1Vw4=
github.com/fsamin/go-shredder v0.0.0-20180118184739-b2488aedb5be h1:UhjSvwE1gxUYfekK9BXZ/LL55we9Avg+2Pt0PIlMYCk=
Expand Down Expand Up @@ -298,8 +296,6 @@ github.com/json-iterator/go v1.1.6/go.mod h1:+SdeFBvtyEkXs7REEP0seUULqWtbJapLOCV
github.com/json-iterator/go v1.1.7 h1:KfgG9LzI+pYjr4xvmz/5H4FXjokeP+rlHLhv3iH62Fo=
github.com/json-iterator/go v1.1.7/go.mod h1:KdQUCv79m/52Kvf8AW2vK1V8akMuk1QjK/uOdHXbAo4=
github.com/jstemmer/go-junit-report v0.0.0-20190106144839-af01ea7f8024/go.mod h1:6v2b51hI/fHJwM22ozAgKL4VKDeJcHhJFhtBdhmNjmU=
github.com/jstemmer/go-junit-report v0.9.1 h1:6QPYqodiu3GuPL+7mfx+NwDdp2eTkp9IfEUpgAwUN0o=
github.com/jstemmer/go-junit-report v0.9.1/go.mod h1:Brl9GWCQeLvo8nXZwPNNblvFj/XSXhF0NWZEnDohbsk=
github.com/jtolds/gls v4.2.1+incompatible h1:fSuqC+Gmlu6l/ZYAoZzx2pyucC8Xza35fpRVWLVmUEE=
github.com/jtolds/gls v4.2.1+incompatible/go.mod h1:QJZ7F/aHp+rZTRtaJ1ow/lLfFfVYBRgL+9YlvaHOwJU=
github.com/juju/errors v0.0.0-20190207033735-e65537c515d7 h1:dMIPRDg6gi7CUp0Kj2+HxqJ5kTr1iAdzsXYIrLCNSmU=
Expand All @@ -318,8 +314,8 @@ github.com/keybase/go.dbus v0.0.0-20190710215703-a33a09c8a604/go.mod h1:a8clEhrr
github.com/kisielk/errcheck v1.1.0/go.mod h1:EZBBE59ingxPouuu3KfxchcWSUPOHkagtvWXihfKN4Q=
github.com/kisielk/gotool v1.0.0/go.mod h1:XhKaO+MFFWcvkIS/tQcRk01m1F5IRFswLeQ+oQHNcck=
github.com/konsorten/go-windows-terminal-sequences v1.0.1/go.mod h1:T0+1ngSBFLxvqU3pZ+m/2kptfBszLMUkC4ZK/EgS/cQ=
github.com/konsorten/go-windows-terminal-sequences v1.0.2 h1:DB17ag19krx9CFsz4o3enTrPXyIXCl+2iCXH/aMAp9s=
github.com/konsorten/go-windows-terminal-sequences v1.0.2/go.mod h1:T0+1ngSBFLxvqU3pZ+m/2kptfBszLMUkC4ZK/EgS/cQ=
github.com/konsorten/go-windows-terminal-sequences v1.0.3 h1:CE8S1cTafDpPvMhIxNJKvHsGVBgn1xWYf1NbHQhywc8=
github.com/konsorten/go-windows-terminal-sequences v1.0.3/go.mod h1:T0+1ngSBFLxvqU3pZ+m/2kptfBszLMUkC4ZK/EgS/cQ=
github.com/kr/logfmt v0.0.0-20140226030751-b84e30acd515/go.mod h1:+0opPa2QZZtGFBFZlji/RkVcI2GknAs/DXo4wKdlNEc=
github.com/kr/pretty v0.1.0 h1:L/CwN0zerZDmRFUapSPitk6f+Q3+0za1rQkzVuMiMFI=
github.com/kr/pretty v0.1.0/go.mod h1:dAy3ld7l9f0ibDNOQOHHMYYIIbhfbHSm3C4ZsoJORNo=
Expand Down Expand Up @@ -500,8 +496,8 @@ github.com/shirou/gopsutil v0.0.0-20170406131756-e49a95f3d5f8 h1:05R1OwSk31dkzqf
github.com/shirou/gopsutil v0.0.0-20170406131756-e49a95f3d5f8/go.mod h1:5b4v6he4MtMOwMlS0TUMTu2PcXUg8+E1lC7eC3UO/RA=
github.com/sirupsen/logrus v1.0.6/go.mod h1:pMByvHTf9Beacp5x1UXfOR9xyW/9antXMhjMPG0dEzc=
github.com/sirupsen/logrus v1.2.0/go.mod h1:LxeOpSwHxABJmUn/MG1IvRgCAasNZTLOkJPxbbu5VWo=
github.com/sirupsen/logrus v1.4.2 h1:SPIRibHv4MatM3XXNO2BJeFLZwZ2LvZgfQ5+UNI2im4=
github.com/sirupsen/logrus v1.4.2/go.mod h1:tLMulIdttU9McNUspp0xgXVQah82FyeX6MwdIuYE2rE=
github.com/sirupsen/logrus v1.6.0 h1:UBcNElsrwanuuMsnGSlYmtmgbb23qDR5dG+6X6Oo89I=
github.com/sirupsen/logrus v1.6.0/go.mod h1:7uNnSEd1DgxDLC74fIahvMZmmYsHGZGEOFrfsX/uA88=
github.com/smartystreets/assertions v0.0.0-20170213163019-15adfb6b24e2 h1:/pp2hwWaiQp5Y2z2kQI27abzNecMhv0iVd8brrY/jP0=
github.com/smartystreets/assertions v0.0.0-20170213163019-15adfb6b24e2/go.mod h1:OnSkiWE9lh6wB0YB77sQom3nweQdgAjqCqsofrRNTgc=
github.com/smartystreets/goconvey v0.0.0-20180222194500-ef6db91d284a h1:JSvGDIbmil4Ui/dDdFBExb7/cmkNjyX5F97oglmvCDo=
Expand Down Expand Up @@ -565,8 +561,6 @@ github.com/yesnault/go-keychain v0.0.0-20190829085436-f78f7ae28786 h1:3i+IgAiigX
github.com/yesnault/go-keychain v0.0.0-20190829085436-f78f7ae28786/go.mod h1:EzotOW21xnO2Lld4dB8qr2bSnzi3nGtE9FG33n/y2Q8=
github.com/yesnault/go-toml v0.0.0-20191205182532-f5ef6cee7945 h1:icS0gqYJLvPFpni3gxPml7gCSdCcJx72RrbkVgmvw80=
github.com/yesnault/go-toml v0.0.0-20191205182532-f5ef6cee7945/go.mod h1:SsMrIuedaKvK8GekjwjVv8gMnHNAuvoINpKCARzdsEQ=
github.com/yesnault/gorp v2.0.0+incompatible h1:4pwtvWrXQTAgGVnzAB0X5jX/mWRQEa8zmcdNT5U8jyg=
github.com/yesnault/gorp v2.0.0+incompatible/go.mod h1:7nhqtxBPZoPXx86SqUzP/OFLd8prnhkydPk51uJthQc=
github.com/yesnault/gorp v2.0.1-0.20200325154225-2dc6d8c2da37+incompatible h1:8M+L4IKModOdc0ZsH0kHJiqZ7CmWF4yH8yy4InZxKyY=
github.com/yesnault/gorp v2.0.1-0.20200325154225-2dc6d8c2da37+incompatible/go.mod h1:7nhqtxBPZoPXx86SqUzP/OFLd8prnhkydPk51uJthQc=
github.com/yuin/gluare v0.0.0-20170607022532-d7c94f1a80ed h1:I1vcLHWU9m30rA90rMrKPu0eD3NDA4FBlkB8WMaDyUw=
Expand Down
22 changes: 12 additions & 10 deletions sdk/log/log.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ type Conf struct {
GraylogFieldCDSVersion string
GraylogFieldCDSOS string
GraylogFieldCDSArch string
Ctx context.Context
}

const (
Expand Down Expand Up @@ -69,7 +68,7 @@ func logWithLogger(level string, fields log.Fields, format string, values ...int
}

// Initialize init log level
func Initialize(conf *Conf) {
func Initialize(ctx context.Context, conf *Conf) {
switch conf.Level {
case "debug":
log.SetLevel(log.DebugLevel)
Expand Down Expand Up @@ -135,12 +134,9 @@ func Initialize(conf *Conf) {
}
}

if conf.Ctx == nil {
conf.Ctx = context.Background()
}
go func() {
<-conf.Ctx.Done()
log.Info(conf.Ctx, "Draining logs")
<-ctx.Done()
Info(ctx, "Draining logs...")
if hook != nil {
hook.Flush()
}
Expand Down Expand Up @@ -261,7 +257,7 @@ type SignatureService struct {
WorkerName string
}

func New(logServerAddr string) (*log.Logger, error) {
func New(ctx context.Context, logServerAddr string) (*log.Logger, *loghook.Hook, error) {
newLogger := log.New()
graylogcfg := &loghook.Config{
Addr: logServerAddr,
Expand All @@ -270,8 +266,14 @@ func New(logServerAddr string) (*log.Logger, error) {
extra := map[string]interface{}{}
hook, err := loghook.NewHook(graylogcfg, extra)
if err != nil {
return nil, fmt.Errorf("unable to add hook: %v", err)
return nil, nil, fmt.Errorf("unable to add hook: %v", err)
}
newLogger.AddHook(hook)
return newLogger, nil

go func() {
<-ctx.Done()
hook.Flush()
}()

return newLogger, hook, nil
}
Loading