github.com/tickoalcantara12/micro/v3@v3.0.0-20221007104245-9d75b9bcbab9/service/debug/log/options.go (about) 1 // Licensed under the Apache License, Version 2.0 (the "License"); 2 // you may not use this file except in compliance with the License. 3 // You may obtain a copy of the License at 4 // 5 // https://www.apache.org/licenses/LICENSE-2.0 6 // 7 // Unless required by applicable law or agreed to in writing, software 8 // distributed under the License is distributed on an "AS IS" BASIS, 9 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 10 // See the License for the specific language governing permissions and 11 // limitations under the License. 12 // 13 // Original source: github.com/micro/go-micro/v3/debug/log/options.go 14 15 package log 16 17 import "time" 18 19 // Option used by the logger 20 type Option func(*Options) 21 22 // Options are logger options 23 type Options struct { 24 // Name of the log 25 Name string 26 // Size is the size of ring buffer 27 Size int 28 // Format specifies the output format 29 Format FormatFunc 30 } 31 32 // Name of the log 33 func Name(n string) Option { 34 return func(o *Options) { 35 o.Name = n 36 } 37 } 38 39 // Size sets the size of the ring buffer 40 func Size(s int) Option { 41 return func(o *Options) { 42 o.Size = s 43 } 44 } 45 46 func Format(f FormatFunc) Option { 47 return func(o *Options) { 48 o.Format = f 49 } 50 } 51 52 // DefaultOptions returns default options 53 func DefaultOptions() Options { 54 return Options{ 55 Size: DefaultSize, 56 } 57 } 58 59 // ReadOptions for querying the logs 60 type ReadOptions struct { 61 // Since what time in past to return the logs 62 Since time.Time 63 // Count specifies number of logs to return 64 Count int 65 // Stream requests continuous log stream 66 Stream bool 67 } 68 69 // ReadOption used for reading the logs 70 type ReadOption func(*ReadOptions) 71 72 // Since sets the time since which to return the log records 73 func Since(s time.Time) ReadOption { 74 return func(o *ReadOptions) { 75 o.Since = s 76 } 77 } 78 79 // Count sets the number of log records to return 80 func Count(c int) ReadOption { 81 return func(o *ReadOptions) { 82 o.Count = c 83 } 84 }