Giter Club home page Giter Club logo

gologtail's Introduction

GoLogTail

Parse files with different log formats and insert in MongoDB.

Usage

$ ./gologtail --help
usage: gologtail [<flags>]

Flags:
      --help                   Show context-sensitive help (also try --help-long and --help-man).
      --dbh="localhost:27017"  MongoDB host
      --dbn="logs"             MongoDB database name
      --dbt="logs"             MongoDB table name
      --dbw=10                 Workers for add item to MongoDB
  -f, --format=1               Time format for log files
                               Values:
                                     1 = "Jan 2, 2006 at 3:04:05pm (UTC)"
                                     2 = "2006-01-02T15:04:05Z"

Run

$ ./gologtail 

with flags

$ echo -e '/logs/test0.log\n/logs/test1.log' ./gologtail --dbh localhost:27017 --dbn logs --dbt logs --dbw 10 -f 1

Testing

$ docker-compose up

Example

package main

import (
	"log"
	"os"
	"os/signal"
	"sync"

	"github.com/tusupov/gologtail/db"
	"github.com/tusupov/gologtail/tail"
)

func main() {

	logFilePath := "/etc/passwd"
	timeFormat := 1

	// Create new
	t, err := tail.New(logFilePath, timeFormat)
	if err != nil {
		log.Fatal(err)
	}

	wg := &sync.WaitGroup{}
	lineItemCh := make(chan db.Item)

	wg.Add(1)

	// Enable debug and listen file
	t.Debug(true)
	go t.Run(wg, lineItemCh)

	sigChan := make(chan os.Signal, 1)
	signal.Notify(sigChan, os.Interrupt)

	// Get lines
	go func() {
		for {
			select {
			case lineItem := <-lineItemCh:
				log.Println(lineItem)

			case <-sigChan:
				t.Stop()
				return

			}
		}
	}()

	wg.Wait()
	close(sigChan)
	close(lineItemCh)

}

gologtail's People

Contributors

tusupov avatar

Watchers

James Cloos avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.