1
// Copyright 2015 Canonical Ltd.
2
// Licensed under the AGPLv3, see LICENCE file for details.
9
"github.com/juju/errors"
10
"github.com/juju/loggo"
12
"github.com/juju/juju/api/logsender"
13
"github.com/juju/juju/apiserver/params"
14
"github.com/juju/juju/worker"
17
const loggerName = "juju.worker.logsender"
19
// New starts a logsender worker which reads log message structs from
20
// a channel and sends them to the JES via the logsink API.
21
func New(logs LogRecordCh, logSenderAPI *logsender.API) worker.Worker {
22
loop := func(stop <-chan struct{}) error {
23
logWriter, err := logSenderAPI.LogWriter()
25
return errors.Annotate(err, "logsender dial failed")
27
defer logWriter.Close()
31
err := logWriter.WriteLog(¶ms.LogRecord{
34
Location: rec.Location,
35
Level: rec.Level.String(),
39
return errors.Trace(err)
41
if rec.DroppedAfter > 0 {
42
// If messages were dropped after this one, report
43
// the count (the source of the log messages -
44
// BufferedLogWriter - handles the actual dropping
47
// Any logs indicated as dropped here are will
48
// never end up in the logs DB in the JES
49
// (although will still be in the local agent log
50
// file). Message dropping by the
51
// BufferedLogWriter is last resort protection
52
// against memory exhaustion and should only
53
// happen if API connectivity is lost for extended
54
// periods. The maximum in-memory log buffer is
55
// quite large (see the InstallBufferedLogWriter
56
// call in jujuDMain).
57
err := logWriter.WriteLog(¶ms.LogRecord{
60
Level: loggo.WARNING.String(),
61
Message: fmt.Sprintf("%d log messages dropped due to lack of API connectivity", rec.DroppedAfter),
64
return errors.Trace(err)
73
return worker.NewSimpleWorker(loop)