func TestStdoutLogging(t *testing.T) {
	settings := logger.Settings{
		Output: logger.Stdout{
			Level: "panic",
		},
	}

	log, err := logger.New(settings)
	if err != nil {
		t.Fatal("Error", err)
	}

	log.Context(logger.Fields{"foo": "bar1"}).Debug("Debug")
}
func TestDiskLogging(t *testing.T) {
	settings := logger.Settings{
		Output: logger.Disk{
			Path:  "output.log",
			Level: "panic",
		},
	}

	log, err := logger.New(settings)
	if err != nil {
		t.Fatal("Error", err)
	}

	log.Context(logger.Fields{"foo": "bar3"}).Debug("Debug")
}
func TestLogglyLogging(t *testing.T) {
	settings := logger.Settings{
		Output: logger.LogglySettings{
			Domain: "web-rat.com",
			Token:  "gibberish",
			Level:  "panic",
			Tags:   []string{"version-1", "stuff", "more-stuff"},
		},
	}

	log, err := logger.New(settings)
	if err != nil {
		t.Fatal("Error", err)
	}
	log.Context(logger.Fields{"foo": "bar4"}).Debug("Debug")
}
Exemple #4
0
func main() {
	log := logger.New(false, true)
	ws := webserver.New(log)

	// You can serve static files. It is quite easy.
	ws.FILES("/public", "static")

	// We can pass the HandlerDefs we've created in this application specific
	// Handler to the Webserver and it will now read the HandlerDef(s) and
	// register those HandlerFunc(s) with the webserver
	ws.RegisterHandlerDefs(api.Endpoints)

	// We can also register a HandlerFunc manualy without all that HandlerDef fuss.
	ws.GET("/", func(ctx *context.Context) {
		ctx.HTML("Winter is coming--but, it's not here yet.")
	})

	// Once the webserver is configured you will want to listen for clients
	ws.Start(":8888")
}
Exemple #5
0
// AppWebInterface represents a application specific structure. You may want to add
// fields for loggers, repos, interactors, or other things to enhance your
// handler.
type AppWebInterface struct {
	Endpoints []webserver.HandlerDef
	logger    logger.Logger
}

// *****************************************************************************
// HANDLER SAMPLE
// *****************************************************************************

// We'll demo the webserver using an API for kicks and grins.
var api = &AppWebInterface{
	Endpoints: []webserver.HandlerDef{},
	logger:    logger.New(false, true),
}

func init() {
	// A simple example of how to register one handler using our HandlerDef system
	// to auto-document this API endpoint
	api.Endpoints = append(api.Endpoints, webserver.HandlerDef{
		Alias:               "ExampleGet",
		Method:              "GET",
		Path:                "/api/sample",
		Documentation:       "/some/path/to/documentation.html",
		DurationExpectation: "1ms",
		Handler: func(ctx *context.Context) {
			ctx.HTML("Listing stuff")
		},
	})