Esempio n. 1
0
func (m *PyModule) Init(tag string, ctxObj py.Object) {
	var ctx log.Context
	if c, ok := ctxObj.(*PyContext); ok {
		ctx = c
	} else {
		ctx = log.NilContext
	}
	m.Module = log.New(tag, ctx).(*log.Module)
}
Esempio n. 2
0
func NewScheduler() _Scheduler {
	var s _Scheduler
	s.tasks = make(map[TaskHook]*list.List)
	for _, hook := range taskHookConstants {
		s.tasks[hook] = list.New()
	}
	s.logger = log.New("scheduler", log.NilContext)
	return s
}
Esempio n. 3
0
func TestDispatch(t *testing.T) {
	log.Targets = map[string]log.Handler{}
	log.Targets["target1"] = &mockTarget{make([]log.Record, 0)}
	log.Targets["target2"] = &mockTarget{make([]log.Record, 0)}

	logger := log.New("testing", log.MapContext{
		"A": 123,
	})

	entries := []entry{
		entry{
			log.LvlInfo,
			"Log Message 1",
		},
		entry{
			log.LvlDebug,
			"Log Message 2",
		},
	}

	for _, r := range entries {
		logger.Dispatch(r.lvl, r.msg)
	}

	if len(log.Targets) != 2 {
		t.Error("Target length invalid")
	}

	for _, target := range log.Targets {
		records := target.(*mockTarget).records

		if len(records) != 2 {
			t.Error("Record length invalid")
		}

		for i, r := range records {
			if r.Level() != entries[i].lvl {
				t.Error("Log level mismatch")
			}

			if r.Tag() != "testing" {
				t.Error("Log tag mismatch")
			}

			if r.Message() != entries[i].msg {
				t.Error("Log message mismatch")
			}

			rctx := r.Context().ContextMap()
			if v, ok := rctx["A"]; !ok || v != 123 {
				t.Error("Log context mismatch")
			}
		}
	}
}
Esempio n. 4
0
func TestConvenienceFunctions(t *testing.T) {
	log.Targets = map[string]log.Handler{}
	log.Targets["target"] = &mockTarget{make([]log.Record, 0)}

	logger := log.New("testing", log.MapContext{
		"A": 123,
	})

	entries := []entry{
		entry{
			log.LvlInfo,
			"Log Message 1",
		},
		entry{
			log.LvlError,
			"Log Message 2",
		},
		entry{
			log.LvlDebug,
			"Log Message 3",
		},
	}

	logger.Info(entries[0].msg)
	logger.Error(entries[1].msg)
	logger.Debug(entries[2].msg)

	target := log.Targets["target"]
	records := target.(*mockTarget).records

	if len(records) != 3 {
		t.Error("Record length invalid")
	}

	for i, r := range records {
		if r.Level() != entries[i].lvl {
			t.Error("Log level mismatch")
		}

		if r.Tag() != "testing" {
			t.Error("Log tag mismatch")
		}

		if r.Message() != entries[i].msg {
			t.Error("Log message mismatch")
		}

		rctx := r.Context().ContextMap()
		if v, ok := rctx["A"]; !ok || v != 123 {
			t.Error("Log context mismatch")
		}
	}
}
Esempio n. 5
0
File: engine.go Progetto: gemrs/gem
package gem

import (
	"time"

	engine_event "github.com/gemrs/gem/gem/engine/event"
	"github.com/gemrs/gem/gem/task"
	"github.com/gemrs/gem/gem/util/safe"
	"github.com/gemrs/willow/log"

	"github.com/qur/gopy/lib"
	tomb "gopkg.in/tomb.v2"
)

var logger = log.New("engine", log.NilContext)

type Engine struct {
	py.BaseObject

	t tomb.Tomb
}

var EngineTick = 600 * time.Millisecond

func (e *Engine) Init() {}

func (e *Engine) Start() {
	logger.Info("Starting engine")
	engine_event.Startup.NotifyObservers()

	e.t.Go(e.run)
Esempio n. 6
0
File: server.go Progetto: gemrs/gem
import (
	"fmt"
	"net"
	"sync"

	"github.com/gemrs/gem/gem/protocol"
	"github.com/gemrs/gem/gem/util/id"
	"github.com/gemrs/gem/gem/util/safe"
	"github.com/gemrs/willow/log"

	"github.com/qur/gopy/lib"
	tomb "gopkg.in/tomb.v2"
)

var logger = log.New("server", log.NilContext)

// Server is the listener object and its associated state
type Server struct {
	py.BaseObject

	laddr string
	ln    net.Listener

	nextIndex <-chan int

	m        sync.Mutex
	clients  map[int]Client
	services map[int]Service

	t tomb.Tomb
Esempio n. 7
0
File: sector.go Progetto: gemrs/gem
func (s *Sector) Init(position *position.Sector) {
	s.Collection = entity.NewCollection()
	s.position = position
	s.logger = log.New("world/sector", log.MapContext{"position": position})
}
Esempio n. 8
0
File: server.go Progetto: gemrs/gem
import (
	"fmt"
	"net"
	"regexp"
	"sync"

	"github.com/gemrs/gem/gem/runite"
	"github.com/gemrs/gem/gem/runite/format/rt3"
	"github.com/gemrs/willow/log"

	"bufio"
	"github.com/qur/gopy/lib"
	tomb "gopkg.in/tomb.v2"
)

var logger = log.New("archive", log.NilContext)
var requestRegexp = regexp.MustCompile("JAGGRAB /([a-z]+)[0-9\\-]+")

type Server struct {
	py.BaseObject

	laddr string
	ln    net.Listener

	archives *rt3.ArchiveFS

	t tomb.Tomb
}

func (s *Server) Init() {}
Esempio n. 9
0
File: event.go Progetto: gemrs/gem
func (e *Event) Init(key string) {
	e.key = key
	e.observers = make(map[int]Observer)
	e.log = log.New("event", log.MapContext{"event": key})
}
Esempio n. 10
0
func TestBuffer(t *testing.T) {
	mtarget := &mockTarget{make([]log.Record, 0)}
	buffer := log.NewBufferingTarget(mtarget)

	log.Targets = map[string]log.Handler{}
	log.Targets["buffer"] = buffer

	logger := log.New("testing", log.MapContext{
		"A": 123,
	})

	entries := []entry{
		entry{
			log.LvlInfo,
			"Log Message 1",
		},
		entry{
			log.LvlDebug,
			"Log Message 2",
		},
	}

	buffer.Redirect()

	logger.Dispatch(entries[0].lvl, entries[0].msg)

	if len(buffer.Buffered()) != 1 {
		t.Error("Buffered length incorrect")
	}

	if len(mtarget.records) != 0 {
		t.Error("Handled length incorrect")
	}

	buffer.Flush()

	if buffer.Buffered() != nil {
		t.Error("Buffer not emptied")
	}

	if len(mtarget.records) != 1 {
		t.Error("Buffer not flushed")
	}

	logger.Dispatch(entries[1].lvl, entries[1].msg)

	if len(mtarget.records) != 2 {
		t.Error("Buffer not flushed")
	}

	records := mtarget.records

	for i, r := range records {
		if r.Level() != entries[i].lvl {
			t.Error("Log level mismatch")
		}

		if r.Tag() != "testing" {
			t.Error("Log tag mismatch")
		}

		if r.Message() != entries[i].msg {
			t.Error("Log message mismatch")
		}

		rctx := r.Context().ContextMap()
		if v, ok := rctx["A"]; !ok || v != 123 {
			t.Error("Log context mismatch")
		}
	}
}