trpc.group/trpc-go/trpc-go@v1.0.3/log/rollwriter/async_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 // AsyncOptions is the call options of AsyncRollWriter. 17 type AsyncOptions struct { 18 // LogQueueSize is the queue size of asynchronous log. 19 LogQueueSize int 20 21 // WriteLogSize is the threshold to write async log. 22 WriteLogSize int 23 24 // WriteLogInterval is the time interval to write async log. 25 WriteLogInterval int 26 27 // DropLog determines whether to discard logs when log queue is full. 28 DropLog bool 29 } 30 31 // AsyncOption modifies the AsyncOptions. 32 type AsyncOption func(*AsyncOptions) 33 34 // WithLogQueueSize returns an AsyncOption which sets log queue size. 35 func WithLogQueueSize(n int) AsyncOption { 36 return func(o *AsyncOptions) { 37 o.LogQueueSize = n 38 } 39 } 40 41 // WithWriteLogSize returns an AsyncOption which sets log size(Byte) threshold. 42 func WithWriteLogSize(n int) AsyncOption { 43 return func(o *AsyncOptions) { 44 o.WriteLogSize = n 45 } 46 } 47 48 // WithWriteLogInterval returns an AsyncOption which sets log interval(ms) threshold(ms). 49 func WithWriteLogInterval(n int) AsyncOption { 50 return func(o *AsyncOptions) { 51 o.WriteLogInterval = n 52 } 53 } 54 55 // WithDropLog returns an AsyncOption which set whether to drop logs on log queue full. 56 func WithDropLog(b bool) AsyncOption { 57 return func(o *AsyncOptions) { 58 o.DropLog = b 59 } 60 }