Skip to content

Commit

Permalink
Merge pull request #130 from ginger51011/feat/add-console-time-format
Browse files Browse the repository at this point in the history
Add logger.console_time_format option
  • Loading branch information
yunginnanet authored Jan 18, 2024
2 parents e2e590e + ad88677 commit dab95ba
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 12 deletions.
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

0 comments on commit dab95ba

Please sign in to comment.