mysqllog

package module
v0.3.0 Latest Latest
Warning

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

Go to latest
Published: Jul 17, 2018 License: MIT Imports: 4 Imported by: 6

README

mysqllog GoDoc CircleCI

This package provides a simple MySQL slow query log parser.

Example: Parse a log from stdin and print events as JSON

package main

import (
	"bufio"
	"encoding/json"
	"fmt"
	"os"

	"github.com/Preetam/mysqllog"
)

func main() {
	p := &mysqllog.Parser{}
	reader := bufio.NewReader(os.Stdin)
	for line, err := reader.ReadString('\n'); err == nil; line, err = reader.ReadString('\n') {
		event := p.ConsumeLine(line)
		if event != nil {
			b, _ := json.Marshal(event)
			fmt.Printf("%s\n", b)
		}
	}
}

License

MIT (see LICENSE)

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type LogEvent

type LogEvent map[string]interface{}

LogEvent represents a slow query log event. "User", "Host", "Timestamp" (from SET timestamp as a time.Time), and "Statement" all should usually be present. Other attributes are set if found. Numbers are float64 or int64. Values of "Yes" or "No" are converted to bools.

type Parser

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

Parser is a MySQL slow query log format parser.

func (*Parser) ConsumeLine

func (p *Parser) ConsumeLine(line string) LogEvent

ConsumeLine consumes a line and returns a LogEvent if the parser recognizes a completed event.

func (*Parser) Flush

func (p *Parser) Flush() LogEvent

Flush processes any pending lines and returns a LogEvent if one is complete.

Directories

Path Synopsis
cmd

Jump to

Keyboard shortcuts

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