Add option to toggle date/time in log messages
This commit is contained in:
parent
f7b7b63e3f
commit
91508c50b5
5 changed files with 49 additions and 1 deletions
|
@ -78,6 +78,10 @@ func Parse() {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if config.Opts.LogDateTime() {
|
||||||
|
logger.EnableDateTime()
|
||||||
|
}
|
||||||
|
|
||||||
if flagDebugMode || config.Opts.HasDebugMode() {
|
if flagDebugMode || config.Opts.HasDebugMode() {
|
||||||
logger.EnableDebug()
|
logger.EnableDebug()
|
||||||
}
|
}
|
||||||
|
|
|
@ -11,6 +11,7 @@ import (
|
||||||
|
|
||||||
const (
|
const (
|
||||||
defaultHTTPS = false
|
defaultHTTPS = false
|
||||||
|
defaultLogDateTime = false
|
||||||
defaultHSTS = true
|
defaultHSTS = true
|
||||||
defaultHTTPService = true
|
defaultHTTPService = true
|
||||||
defaultSchedulerService = true
|
defaultSchedulerService = true
|
||||||
|
@ -47,6 +48,7 @@ const (
|
||||||
// Options contains configuration options.
|
// Options contains configuration options.
|
||||||
type Options struct {
|
type Options struct {
|
||||||
HTTPS bool
|
HTTPS bool
|
||||||
|
logDateTime bool
|
||||||
hsts bool
|
hsts bool
|
||||||
httpService bool
|
httpService bool
|
||||||
schedulerService bool
|
schedulerService bool
|
||||||
|
@ -84,6 +86,7 @@ type Options struct {
|
||||||
func NewOptions() *Options {
|
func NewOptions() *Options {
|
||||||
return &Options{
|
return &Options{
|
||||||
HTTPS: defaultHTTPS,
|
HTTPS: defaultHTTPS,
|
||||||
|
logDateTime: defaultLogDateTime,
|
||||||
hsts: defaultHSTS,
|
hsts: defaultHSTS,
|
||||||
httpService: defaultHTTPService,
|
httpService: defaultHTTPService,
|
||||||
schedulerService: defaultSchedulerService,
|
schedulerService: defaultSchedulerService,
|
||||||
|
@ -118,6 +121,11 @@ func NewOptions() *Options {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// LogDateTime returns true if the date/time should be displayed in log messages.
|
||||||
|
func (o *Options) LogDateTime() bool {
|
||||||
|
return o.logDateTime
|
||||||
|
}
|
||||||
|
|
||||||
// HasDebugMode returns true if debug mode is enabled.
|
// HasDebugMode returns true if debug mode is enabled.
|
||||||
func (o *Options) HasDebugMode() bool {
|
func (o *Options) HasDebugMode() bool {
|
||||||
return o.debug
|
return o.debug
|
||||||
|
@ -283,6 +291,7 @@ func (o *Options) HTTPClientMaxBodySize() int64 {
|
||||||
|
|
||||||
func (o *Options) String() string {
|
func (o *Options) String() string {
|
||||||
var builder strings.Builder
|
var builder strings.Builder
|
||||||
|
builder.WriteString(fmt.Sprintf("LOG_DATE_TIME: %v\n", o.logDateTime))
|
||||||
builder.WriteString(fmt.Sprintf("DEBUG: %v\n", o.debug))
|
builder.WriteString(fmt.Sprintf("DEBUG: %v\n", o.debug))
|
||||||
builder.WriteString(fmt.Sprintf("HTTP_SERVICE: %v\n", o.httpService))
|
builder.WriteString(fmt.Sprintf("HTTP_SERVICE: %v\n", o.httpService))
|
||||||
builder.WriteString(fmt.Sprintf("SCHEDULER_SERVICE: %v\n", o.schedulerService))
|
builder.WriteString(fmt.Sprintf("SCHEDULER_SERVICE: %v\n", o.schedulerService))
|
||||||
|
|
|
@ -71,6 +71,8 @@ func (p *Parser) parseLines(lines []string) (err error) {
|
||||||
value := strings.TrimSpace(fields[1])
|
value := strings.TrimSpace(fields[1])
|
||||||
|
|
||||||
switch key {
|
switch key {
|
||||||
|
case "LOG_DATE_TIME":
|
||||||
|
p.opts.logDateTime = parseBool(value, defaultLogDateTime)
|
||||||
case "DEBUG":
|
case "DEBUG":
|
||||||
p.opts.debug = parseBool(value, defaultDebug)
|
p.opts.debug = parseBool(value, defaultDebug)
|
||||||
case "BASE_URL":
|
case "BASE_URL":
|
||||||
|
|
|
@ -7,9 +7,11 @@ package logger // import "miniflux.app/logger"
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"os"
|
"os"
|
||||||
|
"time"
|
||||||
)
|
)
|
||||||
|
|
||||||
var requestedLevel = InfoLevel
|
var requestedLevel = InfoLevel
|
||||||
|
var displayDateTime = false
|
||||||
|
|
||||||
// LogLevel type.
|
// LogLevel type.
|
||||||
type LogLevel uint32
|
type LogLevel uint32
|
||||||
|
@ -43,6 +45,11 @@ func (level LogLevel) String() string {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// EnableDateTime enables date time in log messages.
|
||||||
|
func EnableDateTime() {
|
||||||
|
displayDateTime = true
|
||||||
|
}
|
||||||
|
|
||||||
// EnableDebug increases logging, more verbose (debug)
|
// EnableDebug increases logging, more verbose (debug)
|
||||||
func EnableDebug() {
|
func EnableDebug() {
|
||||||
requestedLevel = DebugLevel
|
requestedLevel = DebugLevel
|
||||||
|
@ -79,6 +86,13 @@ func Fatal(format string, v ...interface{}) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func formatMessage(level LogLevel, format string, v ...interface{}) {
|
func formatMessage(level LogLevel, format string, v ...interface{}) {
|
||||||
prefix := fmt.Sprintf("[%s] ", level.String())
|
var prefix string
|
||||||
|
|
||||||
|
if displayDateTime {
|
||||||
|
prefix = fmt.Sprintf("[%s] [%s] ", time.Now().Format("2006-01-02T15:04:05"), level)
|
||||||
|
} else {
|
||||||
|
prefix = fmt.Sprintf("[%s] ", level)
|
||||||
|
}
|
||||||
|
|
||||||
fmt.Fprintf(os.Stderr, prefix+format+"\n", v...)
|
fmt.Fprintf(os.Stderr, prefix+format+"\n", v...)
|
||||||
}
|
}
|
||||||
|
|
19
miniflux.1
19
miniflux.1
|
@ -78,11 +78,30 @@ Show application version\&.
|
||||||
Show application version\&.
|
Show application version\&.
|
||||||
.RE
|
.RE
|
||||||
|
|
||||||
|
.SH CONFIGURATION FILE
|
||||||
|
The configuration file is a text file that follow these rules:
|
||||||
|
.LP
|
||||||
|
- Miniflux expects each line to be in KEY=VALUE format.
|
||||||
|
.br
|
||||||
|
- Lines beginning with # are processed as comments and ignored.
|
||||||
|
.br
|
||||||
|
- Blank lines are ignored.
|
||||||
|
.br
|
||||||
|
- There is no variable interpolation.
|
||||||
|
.PP
|
||||||
|
Keys are the same as the environment variables described below.
|
||||||
|
.br
|
||||||
|
Environment variables override the values defined in the config file.
|
||||||
|
|
||||||
.SH ENVIRONMENT
|
.SH ENVIRONMENT
|
||||||
.TP
|
.TP
|
||||||
.B DEBUG
|
.B DEBUG
|
||||||
Set the value to 1 to enable debug logs\&.
|
Set the value to 1 to enable debug logs\&.
|
||||||
.TP
|
.TP
|
||||||
|
.TP
|
||||||
|
.B LOG_DATE_TIME
|
||||||
|
Display the date and time in log messages\&.
|
||||||
|
.TP
|
||||||
.B WORKER_POOL_SIZE
|
.B WORKER_POOL_SIZE
|
||||||
Number of background workers (default is 5)\&.
|
Number of background workers (default is 5)\&.
|
||||||
.TP
|
.TP
|
||||||
|
|
Loading…
Reference in a new issue