说明: 我这里是centos7.9的系统,经测试发现 flog 0.4.4 需要更高版本的glibc环境。因此我下面用的是低版本的flog 0.4.3。
> wget https://github.com/mingrammer/flog/releases/download/v0.4.3/flog_0.4.3_linux_amd64.tar.gz
> tar xf flog_0.4.3_linux_amd64.tar.gz
> ./flog -h
flog is a fake log generator for common log formats
Usage: flog [options]
Version: 0.4.3
Options:
-f, --format string log format. available formats:
- apache_common (default)
- apache_combined
- apache_error
- rfc3164
- rfc5424
- json
-o, --output string output filename. Path-like is allowed. (default "generated.log")
-t, --type string log output type. available types:
- stdout (default)
- log
- gz
-n, --number integer number of lines to generate.
-b, --bytes integer size of logs to generate (in bytes).
"bytes" will be ignored when "number" is set.
-s, --sleep duration fix creation time interval for each log (default unit "seconds"). It does not actually sleep.
examples: 10, 20ms, 5s, 1m
-d, --delay duration delay log generation speed (default unit "seconds").
examples: 10, 20ms, 5s, 1m
-p, --split-by integer set the maximum number of lines or maximum size in bytes of a log file.
with "number" option, the logs will be split whenever the maximum number of lines is reached.
with "byte" option, the logs will be split whenever the maximum size in bytes is reached.
-w, --overwrite overwrite the existing log files.
-l, --loop loop output forever until killed.
最常用的就是生成json格式的log,我这里是生成10w行的日志,每1w行分一个文件存储。
> ./flog -f json -o test.log -t log -n 100000 -w -p 10000
> ls -lhrt
-rw-r--r-- 1 root root 2.7M 2025-05-24 18:35 test.log
-rw-r--r-- 1 root root 2.7M 2025-05-24 18:35 test1.log
-rw-r--r-- 1 root root 2.7M 2025-05-24 18:35 test2.log
-rw-r--r-- 1 root root 2.7M 2025-05-24 18:35 test3.log
-rw-r--r-- 1 root root 2.7M 2025-05-24 18:35 test4.log
-rw-r--r-- 1 root root 2.7M 2025-05-24 18:35 test5.log
-rw-r--r-- 1 root root 2.7M 2025-05-24 18:35 test6.log
-rw-r--r-- 1 root root 2.7M 2025-05-24 18:35 test7.log
-rw-r--r-- 1 root root 2.7M 2025-05-24 18:35 test8.log
-rw-r--r-- 1 root root 2.7M 2025-05-24 18:35 test9.log
> head -3 test1.log 可以看到日志有点像nginx的access_log
{"host":"47.24.93.98", "user-identifier":"-", "datetime":"24/May/2025:18:35:15 +0800", "method": "PATCH", "request": "/empower/action-items/revolutionary/engineer", "protocol":"HTTP/1.0", "status":203, "bytes":18386, "referer": "http://www.productapplications.com/e-business/enhance"}
{"host":"46.109.206.239", "user-identifier":"schimmel6115", "datetime":"24/May/2025:18:35:15 +0800", "method": "HEAD", "request": "/virtual", "protocol":"HTTP/1.1", "status":400, "bytes":20172, "referer": "http://www.directworld-class.com/scale/unleash/frictionless"}
{"host":"54.184.59.83", "user-identifier":"walter6763", "datetime":"24/May/2025:18:35:15 +0800", "method": "PUT", "request": "/visualize/utilize/vortals/incubate", "protocol":"HTTP/1.1", "status":504, "bytes":18143, "referer": "https://www.internalcultivate.org/transition/content"}
如果要不断生成日志,直到按ctrl+c才停止,可以使用下面的命令写法
> ./flog -o test.log -t log -w -f json --loop
原创声明:本文系作者授权腾讯云开发者社区发表,未经许可,不得转载。
如有侵权,请联系 cloudcommunity@tencent.com 删除。
原创声明:本文系作者授权腾讯云开发者社区发表,未经许可,不得转载。
如有侵权,请联系 cloudcommunity@tencent.com 删除。