trpc.group/trpc-go/trpc-go@v1.0.3/log/rollwriter/roll_writer_options.go (about) 1 // 2 // 3 // Tencent is pleased to support the open source community by making tRPC available. 4 // 5 // Copyright (C) 2023 THL A29 Limited, a Tencent company. 6 // All rights reserved. 7 // 8 // If you have downloaded a copy of the tRPC source code from Tencent, 9 // please note that tRPC source code is licensed under the Apache 2.0 License, 10 // A copy of the Apache 2.0 License is included in this file. 11 // 12 // 13 14 package rollwriter 15 16 // Options is the RollWriter call options. 17 type Options struct { 18 // MaxSize is max size by byte of the log file. 19 MaxSize int64 20 21 // MaxBackups is the max number of log files. 22 MaxBackups int 23 24 // MaxAge is the max expire time by day of log files. 25 MaxAge int 26 27 // whether the log file should be compressed. 28 Compress bool 29 30 // TimeFormat is the time format to split log file by time. 31 TimeFormat string 32 } 33 34 // Option modifies the Options. 35 type Option func(*Options) 36 37 // WithMaxSize returns an Option which sets the max size(MB) of log files. 38 func WithMaxSize(n int) Option { 39 return func(o *Options) { 40 o.MaxSize = int64(n) * 1024 * 1024 41 } 42 } 43 44 // WithMaxAge returns an Option which sets the max expire time(Day) of log files. 45 func WithMaxAge(n int) Option { 46 return func(o *Options) { 47 o.MaxAge = n 48 } 49 } 50 51 // WithMaxBackups returns an Option which sets the max number of backup log files. 52 func WithMaxBackups(n int) Option { 53 return func(o *Options) { 54 o.MaxBackups = n 55 } 56 } 57 58 // WithCompress returns an Option which sets whether log files should be compressed. 59 func WithCompress(b bool) Option { 60 return func(o *Options) { 61 o.Compress = b 62 } 63 } 64 65 // WithRotationTime returns an Option which sets the time format(%Y%m%d) to roll logs. 66 func WithRotationTime(s string) Option { 67 return func(o *Options) { 68 o.TimeFormat = s 69 } 70 }