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

fix(settings): It's not possible to switch the log level #13309

Merged
merged 2 commits into from
Feb 5, 2024

Conversation

kounkou
Copy link
Contributor

@kounkou kounkou commented Jan 25, 2024

Description

Previously it was not possible to change the state of the Debug toggle in settings. This was because the code forced the setting the default value (DEBUG or INFO depending on the environment) at every login, ignoring the database setup, hence always setting the DEBUG or INFO as LogLevel.

Closes #13139

What does the PR do

The PR removes forced initialization to avoid overwriting the updated config in the node_config table in database and recently set by the user. To achieve this, the PR uses a newly created entity called runTimeLogLevel that is NOT updated in Database, and that is used to set the logger in status-go. The PR still makes the Debug to be default in dev environments and disbales debug in prod environment


Test plan


Happy path ✅

No CLI, no ENV constant ✅

./bin/nim_status_client

The application displays the last Database state

With env constant DEBUG ✅

export STATUS_RUNTIME_LOG_LEVEL="DEBUG" && ./bin/nim_status_client && unset STATUS_RUNTIME_LOG_LEVEL

The application disables the Switch and set the Switch to Debug

With env constant INFO ✅

export STATUS_RUNTIME_LOG_LEVEL="INFO" && ./bin/nim_status_client && unset STATUS_RUNTIME_LOG_LEVEL

The application disables the Switch and set the Switch to Info

With CLI parameter DEBUG ✅

./bin/nim_status_client --LOG_LEVEL=DEBUG

The application disables the switch and set the switch to Debug

With CLI parameter INFO ✅

./bin/nim_status_client --LOG_LEVEL=INFO

The application disables the switch and set the switch to INFO


Failure cases ✅

With wrong env constant IN for instance ✅

export STATUS_RUNTIME_LOG_LEVEL="IN" && ./bin/nim_status_client && unset STATUS_RUNTIME_LOG_LEVEL

The application displays an error

With wrong CLI parameter -- for instance ✅

./bin/nim_status_client --LOG_LEVEL=--

The application displays an error


Affected areas

Setting Debug

Screenshot of functionality

Screencast.from.2024-01-25.02.06.00.PM.webm

@status-im-auto
Copy link
Member

status-im-auto commented Jan 25, 2024

Jenkins Builds

Click to see older builds (62)
Commit #️⃣ Finished (UTC) Duration Platform Result
✔️ c122456 #1 2024-01-25 22:45:35 ~5 min tests/nim 📄log
✔️ c122456 #1 2024-01-25 22:46:24 ~6 min macos/aarch64 🍎dmg
✔️ c122456 #1 2024-01-25 22:49:41 ~10 min macos/x86_64 🍎dmg
✔️ c122456 #1 2024-01-25 22:50:18 ~10 min tests/ui 📄log
✔️ c122456 #1 2024-01-25 23:00:18 ~20 min linux/x86_64 📦tgz
✔️ c122456 #1 2024-01-25 23:11:04 ~31 min windows/x86_64 💿exe
✖️ c122456 #1 2024-01-25 23:18:26 ~38 min tests/e2e 📄log
✔️ c122456 #2 2024-01-26 00:35:17 ~31 min tests/e2e 📄log
✔️ d4ffa01 #2 2024-01-31 19:04:14 ~5 min tests/nim 📄log
✔️ d4ffa01 #2 2024-01-31 19:04:16 ~5 min macos/aarch64 🍎dmg
✔️ d4ffa01 #2 2024-01-31 19:08:15 ~9 min macos/x86_64 🍎dmg
✔️ d4ffa01 #2 2024-01-31 19:09:13 ~10 min tests/ui 📄log
✔️ d4ffa01 #2 2024-01-31 19:15:19 ~16 min linux/x86_64 📦tgz
✔️ d4ffa01 #3 2024-01-31 19:30:08 ~31 min tests/e2e 📄log
✔️ d4ffa01 #2 2024-01-31 19:33:53 ~35 min windows/x86_64 💿exe
✔️ 5a0aa90 #3 2024-02-01 08:37:56 ~4 min macos/aarch64 🍎dmg
✔️ 5a0aa90 #3 2024-02-01 08:38:44 ~5 min tests/nim 📄log
✔️ 5a0aa90 #3 2024-02-01 08:41:47 ~8 min macos/x86_64 🍎dmg
✔️ 5a0aa90 #3 2024-02-01 08:43:16 ~10 min tests/ui 📄log
✔️ 5a0aa90 #3 2024-02-01 08:48:07 ~15 min linux/x86_64 📦tgz
✔️ 5a0aa90 #3 2024-02-01 09:00:29 ~27 min windows/x86_64 💿exe
✖️ 5a0aa90 #4 2024-02-01 09:03:56 ~30 min tests/e2e 📄log
✔️ 10b0a83 #6 2024-02-02 02:57:31 ~4 min macos/aarch64 🍎dmg
✔️ 10b0a83 #6 2024-02-02 02:58:35 ~5 min tests/nim 📄log
✔️ 10b0a83 #6 2024-02-02 03:00:25 ~7 min macos/x86_64 🍎dmg
✔️ 10b0a83 #6 2024-02-02 03:03:23 ~10 min tests/ui 📄log
✔️ 10b0a83 #6 2024-02-02 03:08:24 ~15 min linux/x86_64 📦tgz
✔️ 10b0a83 #6 2024-02-02 03:15:04 ~21 min windows/x86_64 💿exe
✔️ 10b0a83 #7 2024-02-02 03:21:44 ~28 min tests/e2e 📄log
✔️ 5e10371 #8 2024-02-02 06:09:36 ~5 min macos/aarch64 🍎dmg
✔️ 5e10371 #8 2024-02-02 06:09:56 ~5 min tests/nim 📄log
✔️ 5e10371 #8 2024-02-02 06:13:04 ~8 min macos/x86_64 🍎dmg
✔️ 5e10371 #8 2024-02-02 06:15:04 ~10 min tests/ui 📄log
✔️ 5e10371 #8 2024-02-02 06:20:20 ~15 min linux/x86_64 📦tgz
✔️ 5e10371 #8 2024-02-02 06:27:58 ~23 min windows/x86_64 💿exe
✔️ 5e10371 #9 2024-02-02 06:36:58 ~32 min tests/e2e 📄log
✔️ 797e596 #10 2024-02-02 19:27:28 ~4 min macos/aarch64 🍎dmg
✔️ 797e596 #10 2024-02-02 19:28:26 ~5 min tests/nim 📄log
✔️ 797e596 #10 2024-02-02 19:30:36 ~7 min macos/x86_64 🍎dmg
✔️ 797e596 #10 2024-02-02 19:32:43 ~10 min tests/ui 📄log
✔️ 797e596 #10 2024-02-02 19:38:29 ~15 min linux/x86_64 📦tgz
✔️ 797e596 #10 2024-02-02 19:43:48 ~21 min windows/x86_64 💿exe
✔️ 797e596 #11 2024-02-02 19:52:54 ~30 min tests/e2e 📄log
✔️ 435a6bc #11 2024-02-02 21:17:33 ~4 min macos/aarch64 🍎dmg
✔️ 435a6bc #11 2024-02-02 21:18:26 ~5 min tests/nim 📄log
✔️ 435a6bc #11 2024-02-02 21:20:59 ~8 min macos/x86_64 🍎dmg
✔️ 435a6bc #11 2024-02-02 21:22:18 ~9 min tests/ui 📄log
✔️ 435a6bc #11 2024-02-02 21:28:23 ~15 min linux/x86_64 📦tgz
✔️ 6efd68f #12 2024-02-02 21:33:47 ~4 min macos/aarch64 🍎dmg
✔️ 6efd68f #12 2024-02-02 21:35:45 ~6 min tests/nim 📄log
✔️ 6efd68f #12 2024-02-02 21:36:51 ~7 min macos/x86_64 🍎dmg
✔️ 6efd68f #12 2024-02-02 21:39:38 ~10 min tests/ui 📄log
✔️ 6efd68f #12 2024-02-02 21:45:50 ~16 min linux/x86_64 📦tgz
✔️ 6efd68f #12 2024-02-02 21:49:27 ~19 min windows/x86_64 💿exe
✔️ 6efd68f #13 2024-02-02 21:59:59 ~30 min tests/e2e 📄log
✔️ 9edc9b7 #13 2024-02-02 22:31:06 ~4 min macos/aarch64 🍎dmg
✔️ 9edc9b7 #13 2024-02-02 22:32:37 ~5 min tests/nim 📄log
✔️ 9edc9b7 #13 2024-02-02 22:34:06 ~7 min macos/x86_64 🍎dmg
✔️ 9edc9b7 #13 2024-02-02 22:37:09 ~10 min tests/ui 📄log
✔️ 9edc9b7 #13 2024-02-02 22:42:59 ~16 min linux/x86_64 📦tgz
✔️ 9edc9b7 #13 2024-02-02 22:46:32 ~19 min windows/x86_64 💿exe
✔️ 9edc9b7 #14 2024-02-02 22:56:37 ~29 min tests/e2e 📄log
Commit #️⃣ Finished (UTC) Duration Platform Result
✔️ 52faea5 #14 2024-02-05 01:03:31 ~4 min macos/aarch64 🍎dmg
✔️ 52faea5 #14 2024-02-05 01:04:12 ~5 min tests/nim 📄log
✔️ 52faea5 #14 2024-02-05 01:06:54 ~8 min macos/x86_64 🍎dmg
✔️ 52faea5 #14 2024-02-05 01:08:55 ~10 min tests/ui 📄log
✔️ 52faea5 #14 2024-02-05 01:14:25 ~15 min linux/x86_64 📦tgz
✔️ 52faea5 #14 2024-02-05 01:19:42 ~21 min windows/x86_64 💿exe
✔️ 52faea5 #15 2024-02-05 01:29:25 ~30 min tests/e2e 📄log
✔️ 5c7f76f #15 2024-02-05 16:12:51 ~5 min macos/aarch64 🍎dmg
✔️ 5c7f76f #15 2024-02-05 16:13:46 ~6 min tests/nim 📄log
✔️ 5c7f76f #15 2024-02-05 16:15:07 ~7 min macos/x86_64 🍎dmg
✔️ 5c7f76f #15 2024-02-05 16:18:43 ~11 min tests/ui 📄log
✔️ 5c7f76f #15 2024-02-05 16:23:36 ~16 min linux/x86_64 📦tgz
✔️ 5c7f76f #15 2024-02-05 16:29:02 ~21 min windows/x86_64 💿exe
✖️ 5c7f76f #16 2024-02-05 16:40:07 ~32 min tests/e2e 📄log
✔️ 5c7f76f #17 2024-02-05 17:10:19 ~29 min tests/e2e 📄log

@kounkou kounkou self-assigned this Jan 26, 2024
@igor-sirotin
Copy link
Contributor

But if I use a runtime CLI option or an ENV variable, will it override the database setting?

@igor-sirotin
Copy link
Contributor

igor-sirotin commented Jan 26, 2024

Let me dot all i's and cross all t's.

We have a few debug switchers (and there's a mess with this):

  • STATUS_BUILD_LOG_LEVEL environment variable
  • STATUS_RUNTIME_LOG_LEVEL environment variable
  • --log-level cli option
  • settings.isDebugEnabled database value, which is controlled by a switch in Settings -> Advanced

Currently this options are interconnected in a hard-to-track manner. Some use each other as default value, some override each other values in runtime.

What to we want?

We want:

  1. the default value to depend on the build type
  2. enable "debug" from UI: this should switch the logs to DEBUG and enable debug UI controls
  3. set desired log level from CLI option or ENV variable

Proposal

There're no requirements so far, so we can try to make them up ourselves.

Proposal 1: separate controls (my opinion: 👎 )

The easiest way is to separate the "log level" from "show ui debug controls".
That means to have 2 UI controls and 2 corresponding CLI options:

  1. ComboBox for log level ERROR/WARNING/INFO/DEBUG/TRACE
  2. Switch for "Show UI debug controls"

This sounds too complicated to me. Most of the time we want to control these together.

Proposal 2: define strict rules and dependencies (my opinion: 👍)

  1. CLI option and RUNTIME environment variable must have highest precedence over any other values
  2. When settings.isDebugEnabled is overridden, disable the UI switch.
    By "disable" I mean:
    • switch value shows the overridden value
    • set enabled: false, so that the user's not able to change the value
    • maybe show some explanation text "The value is overridden with runtime options"
  3. When settings.isDebugEnabled is overridden, it's value is calculated as:
    isDebugEnabled = runtimeLogLevel == chronicles.LogLevel.TRACE || 
                     runtimeLogLevel == chronicles.LogLevel.DEBUG
  4. BUILD_LOG_LEVEL controls:
    • default log level for new accounts
    • log level for the time before an account is logged in

I believe this will keep all the "wants" and make things straightforward.

@kounkou
Copy link
Contributor Author

kounkou commented Jan 26, 2024

Hi Igor 👋🏾

Amazing comment, I also like Proposal 2, because it will confuse the user even more to have separate controls for controlling 2 items (IsDebugEnabled, and LogLevel) which are really coupled.

Since I agree with proposal 2 high level idea, and to make sure I understand correctly, let me add my questions quoting your points :

  1. CLI option and RUNTIME environment variable must have highest precedence over any other values

Should this be interpreted as, running the Status application and setting ENV variables or CLI should affect the values of IsDebugEnabled and LogLevel that could have been set through another mean (UI here), right? This make sense to me 👍🏾

Note : What is the precedence between CLI and ENV, I guess ENV is at the top right?

  1. When settings.isDebugEnabled is overridden, disable the UI switch.
    By "disable" I mean:

    • switch displays the overridden value checked: runtimeLogLevelSet
    • set enabled: false, so that the user's not able to change the value
    • maybe show some explanation text "The value is overridden with runtime options"

Here, it's a bit confusing, but I got the point, I like the disabling of the button all together. Because let's suppose I don't disable the button. If I set the IsDebugEnabled through CLI/ENV variable, then we fall into the current ticket situation where updating on the UI doesn't produce changes as the ENV variable is having a priority. This is the bug that I was trying to fix, and it is contradictory action if the disabling is excluded.

Action : I can add explanation like you said at worse. And at best, I think disbaling the button in the ENV variable is ideal.
Note : launching the Status App with the CLI and setting the IsDebugEnabled should only be relevant for the session correct ? Next time we boot, we should rely on ENV or if no ENV var letting the user modify the previous value set by CLI

  1. When settings.isDebugEnabled, it's value is calculated as:
    isDebugEnabled = runtimeLogLevel == chronicles.LogLevel.TRACE || 
                     runtimeLogLevel == chronicles.LogLevel.DEBUG

Fair enough, thanks for this. However, why this is related to chronicles ? am I missing something ?

  1. BUILD_LOG_LEVEL controls:

    • default log level for new accounts
    • log level for the time before an account is logged in

I am not sure I understand this point. Are you talking about the

PROD --> INFO
DEV --> DEBUG

relationship or something else? If yes, this works already today even with my change.

@igor-sirotin
Copy link
Contributor

NOTE: in my reply I by runtime options I mean --log-level CLI option and STATUS_RUNTIME_LOG_LEVEL environment variable.


Should this be interpreted as, running the Status application and setting ENV variables or CLI should affect the values of IsDebugEnabled and LogLevel that could have been set through another mean (UI here), right? This make sense to me 👍🏾

Yep. And the database value should remain the same as it was.

Note : What is the precedence between CLI and ENV, I guess ENV is at the top right?

Don't bother about this. This is already held automatically by the nim config library we use.

This is the bug that I was trying to fix, and it is contradictory action if the disabling is excluded.

Yep!

Action : I can add explanation like you said at worse. And at best, I think disbaling the button in the ENV variable is ideal.

I'd go with both.

  1. Disable the switch if any of runtime options is present.
  2. Show "The value is overridden with runtime options". This could be a ToolTip on hover, for example. You can ping @benjthayer, but this is really not a big deal. It's advanced settings, not smth a usual user should do. Just a simple note for ourselves.

Launching the Status App with the CLI and setting the IsDebugEnabled should only be relevant for the session correct? Next time we boot, we should rely on ENV or if no ENV var letting the user modify the previous value set by CLI

Hmm. Yes, runtime options are temporary, for current session only. They shouldn't affect the settings.isDebugEnabled value stored in the database.

However, why this is related to chronicles? am I missing something ?

chronicles is the Nim library we use for logging. And this is the library where the LogLevel enum is actually defined:
https://github.com/status-im/nim-chronicles/blob/14e8537e4aefda832996a187c4acfef8eadb2aeb/chronicles/options.nim#L38-L48

I am not sure I understand this point. Are you talking about the
PROD --> INFO
DEV --> DEBUG
relationship or something else? If yes, this works already today even with my change.

Yes, I'm about this. Yes, I believe it already works 🙂

@kounkou
Copy link
Contributor Author

kounkou commented Jan 30, 2024

Confirmed with Ben about what we want in terms of UI :

I would perhaps implement a tooltip on hover of the disabled toggle confirming why it is disabled to help clarify this to the user. Other than that, it's just the change to the opacity of the toggle. As you say, the Debug text should be 100% of main black text colour.


Result :

Screencast.from.2024-01-30.05.04.17.PM.webm

@kounkou
Copy link
Contributor Author

kounkou commented Jan 30, 2024

-[x] the default value to depend on the build type (Already worked)

Verified that when building Status in release mode, example by overriding

RESOURCES_LAYOUT ?= -d:development
with RESOURCES_LAYOUT ?= -d:production then the status application has default DebugEnabled false and the logs are INFO.

-[x] set desired log level from CLI option or ENV variable (NEW)

Verified that when setting a CLI variable example export STATUS_RUNTIME_LOG_LEVEL="DEBUG" or with run parameter ./bin/nim_status_client --LOG_LEVEL=TRACE, the UI Debug setting displays the DEBUG option On and non-modifiable and the logs in terminal for instance, match the corresponding log level

-[x] enable "debug" from UI: this should switch (AFTER Restart) the logs to DEBUG and enable debug UI controls

Solved This is currently work in progress
Just to clarify, this should override the default logs (DEBUG in development and INFO in production) and apply the logging level with the condition that the ENV or cli parameters are NOT used when launching the status client application.

@kounkou kounkou force-pushed the fix-debug-log-setting branch 4 times, most recently from 064fec4 to 10b0a83 Compare February 2, 2024 02:52
src/constants.nim Outdated Show resolved Hide resolved
ui/app/AppLayouts/Profile/views/AdvancedView.qml Outdated Show resolved Hide resolved
@kounkou kounkou force-pushed the fix-debug-log-setting branch 2 times, most recently from f3fd6ac to 797e596 Compare February 2, 2024 19:22
@kounkou kounkou force-pushed the fix-debug-log-setting branch 2 times, most recently from 435a6bc to 6efd68f Compare February 2, 2024 21:29
Copy link
Contributor

@igor-sirotin igor-sirotin left a comment

Choose a reason for hiding this comment

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

Just 2 minor comments. Thanks for your patience 👍

ui/app/AppLayouts/Profile/stores/AdvancedStore.qml Outdated Show resolved Hide resolved
Copy link
Contributor

@MishkaRogachev MishkaRogachev left a comment

Choose a reason for hiding this comment

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

LGTM!

Previously it was not possible to change the state of the Debug toggle.
This is because the code forced the setting the default value, ignoring
the database setup, hence always setting the DEBUG as LogLevel.

Closes #13139
@kounkou kounkou merged commit ae16bd8 into master Feb 5, 2024
9 checks passed
@kounkou kounkou deleted the fix-debug-log-setting branch February 5, 2024 17:11
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.

It's not possible to switch the log level
5 participants