Blame


1 4b33cdd0 2015-11-30 stephen.d // +build ignore
2 4b33cdd0 2015-11-30 stephen.d
3 4b33cdd0 2015-11-30 stephen.d package p9p
4 4b33cdd0 2015-11-30 stephen.d
5 4b33cdd0 2015-11-30 stephen.d import (
6 4b33cdd0 2015-11-30 stephen.d "log"
7 4b33cdd0 2015-11-30 stephen.d "os"
8 4b33cdd0 2015-11-30 stephen.d )
9 4b33cdd0 2015-11-30 stephen.d
10 4b33cdd0 2015-11-30 stephen.d type logging struct {
11 4b33cdd0 2015-11-30 stephen.d session Session
12 4b33cdd0 2015-11-30 stephen.d logger log.Logger
13 4b33cdd0 2015-11-30 stephen.d }
14 4b33cdd0 2015-11-30 stephen.d
15 4b33cdd0 2015-11-30 stephen.d var _ Session = &logging{}
16 4b33cdd0 2015-11-30 stephen.d
17 4b33cdd0 2015-11-30 stephen.d func NewLogger(prefix string, session Session) Session {
18 4b33cdd0 2015-11-30 stephen.d return &logging{
19 4b33cdd0 2015-11-30 stephen.d session: session,
20 4b33cdd0 2015-11-30 stephen.d logger: *log.New(os.Stdout, prefix, 0),
21 4b33cdd0 2015-11-30 stephen.d }
22 4b33cdd0 2015-11-30 stephen.d }
23 4b33cdd0 2015-11-30 stephen.d
24 4b33cdd0 2015-11-30 stephen.d func (l *logging) Auth(afid Fid, uname, aname string) (Qid, error) {
25 4b33cdd0 2015-11-30 stephen.d qid, err := l.session.Auth(afid, uname, aname)
26 4b33cdd0 2015-11-30 stephen.d l.logger.Printf("Auth(%v, %s, %s) -> (%v, %v)", afid, uname, aname, qid, err)
27 4b33cdd0 2015-11-30 stephen.d return qid, err
28 4b33cdd0 2015-11-30 stephen.d }
29 4b33cdd0 2015-11-30 stephen.d
30 4b33cdd0 2015-11-30 stephen.d func (l *logging) Attach(fid, afid Fid, uname, aname string) (Qid, error) {
31 4b33cdd0 2015-11-30 stephen.d qid, err := l.session.Attach(fid, afid, uname, aname)
32 4b33cdd0 2015-11-30 stephen.d l.logger.Printf("Attach(%v, %v, %s, %s) -> (%v, %v)", fid, afid, uname, aname, qid, err)
33 4b33cdd0 2015-11-30 stephen.d return qid, err
34 4b33cdd0 2015-11-30 stephen.d }
35 4b33cdd0 2015-11-30 stephen.d
36 4b33cdd0 2015-11-30 stephen.d func (l *logging) Clunk(fid Fid) error {
37 4b33cdd0 2015-11-30 stephen.d return l.session.Clunk(fid)
38 4b33cdd0 2015-11-30 stephen.d }
39 4b33cdd0 2015-11-30 stephen.d
40 4b33cdd0 2015-11-30 stephen.d func (l *logging) Remove(fid Fid) (err error) {
41 4b33cdd0 2015-11-30 stephen.d defer func() {
42 4b33cdd0 2015-11-30 stephen.d l.logger.Printf("Remove(%v) -> %v", fid, err)
43 4b33cdd0 2015-11-30 stephen.d }()
44 4b33cdd0 2015-11-30 stephen.d return l.session.Remove(fid)
45 4b33cdd0 2015-11-30 stephen.d }
46 4b33cdd0 2015-11-30 stephen.d
47 4b33cdd0 2015-11-30 stephen.d func (l *logging) Walk(fid Fid, newfid Fid, names ...string) ([]Qid, error) {
48 4b33cdd0 2015-11-30 stephen.d return l.session.Walk(fid, newfid, names...)
49 4b33cdd0 2015-11-30 stephen.d }
50 4b33cdd0 2015-11-30 stephen.d
51 4b33cdd0 2015-11-30 stephen.d func (l *logging) Read(fid Fid, p []byte, offset int64) (n int, err error) {
52 4b33cdd0 2015-11-30 stephen.d return l.session.Read(fid, p, offset)
53 4b33cdd0 2015-11-30 stephen.d }
54 4b33cdd0 2015-11-30 stephen.d
55 4b33cdd0 2015-11-30 stephen.d func (l *logging) Write(fid Fid, p []byte, offset int64) (n int, err error) {
56 4b33cdd0 2015-11-30 stephen.d return l.session.Write(fid, p, offset)
57 4b33cdd0 2015-11-30 stephen.d }
58 4b33cdd0 2015-11-30 stephen.d
59 4b33cdd0 2015-11-30 stephen.d func (l *logging) Open(fid Fid, mode int32) (Qid, error) {
60 4b33cdd0 2015-11-30 stephen.d return l.session.Open(fid, mode)
61 4b33cdd0 2015-11-30 stephen.d }
62 4b33cdd0 2015-11-30 stephen.d
63 4b33cdd0 2015-11-30 stephen.d func (l *logging) Create(parent Fid, name string, perm uint32, mode uint32) (Qid, error) {
64 4b33cdd0 2015-11-30 stephen.d return l.session.Create(parent, name, perm, mode)
65 4b33cdd0 2015-11-30 stephen.d }
66 4b33cdd0 2015-11-30 stephen.d
67 4b33cdd0 2015-11-30 stephen.d func (l *logging) Stat(fid Fid) (Dir, error) {
68 4b33cdd0 2015-11-30 stephen.d return l.session.Stat(fid)
69 4b33cdd0 2015-11-30 stephen.d }
70 4b33cdd0 2015-11-30 stephen.d
71 4b33cdd0 2015-11-30 stephen.d func (l *logging) WStat(fid Fid, dir Dir) error {
72 4b33cdd0 2015-11-30 stephen.d return l.session.WStat(fid, dir)
73 4b33cdd0 2015-11-30 stephen.d }
74 4b33cdd0 2015-11-30 stephen.d
75 4b33cdd0 2015-11-30 stephen.d func (l *logging) Version(msize int32, version string) (int32, string, error) {
76 4b33cdd0 2015-11-30 stephen.d return l.session.Version(msize, version)
77 4b33cdd0 2015-11-30 stephen.d }