gmlog

package module
v0.0.0-...-64dd082 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jul 4, 2016 License: MIT Imports: 11 Imported by: 1

README

Simple logging package for gomobile applications. It supports Print, Printf, Fatal and Fatalf methods.

go get github.com/viru/gmlog

Typical usage (simplified code to show the idea):

package main

import (
	"github.com/viru/gmlog"
	// other imports left out for readibility
)

func main() {
	app.Main(func(a app.App) {
		var glctx gl.Context
		var sz size.Event
		for e := range a.Events() {
			switch e := a.Filter(e).(type) {
			case lifecycle.Event:
				switch e.Crosses(lifecycle.StageVisible) {
				case lifecycle.CrossOn:
					onStart(glctx, sz) // Initialise logger here.
					a.Send(paint.Event{})
				case lifecycle.CrossOff:
					onStop() // Release logger here.
				}
			case size.Event:
				sz = e
			case paint.Event:
				onPaint(glctx, sz) // Make sure logger Draw func is called here.
				a.Publish()
				a.Send(paint.Event{})
			}
		}
	})
}

var (
	images    *glutil.Images
	eng       sprite.Engine
	log       *gmlog.Logger // Global log handler.
)

func onStart(glctx gl.Context, sz size.Event) {
	images = glutil.NewImages(glctx)
	eng = glsprite.Engine(images)
	log = gmlog.New(images, 5)) // Pass your images to logger along with lines limit.
	log.Print("Initialised app") // Now you can print to your logs.
}

func onStop() {
	eng.Release()
	log.Release() // Release logger before releasing images.
	images.Release()
}

func onPaint(glctx gl.Context, sz size.Event) {
	glctx.ClearColor(0, 0, 0, 1)
	glctx.Clear(gl.COLOR_BUFFER_BIT)
	eng.Render(scene, now, sz)
	log.Draw(sz) // Call Draw to display the logs.
}

Logs are added on top of the screen (not configurable at the moment):

screenshot

Documentation

Overview

Package gmlog implements a simple logging package. It defines a type, Logger, with methods for formatting output. It is anologous to standard library's log package, but prints lines of logs on gomobile application.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Logger

type Logger struct {
	// contains filtered or unexported fields
}

A Logger represents an active logging object that generates lines of output to glutil Images (useful in gomobile applications).

func New

func New(images *glutil.Images, limit int) *Logger

New creates a Logger tied to the current GL images. Limit limits amount of lines to be displayed.

func (*Logger) Draw

func (l *Logger) Draw(sz size.Event)

Draw draws all current logs at the top of the screen.

func (*Logger) Fatal

func (l *Logger) Fatal(v ...interface{})

Fatal is equivalent to l.Print() followed by a call to os.Exit(1).

func (*Logger) Fatalf

func (l *Logger) Fatalf(format string, v ...interface{})

Fatalf is equivalent to l.Printf() followed by a call to os.Exit(1).

func (*Logger) Output

func (l *Logger) Output(msg string)

Output adds formatted message to the buffer.

func (*Logger) Print

func (l *Logger) Print(v ...interface{})

Print adds new message to logger buffer.

func (*Logger) Printf

func (l *Logger) Printf(format string, v ...interface{})

Printf adds new message format and optional arguments to logger buffer.

func (*Logger) Release

func (l *Logger) Release()

Release releases image resources.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL