-
Notifications
You must be signed in to change notification settings - Fork 148
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
* Fix logger not respecting updated level (#2456) Fix logger not respecting updated level (#2456) (cherry picked from commit c4c2ac0) --------- Co-authored-by: Michal Pristas <[email protected]>
- Loading branch information
1 parent
2d90292
commit 1ae907d
Showing
8 changed files
with
126 additions
and
41 deletions.
There are no files selected for viewing
31 changes: 31 additions & 0 deletions
31
changelog/fragments/1680764383-Respecting-logging.level-settings.yaml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
# Kind can be one of: | ||
# - breaking-change: a change to previously-documented behavior | ||
# - deprecation: functionality that is being removed in a later release | ||
# - bug-fix: fixes a problem in a previous version | ||
# - enhancement: extends functionality but does not break or fix existing behavior | ||
# - feature: new functionality | ||
# - known-issue: problems that we are aware of in a given version | ||
# - security: impacts on the security of a product or a user’s deployment. | ||
# - upgrade: important information for someone upgrading from a prior version | ||
# - other: does not fit into any of the other categories | ||
kind: bug-fix | ||
|
||
# Change summary; a 80ish characters long description of the change. | ||
summary: Respecting logging.level settings coming whether from Fleet UI or config file. | ||
|
||
# Long description; in case the summary is not enough to describe the change | ||
# this field accommodate a description without length limits. | ||
#description: | ||
|
||
# Affected component; a word indicating the component this changeset affects. | ||
component: elastic-agent | ||
|
||
# PR number; optional; the PR number that added the changeset. | ||
# If not present is automatically filled by the tooling finding the PR where this changelog fragment has been added. | ||
# NOTE: the tooling supports backports, so it's able to fill the original PR number instead of the backport PR number. | ||
# Please provide it if you are adding a fragment for a different PR. | ||
pr: 2456 | ||
|
||
# Issue number; optional; the GitHub issue related to this changeset (either closes or is part of). | ||
# If not present is automatically filled by the tooling with the issue linked to the PR number. | ||
issue: 2450 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
// Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
// or more contributor license agreements. Licensed under the Elastic License; | ||
// you may not use this file except in compliance with the Elastic License. | ||
|
||
package logger | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/stretchr/testify/require" | ||
"go.uber.org/zap/zapcore" | ||
|
||
"github.com/elastic/elastic-agent-libs/logp" | ||
) | ||
|
||
func Test_SetLevel(t *testing.T) { | ||
l, err := NewWithLogpLevel("", logp.ErrorLevel, true) | ||
require.NoError(t, err) | ||
|
||
// core logger works | ||
require.Equal(t, false, l.Core().Enabled(zapcore.DebugLevel)) | ||
require.Equal(t, false, l.Core().Enabled(zapcore.InfoLevel)) | ||
require.Equal(t, false, l.Core().Enabled(zapcore.WarnLevel)) | ||
require.Equal(t, true, l.Core().Enabled(zapcore.ErrorLevel)) | ||
// enabler updated | ||
require.Equal(t, false, internalLevelEnabler.Enabled(zapcore.DebugLevel)) | ||
require.Equal(t, false, internalLevelEnabler.Enabled(zapcore.InfoLevel)) | ||
require.Equal(t, false, internalLevelEnabler.Enabled(zapcore.WarnLevel)) | ||
require.Equal(t, true, internalLevelEnabler.Enabled(zapcore.ErrorLevel)) | ||
|
||
tests := []struct { | ||
SetLogLevel logp.Level | ||
DebugEnabled bool | ||
InfoEnabled bool | ||
WarnEnabled bool | ||
ErrEnabled bool | ||
}{ | ||
{logp.DebugLevel, true, true, true, true}, | ||
{logp.InfoLevel, false, true, true, true}, | ||
{logp.WarnLevel, false, false, true, true}, | ||
{logp.ErrorLevel, false, false, false, true}, | ||
} | ||
|
||
for _, tc := range tests { | ||
SetLevel(tc.SetLogLevel) | ||
|
||
// core logger works | ||
require.Equal(t, tc.DebugEnabled, l.Core().Enabled(zapcore.DebugLevel)) | ||
require.Equal(t, tc.InfoEnabled, l.Core().Enabled(zapcore.InfoLevel)) | ||
require.Equal(t, tc.WarnEnabled, l.Core().Enabled(zapcore.WarnLevel)) | ||
require.Equal(t, tc.ErrEnabled, l.Core().Enabled(zapcore.ErrorLevel)) | ||
// enabler updated | ||
require.Equal(t, tc.DebugEnabled, internalLevelEnabler.Enabled(zapcore.DebugLevel)) | ||
require.Equal(t, tc.InfoEnabled, internalLevelEnabler.Enabled(zapcore.InfoLevel)) | ||
require.Equal(t, tc.WarnEnabled, internalLevelEnabler.Enabled(zapcore.WarnLevel)) | ||
require.Equal(t, tc.ErrEnabled, internalLevelEnabler.Enabled(zapcore.ErrorLevel)) | ||
} | ||
} |