~rogpeppe/juju-core/themue-058-debug-log-api

« back to all changes in this revision

Viewing changes to state/api/debugger/debugger.go

  • Committer: Frank Mueller
  • Date: 2014-01-17 17:07:41 UTC
  • Revision ID: frank.mueller@canonical.com-20140117170741-ywfubevw7ery16vh
debugger: removed api debugger package and added watch command to client

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
// Copyright 2014 Canonical Ltd.
2
 
// Licensed under the AGPLv3, see LICENCE file for details.
3
 
 
4
 
package debugger
5
 
 
6
 
import (
7
 
        "fmt"
8
 
 
9
 
        "launchpad.net/juju-core/state/api/common"
10
 
        "launchpad.net/juju-core/state/api/params"
11
 
        "launchpad.net/juju-core/state/api/watcher"
12
 
)
13
 
 
14
 
// State provides access to an debugger worker's view of the state.
15
 
type State struct {
16
 
        caller common.Caller
17
 
}
18
 
 
19
 
// NewState returns a version of the state that provides functionality
20
 
// required by the debugger worker.
21
 
func NewState(caller common.Caller) *State {
22
 
        return &State{caller}
23
 
}
24
 
 
25
 
// WatchDebugLog starts a StringsWatcher to watch the all-machines log. The initial
26
 
// number of lines and a filter tag for machines or units can be passed.
27
 
func (st *State) WatchDebugLog(lines int, tag string) (watcher.StringsWatcher, error) {
28
 
        var results params.StringsWatchResults
29
 
        args := params.EntityLogRequests{Entities: []params.EntityLogRequest{{
30
 
                Lines: lines,
31
 
                Tag:   tag,
32
 
        }}}
33
 
        err := st.caller.Call("Debugger", "", "WatchDebugLog", args, &results)
34
 
        if err != nil {
35
 
                return nil, err
36
 
        }
37
 
        if len(results.Results) != 1 {
38
 
                return nil, fmt.Errorf("expected one result, got %d", len(results.Results))
39
 
        }
40
 
        result := results.Results[0]
41
 
        if result.Error != nil {
42
 
                return nil, result.Error
43
 
        }
44
 
        w := watcher.NewStringsWatcher(st.caller, result)
45
 
        return w, nil
46
 
}