Skip to content

Commit

Permalink
fix(settings): It's not possible to switch the log level
Browse files Browse the repository at this point in the history
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
  • Loading branch information
kounkou committed Feb 5, 2024
1 parent dd26511 commit 52faea5
Show file tree
Hide file tree
Showing 8 changed files with 42 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,9 @@ method toggleAutoMessage*(self: AccessInterface) {.base.} =
method isDebugEnabled*(self: AccessInterface): bool {.base.} =
raise newException(ValueError, "No implementation available")

method isRuntimeLogLevelSet*(self: AccessInterface): bool {.base.} =
raise newException(ValueError, "No implementation available")

method toggleDebug*(self: AccessInterface) {.base.} =
raise newException(ValueError, "No implementation available")

Expand Down
6 changes: 6 additions & 0 deletions src/app/modules/main/profile_section/advanced/module.nim
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,12 @@ method toggleDebug*(self: Module) =
method onDebugToggled*(self: Module) =
self.view.isDebugEnabledChanged()

method isRuntimeLogLevelSet*(self: Module): bool =
return constants.runtimeLogLevelSet()

method getRuntimeLogLevel*(self: Module): string =
return constants.LOG_LEVEL

method toggleWalletSection*(self: Module) =
self.controller.toggleWalletSection()

Expand Down
5 changes: 5 additions & 0 deletions src/app/modules/main/profile_section/advanced/view.nim
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,11 @@ QtObject:
proc toggleDebug*(self: View) {.slot.} =
self.delegate.toggleDebug()

proc getIsRuntimeLogLevelSet*(self: View): bool {.slot.} =
return self.delegate.isRuntimeLogLevelSet()
QtProperty[bool] isRuntimeLogLevelSet:
read = getIsRuntimeLogLevelSet

proc toggleWalletSection*(self: View) {.slot.} =
self.delegate.toggleWalletSection()

Expand Down
3 changes: 2 additions & 1 deletion src/app_service/service/accounts/service.nim
Original file line number Diff line number Diff line change
Expand Up @@ -405,7 +405,8 @@ QtObject:
"TorrentDir": DEFAULT_TORRENT_CONFIG_TORRENTDIR
}

result["LogLevel"] = newJString(toStatusGoSupportedLogLevel(main_constants.LOG_LEVEL))
if main_constants.runtimeLogLevelSet():
result["RuntimeLogLevel"] = newJString(toStatusGoSupportedLogLevel(main_constants.LOG_LEVEL))

if STATUS_PORT != 0:
result["ListenAddr"] = newJString("0.0.0.0:" & $main_constants.STATUS_PORT)
Expand Down
10 changes: 8 additions & 2 deletions src/app_service/service/node_configuration/service.nim
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import ../settings/service as settings_service
import ../../../app/core/eventemitter
import ../../../app/core/fleets/fleet_configuration
import ../../../backend/node_config as status_node_config
import ../../../constants as main_constants

export node_config

Expand All @@ -14,7 +15,9 @@ logScope:
const WAKU_VERSION_1* = 1
const WAKU_VERSION_2* = 2

const SIGNAL_NODE_LOG_LEVEL_UPDATE* = "nodeLogLevelUpdated"
const
SIGNAL_NODE_LOG_LEVEL_UPDATE* = "nodeLogLevelUpdated"
DEBUG_LOG_LEVELS = @["DEBUG", "TRACE"]

type
NodeLogLevelUpdatedArgs* = ref object of Args
Expand Down Expand Up @@ -194,7 +197,10 @@ proc getLogLevel(self: Service): string =
return self.configuration.LogLevel

proc isDebugEnabled*(self: Service): bool =
return self.getLogLevel() == $LogLevel.DEBUG
var logLevel = self.getLogLevel()
if main_constants.runtimeLogLevelSet():
logLevel = main_constants.LOG_LEVEL
return logLevel in DEBUG_LOG_LEVELS

proc setLogLevel*(self: Service, logLevel: LogLevel): bool =
var newConfiguration = self.configuration
Expand Down
1 change: 1 addition & 0 deletions ui/app/AppLayouts/Profile/stores/AdvancedStore.qml
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ QtObject {
property bool isDebugEnabled: advancedModule? advancedModule.isDebugEnabled : false
readonly property bool isWakuV2ShardedCommunitiesEnabled: localAppSettings.wakuV2ShardedCommunitiesEnabled ?? false
property int logMaxBackups: advancedModule ? advancedModule.logMaxBackups : 1
property bool isRuntimeLogLevelSet: advancedModule ? advancedModule.isRuntimeLogLevelSet: false

property var customNetworksModel: advancedModule? advancedModule.customNetworksModel : []

Expand Down
16 changes: 16 additions & 0 deletions ui/app/AppLayouts/Profile/views/AdvancedView.qml
Original file line number Diff line number Diff line change
Expand Up @@ -354,10 +354,26 @@ SettingsContentBase {
anchors.rightMargin: 0
text: qsTr("Debug")
isSwitch: true
isEnabled: !root.advancedStore.isRuntimeLogLevelSet
switchChecked: root.advancedStore.isDebugEnabled

onClicked: {
Global.openPopup(enableDebugComponent)
}

MouseArea {
id: overlayMouseArea
anchors.fill: parent
enabled: true
hoverEnabled: true
propagateComposedEvents: true
}

StatusToolTip {
text: qsTr("The value is overridden with runtime options")
visible: overlayMouseArea.containsMouse && root.advancedStore.isRuntimeLogLevelSet
delay: 1000
}
}

// TODO: replace with StatusQ component
Expand Down
2 changes: 1 addition & 1 deletion ui/imports/shared/status/StatusSettingsLineButton.qml
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ Rectangle {
anchors.verticalCenter: parent.verticalCenter
text: root.text
font.pixelSize: 15
color: !root.isEnabled ? Style.current.secondaryText : Style.current.textColor
color: Style.current.textColor
}

StyledText {
Expand Down

0 comments on commit 52faea5

Please sign in to comment.