@@ -37,28 +37,26 @@ func (handler *AgentAPI) getElasticLogFiles(w http.ResponseWriter, req *http.Req
37
37
}
38
38
var files []util.MapStr
39
39
for _ , info := range fileInfos {
40
- if strings .HasSuffix (info .Name (), ".log" ) || strings .HasSuffix (info .Name (), ".json" ) {
41
- if info .IsDir () {
42
- continue
43
- }
44
- fInfo , err := info .Info ()
45
- if err != nil {
46
- log .Error (err )
47
- continue
48
- }
49
- filePath := path .Join (reqBody .LogsPath , info .Name ())
50
- totalRows , err := util2 .CountFileRows (filePath )
51
- if err != nil {
52
- log .Error (err )
53
- continue
54
- }
55
- files = append (files , util.MapStr {
56
- "name" : fInfo .Name (),
57
- "size_in_bytes" : fInfo .Size (),
58
- "modify_time" : fInfo .ModTime (),
59
- "total_rows" : totalRows ,
60
- })
40
+ if info .IsDir () {
41
+ continue
42
+ }
43
+ fInfo , err := info .Info ()
44
+ if err != nil {
45
+ log .Error (err )
46
+ continue
47
+ }
48
+ filePath := path .Join (reqBody .LogsPath , info .Name ())
49
+ totalRows , err := util2 .CountFileRows (filePath )
50
+ if err != nil {
51
+ log .Error (err )
52
+ continue
61
53
}
54
+ files = append (files , util.MapStr {
55
+ "name" : fInfo .Name (),
56
+ "size_in_bytes" : fInfo .Size (),
57
+ "modify_time" : fInfo .ModTime (),
58
+ "total_rows" : totalRows ,
59
+ })
62
60
}
63
61
64
62
handler .WriteJSON (w , util.MapStr {
@@ -80,6 +78,28 @@ func (handler *AgentAPI) readElasticLogFile(w http.ResponseWriter, req *http.Req
80
78
if reqBody .StartLineNumber < 0 {
81
79
reqBody .StartLineNumber = 0
82
80
}
81
+ if strings .HasSuffix (reqBody .FileName , ".gz" ) {
82
+ // read gzip log file, and then unpack it to tmp file
83
+ tmpFilePath := filepath .Join (os .TempDir (), "agent" , strings .TrimSuffix (reqBody .FileName , ".gz" ))
84
+ if ! util .FileExists (tmpFilePath ) {
85
+ fileDir := filepath .Dir (tmpFilePath )
86
+ if ! util .FileExists (fileDir ) {
87
+ err = os .MkdirAll (fileDir , os .ModePerm )
88
+ if err != nil {
89
+ log .Error (err )
90
+ handler .WriteJSON (w , err .Error (), http .StatusInternalServerError )
91
+ return
92
+ }
93
+ }
94
+ err = util2 .UnpackGzipFile (logFilePath , tmpFilePath )
95
+ if err != nil {
96
+ log .Error (err )
97
+ handler .WriteJSON (w , err .Error (), http .StatusInternalServerError )
98
+ return
99
+ }
100
+ }
101
+ logFilePath = tmpFilePath
102
+ }
83
103
r , err := linenumber .NewLinePlainTextReader (logFilePath , reqBody .StartLineNumber , io .SeekStart )
84
104
if err != nil {
85
105
log .Error (err )
0 commit comments