-
Notifications
You must be signed in to change notification settings - Fork 1
/
chunk_logger.go
43 lines (37 loc) · 1.06 KB
/
chunk_logger.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
package conveyor
import "strconv"
// The ChunkResultLogger type is the function that formats and logs
// the chunk result to Queue.Logger and QueueErrLogger.
type ChunkResultLogger func(queue *Queue, result ChunkResult, currentChunkNumber int)
// DefaultChunkResultLogger is the default logger used by Queue.
var DefaultChunkResultLogger = LogChunkResult
// LogChunkResult is the default ChunkResultLogger.
func LogChunkResult(queue *Queue, result ChunkResult, currentChunkNumber int) {
percent := float32(currentChunkNumber) / float32(queue.chunkCount) * 100
if result.Err == nil {
percentPadding := ""
if percent < 10 {
percentPadding = " "
}
if percent >= 10 && percent != 100 {
percentPadding = " "
}
queue.Logger.Printf(
"[%*d/%d] %s%.2f %% done. lines: %d\n",
len(strconv.Itoa(queue.chunkCount)),
result.Chunk.Id,
queue.chunkCount,
percentPadding,
percent,
result.Lines,
)
} else {
queue.ErrLogger.Printf(
"[%*d/%d] %s\n",
len(strconv.Itoa(queue.chunkCount)),
result.Chunk.Id,
queue.chunkCount,
result.Err,
)
}
}