https://github.com/vogo/logtail
logtail is a log tailing utility, support tailing multiple commands output stream, transferring matching content to file/webhook(like dingtalk)
https://github.com/vogo/logtail
golang log tail websocket
Last synced: 4 months ago
JSON representation
logtail is a log tailing utility, support tailing multiple commands output stream, transferring matching content to file/webhook(like dingtalk)
- Host: GitHub
- URL: https://github.com/vogo/logtail
- Owner: vogo
- License: apache-2.0
- Created: 2020-11-24T13:27:14.000Z (over 5 years ago)
- Default Branch: master
- Last Pushed: 2023-07-14T15:04:27.000Z (almost 3 years ago)
- Last Synced: 2024-11-05T09:44:30.583Z (over 1 year ago)
- Topics: golang, log, tail, websocket
- Language: Go
- Homepage: http://github.com/vogo/logtail
- Size: 535 KB
- Stars: 36
- Watchers: 7
- Forks: 12
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# logtail is a log tailing utility.
[](https://codecov.io/gh/vogo/logtail)
[](https://godoc.org/github.com/vogo/logtail)

## 1. Features
- tailing command output
- support watch files under directory/sub-directories
- support (dynamically) multiple commands tailing
- support websocket tailing
- support log matching filter
- support transfer log to console/file/webhook (include dingtalk)
## 2. Architecture

## 3. Usage
## 3.2. install logtail
`go install github.com/vogo/logtail@master`
### 3.2. StartLoop logtail server using config file
```bash
logtail -file
```
config file [examples](examples/README.md).
### 3.3. StartLoop logtail server and config using webapi
usage: `logtail -port=`
```bash
# start at port 54321
logtail -port=54321
```
Then config using [web api](webapi/README.md) from web page `http://:/manage`.
And you can browse `http://:` to list all tailing logs.
## 4. log format
You can config log format globally, or config it for a server.
The config `prefix` of the format is the wildcard of the prefix of a new log record,
`logtail` will check whether a new line is the StartLoop of a new log record, or one of the following lines.
The wildcard does NOT support '*' for none or many chars, it supports the following tag:
- '?' as one byte char;
- '~' as one alphabet char;
- '!' as one number char;
- other chars must exact match.
example:
```bash
{
"default_format":{
"prefix": "!!!!-!!-!!" # global format config, Matches 2020-12-12
},
"servers": [
{
"name": "app1",
"command": "tail -f /logs/app/app1.log",
"format":{
"prefix": "!!!!-!!-!!" # server format config, Matches 2020-12-12
}
}
]
}
```
## 4. command examples
The following are some useful commands which can be used in logtail.
```bash
# tail log file
tail -f /usr/local/myapp/myapp.log
# k8s: find and tail logs for the single pod of myapp
kubectl logs --tail 10 -f $(kubectl get pods --selector=app=myapp -o jsonpath='{.items[*].metadata.name}')
# k8s: find and tail logs for the myapp deployment (multiple pods)
kubectl logs --tail 10 -f deployment/$(kubectl get deployments --selector=project-name=myapp -o jsonpath='{.items[*].metadata.name}')
# k8s: find and tail logs for the latest version of the myapp deployment (single pod)
s=$(kubectl get deployments --selector=project-name=myapp -o jsonpath='{.items[*].metadata.name}');s=${s##* };kubectl logs --tail 10 -f deployment/$s
# k8s: find and tail logs for the latest version of the myapp deployment (multiple pods)
app=$(kubectl get deployments --selector=project-name=myapp -o jsonpath='{.items[*].metadata.name}');app=${app##* };pods=$(kubectl get pods --selector=app=$app -o jsonpath='{.items[*].metadata.name}');cmd='';for pod in $pods; do cmd=$cmd'kubectl logs --tail 2 -f pod/'$pod$'\n'; done;cmd=${cmd::-1}; echo "$cmd"
```