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

feat(log): support verbosing logging #61

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open

Conversation

zoumo
Copy link

@zoumo zoumo commented Aug 22, 2018

Example

import util/log

namespace test/verbose
VERBOSE=1

Log::AddOutput test/verbose DEBUG

Log "this log will be printed"
V=1 Log "this log will be printed"
V=2 Log "this log will be filtered"
$ bash example/verbose.sh
[DEBUG] [verbose.sh:11] this log will be printed
[DEBUG] [verbose.sh:12] this log will be printed

@zoumo
Copy link
Author

zoumo commented Aug 22, 2018

/cc @niieani @tterranigma

Copy link
Owner

@niieani niieani left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please change the variable name and revert the formatting of the files so it is consistent. I presume you used some auto-formatter on the file, hence it rolled together the if/thens?

Thanks.

lib/util/log.sh Outdated
if [[ ! -z ${__oo__loggers["$logger"]} ]]
then
${__oo__loggers["$logger"]} "$@"
if [[ ! -z ${__oo__loggers["$logger"]} ]]; then
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The repository uses syntax with a new line, so I'd prefer to keep it consistent.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OK

lib/util/log.sh Outdated
for logger in "${loggers[@]}"
do
loggers=(${loggerList//;/ })
for logger in "${loggers[@]}"; do
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The repository uses syntax with a new line, so I'd prefer to keep it consistent.

lib/util/log.sh Outdated
then
if [[ -z $logged ]] || [[ ${__oo__logDisabledFilter["$scope"]} == true ]]
then
if [[ ! -z "${__oo__logScopeOutputs["$scope"]}" ]]; then
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The repository uses syntax with a new line, so I'd prefer to keep it consistent.

lib/util/log.sh Outdated
@@ -6,6 +6,9 @@ declare -Ag __oo__logScopeOutputs
declare -Ag __oo__logDisabledFilter
declare -Ag __oo__loggers

# Controls verbosity of the script output and logging.
VERBOSE="${VERBOSE:-5}"
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd use something like __oo__verbosity for the variable name, VERBOSE can conflict with a user-space variable of the same name.

Ideally, we'd set this variable with some configuration function, but I can accept this as a temporary workaround.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the variable VERBOSE is for user to set.
Just like the example, before or after users import util/log, they can set/change the VERBOSE level by themselves to determine which log will be displayed

VERBOSE=2

Log::AddOutput test/verbose DEBUG

Log "this log will be displayed"
V=2 Log "this log will be displayed"

VERBOSE=1
V=2 Log "this log will not be displayed"

@zoumo
Copy link
Author

zoumo commented Aug 23, 2018

ping @niieani
I have reverted the formatting of the files.

And
the variable VERBOSE is for user to set.
Just like the example, before or after users import util/log, they can set/change the VERBOSE level by themselves to determine which log will be displayed

VERBOSE=2

Log::AddOutput test/verbose DEBUG

Log "this log will be displayed"
V=2 Log "this log will be displayed"

VERBOSE=1
V=2 Log "this log will not be displayed"

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants