Exemple #1
0
// handleFunc is the main function of the web server dispatching the
// requests to registered resource handler.
func handleFunc(rw http.ResponseWriter, r *http.Request) {
	ctx := newContext(rw, r)
	resources := srv.domains[ctx.Domain]
	if resources != nil {
		handlers := resources[ctx.Resource]
		if handlers != nil {
			m := monitoring.BeginMeasuring(identifier.Identifier("web", ctx.Domain, ctx.Resource, ctx.Request.Method))
			for _, h := range handlers {
				if !dispatch(ctx, h) {
					break
				}
			}
			m.EndMeasuring()
			return
		}
	}
	// No valid configuration, redirect to default (if not already).
	if ctx.Domain == srv.defaultDomain && ctx.Resource == srv.defaultResource {
		// No default handler registered.
		msg := fmt.Sprintf("domain '%v' and resource '%v' not found!", ctx.Domain, ctx.Resource)
		applog.Errorf(msg)
		http.Error(ctx.ResponseWriter, msg, http.StatusNotFound)
	} else {
		// Redirect to default handler.
		applog.Warningf("domain '%v' and resource '%v' not found, redirecting to default", ctx.Domain, ctx.Resource)
		ctx.Redirect(srv.defaultDomain, srv.defaultResource, "")
	}
}
Exemple #2
0
// Test logging from level warning and above.
func TestWarningAndAbove(t *testing.T) {
	applog.SetLevel(applog.LevelWarning)

	applog.Debugf("Debug.")
	applog.Infof("Info.")
	applog.Warningf("Warning.")
	applog.Errorf("Error.")
	applog.Criticalf("Critical.")
}
Exemple #3
0
// Test log at all levels.
func TestAllLevels(t *testing.T) {
	applog.SetLevel(applog.LevelDebug)

	applog.Debugf("Debug.")
	applog.Infof("Info.")
	applog.Warningf("Warning.")
	applog.Errorf("Error.")
	applog.Criticalf("Critical.")
}
Exemple #4
0
// Test logging with the go logger.
func TestGoLogger(t *testing.T) {
	log.SetOutput(os.Stdout)

	applog.SetLevel(applog.LevelDebug)
	applog.SetLogger(applog.GoLogger{})

	applog.Debugf("Debug.")
	applog.Infof("Info.")
	applog.Warningf("Warning.")
	applog.Errorf("Error.")
	applog.Criticalf("Critical.")
}
Exemple #5
0
// Test logging with an own logger.
func TestOwnLogger(t *testing.T) {
	assert := asserts.NewTestingAsserts(t, true)
	ownLogger := &testLogger{[]string{}}

	applog.SetLevel(applog.LevelDebug)
	applog.SetLogger(ownLogger)

	applog.Debugf("Debug.")
	applog.Infof("Info.")
	applog.Warningf("Warning.")
	applog.Errorf("Error.")
	applog.Criticalf("Critical.")

	assert.Length(ownLogger.logs, 5, "Everything logged.")
}