mirror of
https://github.com/tailscale/tailscale.git
synced 2025-01-09 09:33:42 +00:00
0d19f5d421
The log ID types were moved to a separate package so that code that only depend on log ID types do not need to link in the logic for the logtail client itself. Not all code need the logtail client. Signed-off-by: Joe Tsai <joetsai@digital-static.net>
47 lines
936 B
Go
47 lines
936 B
Go
// Copyright (c) Tailscale Inc & AUTHORS
|
|
// SPDX-License-Identifier: BSD-3-Clause
|
|
|
|
// The logtail program logs stdin.
|
|
package main
|
|
|
|
import (
|
|
"bufio"
|
|
"flag"
|
|
"io"
|
|
"log"
|
|
"os"
|
|
|
|
"tailscale.com/logtail"
|
|
"tailscale.com/types/logid"
|
|
)
|
|
|
|
func main() {
|
|
collection := flag.String("c", "", "logtail collection name")
|
|
privateID := flag.String("k", "", "machine private identifier, 32-bytes in hex")
|
|
flag.Parse()
|
|
if len(flag.Args()) != 0 {
|
|
flag.Usage()
|
|
os.Exit(1)
|
|
}
|
|
|
|
log.SetFlags(0)
|
|
|
|
var id logid.PrivateID
|
|
if err := id.UnmarshalText([]byte(*privateID)); err != nil {
|
|
log.Fatalf("logtail: bad -privateid: %v", err)
|
|
}
|
|
|
|
logger := logtail.NewLogger(logtail.Config{
|
|
Collection: *collection,
|
|
PrivateID: id,
|
|
}, log.Printf)
|
|
log.SetOutput(io.MultiWriter(logger, os.Stdout))
|
|
defer logger.Flush()
|
|
defer log.Printf("logtail exited")
|
|
|
|
scanner := bufio.NewScanner(os.Stdin)
|
|
for scanner.Scan() {
|
|
log.Println(scanner.Text())
|
|
}
|
|
}
|