Skip to content

xellio/logger

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

13 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

logger

Like tail -F /log/this/file

go report card Build Status MIT license GoDoc

Usage:

package main

import (
    "fmt"
    "log"
    "os"
    "path/filepath"

    "github.com/xellio/logger"
)

var logFiles []string

func init() {
    for _, file := range os.Args[1:] {
        file = filepath.Clean(file)
        logFiles = append(logFiles, file)
    }
}

func main() {

    if len(logFiles) <= 0 {
        fmt.Println(`Usage:
    logger /path/to/logfile /path/to/another/logfile`)
        os.Exit(1)
    }

    resCh := make(chan *logger.Change)
    errCh := make(chan error)
    go func() {
        err := logger.Start(resCh, logFiles...)
        if err != nil {
            errCh <- err
        }
    }()

    for {
        select {
        case change := <-resCh:
            for _, line := range change.Lines {
                fmt.Println(string(line.Content))
            }

        case err := <-errCh:
            log.Fatalf("Error: %s", err.Error())
            os.Exit(1)
        }
    }

}

About

log files using go

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published