Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add logger.console_time_format option #130

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 6 additions & 5 deletions internal/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -133,11 +133,12 @@ func loadCustomConfig(path string) {
func processOpts() {
// string options and their exported variables
stringOpt := map[string]*string{
"http.bind_addr": &HTTPBind,
"http.bind_port": &HTTPPort,
"http.real_ip_header": &HeaderName,
"logger.directory": &logDir,
"deception.server_name": &FakeServerName,
"http.bind_addr": &HTTPBind,
"http.bind_port": &HTTPPort,
"http.real_ip_header": &HeaderName,
"logger.directory": &logDir,
"logger.console_time_format": &ConsoleTimeFormat,
"deception.server_name": &FakeServerName,
}
// string slice options and their exported variables
strSliceOpt := map[string]*[]string{
Expand Down
12 changes: 7 additions & 5 deletions internal/config/defaults.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
"os"
"path"
"runtime"
"time"

"github.com/spf13/afero"
)
Expand All @@ -29,11 +30,12 @@ var (

var defOpts = map[string]map[string]interface{}{
"logger": {
"debug": true,
"trace": false,
"nocolor": defNoColor,
"use_date_filename": true,
"docker_logging": false,
"debug": true,
"trace": false,
"nocolor": defNoColor,
"use_date_filename": true,
"docker_logging": false,
"console_time_format": time.Kitchen,
},
"http": {
"use_unix_socket": false,
Expand Down
6 changes: 5 additions & 1 deletion internal/config/globals.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package config

import "runtime/debug"
import (
"runtime/debug"
)

// Title is the name of the application used throughout the configuration process.
const Title = "HellPot"
Expand Down Expand Up @@ -39,6 +41,8 @@ var (
// CatchAll when true will cause HellPot to respond to all paths.
// Note that this will override MakeRobots.
CatchAll bool
// ConsoleTimeFormat sets the time format for the console. The string is passed to time.Format() down the line.
ConsoleTimeFormat string
)

// "http"
Expand Down
2 changes: 1 addition & 1 deletion internal/config/logger.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ func StartLogger(pretty bool, targets ...io.Writer) zerolog.Logger {
var logWriter = logFile

if pretty {
logWriter = zerolog.MultiLevelWriter(zerolog.ConsoleWriter{NoColor: NoColor, Out: os.Stdout}, logFile)
logWriter = zerolog.MultiLevelWriter(zerolog.ConsoleWriter{TimeFormat: ConsoleTimeFormat, NoColor: NoColor, Out: os.Stdout}, logFile)
}

logger = zerolog.New(logWriter).With().Timestamp().Logger()
Expand Down