12
12
"launchpad.net/juju-core/state/watcher"
15
var logger = loggo.GetLogger("juju.api.logger")
16
logger = loggo.GetLogger("juju.api.logger")
18
logLocation = "/var/log/juju/all-machines.log"
17
21
// Logger defines the methods on the logger API end point. Unfortunately, the
18
22
// api infrastructure doesn't allow interfaces to be used as an actual
21
25
type Logger interface {
22
26
WatchLoggingConfig(args params.Entities) params.NotifyWatchResults
23
27
LoggingConfig(args params.Entities) params.StringResults
28
WatchDebugLog(args params.DebugLogWatchings) params.StringsWatchResults
26
31
// LoggerAPI implements the Logger interface and is the concrete
92
97
return params.StringResults{results}
100
// WatchDebugLog starts a StringsWatcher to watch the debug log for entries
101
// regarding the machines or units passed in args.
102
func (api *LoggerAPI) WatchDebugLog(args params.DebugLogWatchings) params.StringsWatchResults {
103
result := params.StringsWatchResults{
104
Results: make([]params.StringsWatchResult, len(args.Watchings)),
106
for i, watching := range args.Watchings {
107
debugResult, err := api.watchOneDebugLog(watching)
108
result.Results[i] = debugResult
109
result.Results[i].Error = common.ServerError(err)
114
// watchOneDebugLog starts a StringWatcher for the log entries of
115
// one machine or unit.
116
func (api *LoggerAPI) watchOneDebugLog(arg params.DebugLogWatching) (params.StringsWatchResult, error) {
117
nothing := params.StringsWatchResult{}
118
logTailer, err := startLogTailer(logLocation, arg.Lines, arg.Tag)
122
defer logTailer.Stop()
123
// Consume the initial event and forward it to the result.
124
if changes, ok := <-logTailer.Changes(); ok {
125
return params.StringsWatchResult{
126
StringsWatcherId: api.resources.Register(logTailer),
130
return nothing, watcher.MustErr(logTailer)