Skip to content

Commit

Permalink
fix logger (#370)
Browse files Browse the repository at this point in the history
  • Loading branch information
harjotgill authored Sep 8, 2022
1 parent dc22124 commit dd77ac5
Show file tree
Hide file tree
Showing 11 changed files with 17 additions and 182 deletions.
3 changes: 2 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,8 @@ operator-manifests: controller-gen ## Generate WebhookConfiguration, ClusterRole

.PHONY: operator-generate
operator-generate: controller-gen ## Generate code containing DeepCopy, DeepCopyInto, and DeepCopyObject method implementations.
$(CONTROLLER_GEN) object:headerFile="operator/hack/boilerplate.go.txt" paths="./..."
$(CONTROLLER_GEN) object:headerFile="operator/hack/boilerplate.go.txt" paths="./pkg/..."
$(CONTROLLER_GEN) object:headerFile="operator/hack/boilerplate.go.txt" paths="./operator/..."

.PHONY: operator-fmt
operator-fmt: ## Run go fmt against code.
Expand Down
34 changes: 1 addition & 33 deletions docs/gen/config/aperture-agent/config-swagger.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -570,45 +570,13 @@ definitions:
x-go-package: github.com/fluxninja/aperture/pkg/net/listener
LogConfig:
properties:
compress:
description: Compress
type: boolean
x-go-default: "false"
x-go-name: Compress
file:
description: Output file for logs. Keywords allowed - ["stderr", "default"].
"default" maps to `/var/log/fluxninja/<service>.log`
type: string
x-go-default: stderr
x-go-name: File
level:
description: Log level
type: string
x-go-default: info
x-go-name: LogLevel
x-go-validate: oneof=debug DEBUG info INFO warn WARN error ERROR fatal FATAL
panic PANIC trace TRACE disabled DISABLED
max_age:
description: Max age in days for log files
format: int64
type: integer
x-go-default: "7"
x-go-name: MaxAge
x-go-validate: gte=0
max_backups:
description: Max log file backups
format: int64
type: integer
x-go-default: "3"
x-go-name: MaxBackups
x-go-validate: gte=0
max_size:
description: Log file max size in MB
format: int64
type: integer
x-go-default: "50"
x-go-name: MaxSize
x-go-validate: gte=0
non_blocking:
description: Use non-blocking log writer (can lose logs at high throughput)
type: boolean
Expand All @@ -621,7 +589,7 @@ definitions:
x-go-default: "false"
x-go-name: PrettyConsole
writers:
description: Additional log writers
description: Log writers
items:
$ref: '#/definitions/LogWriterConfig'
type: array
Expand Down
32 changes: 1 addition & 31 deletions docs/gen/config/aperture-agent/swagger.md
Original file line number Diff line number Diff line change
Expand Up @@ -1189,41 +1189,11 @@ LogConfig holds configuration for a logger and log writers.
#### Properties

<dl>
<dt>compress</dt>
<dd>

(bool, default: `false`) Compress

</dd>
<dt>file</dt>
<dd>

(string, default: `stderr`) Output file for logs. Keywords allowed - ["stderr", "default"]. "default" maps to `/var/log/fluxninja/<service>.log`

</dd>
<dt>level</dt>
<dd>

(string, `oneof=debug DEBUG info INFO warn WARN error ERROR fatal FATAL panic PANIC trace TRACE disabled DISABLED`, default: `info`) Log level

</dd>
<dt>max_age</dt>
<dd>

(int64, `gte=0`, default: `7`) Max age in days for log files

</dd>
<dt>max_backups</dt>
<dd>

(int64, `gte=0`, default: `3`) Max log file backups

</dd>
<dt>max_size</dt>
<dd>

(int64, `gte=0`, default: `50`) Log file max size in MB

</dd>
<dt>non_blocking</dt>
<dd>
Expand All @@ -1240,7 +1210,7 @@ LogConfig holds configuration for a logger and log writers.
<dt>writers</dt>
<dd>

([[]LogWriterConfig](#log-writer-config), `omitempty,dive,omitempty`) Additional log writers
([[]LogWriterConfig](#log-writer-config), `omitempty,dive,omitempty`) Log writers

</dd>
</dl>
Expand Down
34 changes: 1 addition & 33 deletions docs/gen/config/aperture-controller/config-swagger.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -505,45 +505,13 @@ definitions:
x-go-package: github.com/fluxninja/aperture/pkg/net/listener
LogConfig:
properties:
compress:
description: Compress
type: boolean
x-go-default: "false"
x-go-name: Compress
file:
description: Output file for logs. Keywords allowed - ["stderr", "default"].
"default" maps to `/var/log/fluxninja/<service>.log`
type: string
x-go-default: stderr
x-go-name: File
level:
description: Log level
type: string
x-go-default: info
x-go-name: LogLevel
x-go-validate: oneof=debug DEBUG info INFO warn WARN error ERROR fatal FATAL
panic PANIC trace TRACE disabled DISABLED
max_age:
description: Max age in days for log files
format: int64
type: integer
x-go-default: "7"
x-go-name: MaxAge
x-go-validate: gte=0
max_backups:
description: Max log file backups
format: int64
type: integer
x-go-default: "3"
x-go-name: MaxBackups
x-go-validate: gte=0
max_size:
description: Log file max size in MB
format: int64
type: integer
x-go-default: "50"
x-go-name: MaxSize
x-go-validate: gte=0
non_blocking:
description: Use non-blocking log writer (can lose logs at high throughput)
type: boolean
Expand All @@ -556,7 +524,7 @@ definitions:
x-go-default: "false"
x-go-name: PrettyConsole
writers:
description: Additional log writers
description: Log writers
items:
$ref: '#/definitions/LogWriterConfig'
type: array
Expand Down
32 changes: 1 addition & 31 deletions docs/gen/config/aperture-controller/swagger.md
Original file line number Diff line number Diff line change
Expand Up @@ -1034,41 +1034,11 @@ LogConfig holds configuration for a logger and log writers.
#### Properties

<dl>
<dt>compress</dt>
<dd>

(bool, default: `false`) Compress

</dd>
<dt>file</dt>
<dd>

(string, default: `stderr`) Output file for logs. Keywords allowed - ["stderr", "default"]. "default" maps to `/var/log/fluxninja/<service>.log`

</dd>
<dt>level</dt>
<dd>

(string, `oneof=debug DEBUG info INFO warn WARN error ERROR fatal FATAL panic PANIC trace TRACE disabled DISABLED`, default: `info`) Log level

</dd>
<dt>max_age</dt>
<dd>

(int64, `gte=0`, default: `7`) Max age in days for log files

</dd>
<dt>max_backups</dt>
<dd>

(int64, `gte=0`, default: `3`) Max log file backups

</dd>
<dt>max_size</dt>
<dd>

(int64, `gte=0`, default: `50`) Log file max size in MB

</dd>
<dt>non_blocking</dt>
<dd>
Expand All @@ -1085,7 +1055,7 @@ LogConfig holds configuration for a logger and log writers.
<dt>writers</dt>
<dd>

([[]LogWriterConfig](#log-writer-config), `omitempty,dive,omitempty`) Additional log writers
([[]LogWriterConfig](#log-writer-config), `omitempty,dive,omitempty`) Log writers

</dd>
</dl>
Expand Down
25 changes: 4 additions & 21 deletions operator/config/crd/bases/fluxninja.com_agents.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -1201,25 +1201,9 @@ spec:
log:
description: Log configuration.
properties:
compress:
description: Compress
type: boolean
file:
description: Output file for logs. Keywords allowed - ["stderr",
"default"]. "default" maps to `/var/log/fluxninja/<service>.log`
type: string
level:
description: Log level
type: string
max_age:
description: Max age in days for log files
type: integer
max_backups:
description: Max log file backups
type: integer
max_size:
description: Log file max size in MB
type: integer
non_blocking:
description: Use non-blocking log writer (can lose logs at
high throughput)
Expand Down Expand Up @@ -1331,8 +1315,8 @@ spec:
type: string
type: array
plugins_path:
description: Path to plugins directory. This can be set via
command line arguments as well.
description: Path to plugins directory. "default" points to
`/var/lib/aperture/<service>/plugins`.
type: string
type: object
profilers:
Expand All @@ -1344,9 +1328,8 @@ spec:
is enabled as CPU profile will always be running.
type: boolean
profiles_path:
description: Path to save performance profiles. This can be
set via command line arguments as well. E.g. default path
for aperture-agent is /var/log/aperture/aperture-agent/profiles.
description: Path to save performance profiles. "default"
path is `/var/log/aperture/<service>/profiles`.
type: string
register_http_routes:
description: Register routes. Profile types profile, symbol
Expand Down
25 changes: 4 additions & 21 deletions operator/config/crd/bases/fluxninja.com_controllers.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -1096,25 +1096,9 @@ spec:
log:
description: Log configuration.
properties:
compress:
description: Compress
type: boolean
file:
description: Output file for logs. Keywords allowed - ["stderr",
"default"]. "default" maps to `/var/log/fluxninja/<service>.log`
type: string
level:
description: Log level
type: string
max_age:
description: Max age in days for log files
type: integer
max_backups:
description: Max log file backups
type: integer
max_size:
description: Log file max size in MB
type: integer
non_blocking:
description: Use non-blocking log writer (can lose logs at
high throughput)
Expand Down Expand Up @@ -1217,8 +1201,8 @@ spec:
type: string
type: array
plugins_path:
description: Path to plugins directory. This can be set via
command line arguments as well.
description: Path to plugins directory. "default" points to
`/var/lib/aperture/<service>/plugins`.
type: string
type: object
policies:
Expand Down Expand Up @@ -1250,9 +1234,8 @@ spec:
is enabled as CPU profile will always be running.
type: boolean
profiles_path:
description: Path to save performance profiles. This can be
set via command line arguments as well. E.g. default path
for aperture-agent is /var/log/aperture/aperture-agent/profiles.
description: Path to save performance profiles. "default"
path is `/var/log/aperture/<service>/profiles`.
type: string
register_http_routes:
description: Register routes. Profile types profile, symbol
Expand Down
11 changes: 3 additions & 8 deletions pkg/config/log.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,12 +53,9 @@ type LogConfig struct {
// Log level
LogLevel string `json:"level" validate:"oneof=debug DEBUG info INFO warn WARN error ERROR fatal FATAL panic PANIC trace TRACE disabled DISABLED" default:"info"`

// Additional log writers
// Log writers
Writers []LogWriterConfig `json:"writers" validate:"omitempty,dive,omitempty"`

// Base LogWriterConfig
LogWriterConfig `json:",inline"`

// Use non-blocking log writer (can lose logs at high throughput)
NonBlocking bool `json:"non_blocking" default:"true"`

Expand Down Expand Up @@ -122,7 +119,7 @@ func (constructor LoggerConstructor) provideLogger(w []io.Writer,
log.Panic().Err(err).Msg("Unable to deserialize log configuration!")
}
logger, writers := NewLogger(config)
// append additional writers provided via Fx
// append writers provided via Fx
writers = append(writers, w...)

lifecycle.Append(fx.Hook{
Expand Down Expand Up @@ -152,7 +149,7 @@ func NewLogger(config LogConfig) (log.Logger, []io.Writer) {
// append file writers
for _, writerConfig := range config.Writers {
var writer io.Writer
if config.File != "" {
if writerConfig.File != "" {
switch writerConfig.File {
case stdErrFile:
writer = os.Stderr
Expand Down Expand Up @@ -188,7 +185,5 @@ func NewLogger(config LogConfig) (log.Logger, []io.Writer) {

logger := log.NewLogger(multi, config.NonBlocking, strings.ToLower(config.LogLevel))

logger.Info().Msg("Configured logger")

return logger, writers
}
1 change: 0 additions & 1 deletion pkg/config/zz_generated.deepcopy.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 0 additions & 1 deletion playground/tanka/apps/aperture-agent/mixins.libsonnet
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ local apertureAgentMixin =
pretty_console: true,
non_blocking: true,
level: 'debug',
file: 'default',
},
etcd+: {
endpoints: ['http://controller-etcd.aperture-controller.svc.cluster.local:2379'],
Expand Down
1 change: 0 additions & 1 deletion playground/tanka/apps/aperture-controller/mixins.libsonnet
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ local apertureControllerMixin =
pretty_console: true,
non_blocking: true,
level: 'debug',
file: 'default',
},
etcd+: {
endpoints: ['http://controller-etcd.aperture-controller.svc.cluster.local:2379'],
Expand Down

0 comments on commit dd77ac5

Please sign in to comment.