Skip to content

scripts: improve helpers/log.sh#2754

Merged
georglauterbach merged 4 commits intomasterfrom
scripts/log
Sep 3, 2022
Merged

scripts: improve helpers/log.sh#2754
georglauterbach merged 4 commits intomasterfrom
scripts/log

Conversation

@georglauterbach
Copy link
Copy Markdown
Member

Description

This PR prepares for other PRs that use the newly introduced helper
functions. The _log function itself was adjusted a bit to be shorter
and more concise.

Follow up of #2752 taking care of log.sh.

Type of change

  • Improvement (non-breaking change that does improve existing functionality)

Checklist:

  • My code follows the style guidelines of this project
  • I have performed a self-review of my own code
  • I have commented my code, particularly in hard-to-understand areas
  • I have made corresponding changes to the documentation (README.md or the documentation under docs/)
  • If necessary I have added tests that prove my fix is effective or that my feature works
  • New and existing unit tests pass locally with my changes

This PR prepares for other PRs that use the newly introduced helper
functions. The `_log` function itself was adjusted a bit to be shorter
and more concise.
@georglauterbach georglauterbach added area/scripts kind/improvement Improve an existing feature, configuration file or the documentation labels Aug 30, 2022
@georglauterbach georglauterbach added this to the v11.2.0 milestone Aug 30, 2022
@georglauterbach georglauterbach self-assigned this Aug 30, 2022
@georglauterbach georglauterbach changed the title improve scripts/helpers/log.sh scripts: improve scripts/helpers/log.sh Aug 30, 2022
@georglauterbach georglauterbach changed the title scripts: improve scripts/helpers/log.sh scripts: improve helpers/log.sh Aug 30, 2022
Comment thread target/scripts/helpers/log.sh Outdated
Comment thread target/scripts/helpers/log.sh
polarathene
polarathene previously approved these changes Aug 31, 2022
I implemented an alterative provided by @casperklein, which does the job
as well without using string truncation syntax which can look ambiguous.
printf '%s' "${LOG_LEVEL}"
elif [[ -e /etc/dms-settings ]]
then
grep "^LOG_LEVEL=" /etc/dms-settings | cut -d "'" -f 2
Copy link
Copy Markdown
Member

@polarathene polarathene Sep 1, 2022

Choose a reason for hiding this comment

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

Just a reminder that you added similar functionality in helpers/utils.sh. Might be good to apply the improvement there too:

# Provide the name of an environment variable to this function
# and it will return its value stored in /etc/dms-settings
function _get_dms_env_value
{
local VALUE
VALUE=$(grep "^${1}=" /etc/dms-settings | cut -d '=' -f 2)
printf '%s' "${VALUE:1:-1}"
}

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Nice observation. I will provide a follow-up PR :)

then
grep "^LOG_LEVEL=" /etc/dms-settings | cut -d "'" -f 2
else
printf 'info'
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

🤷

Suggested change
printf 'info'
echo 'info'

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Will do in a follow-up PR, so I can merge this first :)

{
if [[ -n ${LOG_LEVEL+set} ]]
then
printf '%s' "${LOG_LEVEL}"
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Change it or leave it 😉

Suggested change
printf '%s' "${LOG_LEVEL}"
echo "${LOG_LEVEL}"

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Will do in a follow-up PR, so I can merge this first :)

@georglauterbach georglauterbach enabled auto-merge (squash) September 3, 2022 20:59
@georglauterbach georglauterbach merged commit 39774df into master Sep 3, 2022
@georglauterbach georglauterbach deleted the scripts/log branch September 3, 2022 20:59
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area/scripts kind/improvement Improve an existing feature, configuration file or the documentation

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants