1 // Copyright 2017 The Prometheus Authors 2 // Licensed under the Apache License, Version 2.0 (the "License"); 3 // you may not use this file except in compliance with the License. 4 // You may obtain a copy of the License at 5 // 6 // http://www.apache.org/licenses/LICENSE-2.0 7 // 8 // Unless required by applicable law or agreed to in writing, software 9 // distributed under the License is distributed on an "AS IS" BASIS, 10 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 11 // See the License for the specific language governing permissions and 12 // limitations under the License. 13 14 package flag 15 16 import ( 17 "strings" 18 19 kingpin "github.com/alecthomas/kingpin/v2" 20 21 "github.com/prometheus/common/promlog" 22 ) 23 24 // LevelFlagName is the canonical flag name to configure the allowed log level 25 // within Prometheus projects. 26 const LevelFlagName = "log.level" 27 28 // LevelFlagHelp is the help description for the log.level flag. 29 var LevelFlagHelp = "Only log messages with the given severity or above. One of: [" + strings.Join(promlog.LevelFlagOptions, ", ") + "]" 30 31 // FormatFlagName is the canonical flag name to configure the log format 32 // within Prometheus projects. 33 const FormatFlagName = "log.format" 34 35 // FormatFlagHelp is the help description for the log.format flag. 36 var FormatFlagHelp = "Output format of log messages. One of: [" + strings.Join(promlog.FormatFlagOptions, ", ") + "]" 37 38 // AddFlags adds the flags used by this package to the Kingpin application. 39 // To use the default Kingpin application, call AddFlags(kingpin.CommandLine) 40 func AddFlags(a *kingpin.Application, config *promlog.Config) { 41 config.Level = &promlog.AllowedLevel{} 42 a.Flag(LevelFlagName, LevelFlagHelp). 43 Default("info").HintOptions(promlog.LevelFlagOptions...). 44 SetValue(config.Level) 45 46 config.Format = &promlog.AllowedFormat{} 47 a.Flag(FormatFlagName, FormatFlagHelp). 48 Default("logfmt").HintOptions(promlog.FormatFlagOptions...). 49 SetValue(config.Format) 50 } 51