-
-
Notifications
You must be signed in to change notification settings - Fork 1.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
improve error stack configuration for package gerror, add framework e…
…rror stack filter for package glog (#2918)
- Loading branch information
Showing
5 changed files
with
94 additions
and
22 deletions.
There are no files selected for viewing
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,61 @@ | ||
// Copyright GoFrame gf Author(https://goframe.org). All Rights Reserved. | ||
// | ||
// This Source Code Form is subject to the terms of the MIT License. | ||
// If a copy of the MIT was not distributed with this file, | ||
// You can obtain one at https://github.com/gogf/gf. | ||
|
||
// Package errors provides functionalities to manipulate errors for internal usage purpose. | ||
package errors | ||
|
||
import ( | ||
"github.com/gogf/gf/v2/internal/command" | ||
) | ||
|
||
// StackMode is the mode that printing stack information in StackModeBrief or StackModeDetail mode. | ||
type StackMode string | ||
|
||
const ( | ||
// commandEnvKeyForBrief is the command environment name for switch key for brief error stack. | ||
// Deprecated: use commandEnvKeyForStackMode instead. | ||
commandEnvKeyForBrief = "gf.gerror.brief" | ||
|
||
// commandEnvKeyForStackMode is the command environment name for switch key for brief error stack. | ||
commandEnvKeyForStackMode = "gf.gerror.stack.mode" | ||
) | ||
|
||
const ( | ||
// StackModeBrief specifies all error stacks printing no framework error stacks. | ||
StackModeBrief StackMode = "brief" | ||
|
||
// StackModeDetail specifies all error stacks printing detailed error stacks including framework stacks. | ||
StackModeDetail StackMode = "detail" | ||
) | ||
|
||
var ( | ||
// stackModeConfigured is the configured error stack mode variable. | ||
// It is brief stack mode in default. | ||
stackModeConfigured = StackModeBrief | ||
) | ||
|
||
func init() { | ||
// Deprecated. | ||
briefSetting := command.GetOptWithEnv(commandEnvKeyForBrief) | ||
if briefSetting == "1" || briefSetting == "true" { | ||
stackModeConfigured = StackModeBrief | ||
} | ||
|
||
// The error stack mode is configured using command line arguments or environments. | ||
stackModeSetting := command.GetOptWithEnv(commandEnvKeyForStackMode) | ||
if stackModeSetting != "" { | ||
stackModeSettingMode := StackMode(stackModeSetting) | ||
switch stackModeSettingMode { | ||
case StackModeBrief, StackModeDetail: | ||
stackModeConfigured = stackModeSettingMode | ||
} | ||
} | ||
} | ||
|
||
// IsStackModeBrief returns whether current error stack mode is in brief mode. | ||
func IsStackModeBrief() bool { | ||
return stackModeConfigured == StackModeBrief | ||
} |
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,20 @@ | ||
// Copyright GoFrame Author(https://goframe.org). All Rights Reserved. | ||
// | ||
// This Source Code Form is subject to the terms of the MIT License. | ||
// If a copy of the MIT was not distributed with this file, | ||
// You can obtain one at https://github.com/gogf/gf. | ||
|
||
package errors_test | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/gogf/gf/v2/internal/errors" | ||
"github.com/gogf/gf/v2/test/gtest" | ||
) | ||
|
||
func Test_IsStackModeBrief(t *testing.T) { | ||
gtest.C(t, func(t *gtest.T) { | ||
t.Assert(errors.IsStackModeBrief(), true) | ||
}) | ||
} |
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