Skip to content

Commit

Permalink
chore: re-enable logging in prod version
Browse files Browse the repository at this point in the history
closes: #8932
  • Loading branch information
osmaczko committed Jan 4, 2023
1 parent b8a1c70 commit ce08265
Show file tree
Hide file tree
Showing 5 changed files with 43 additions and 17 deletions.
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -409,7 +409,7 @@ $(FCITX5_QT): | check-qt-dir deps
.. $(HANDLE_OUTPUT) && \
$(FCITX5_QT_BUILD_CMD)

PRODUCTION_PARAMETERS := -d:production -d:chronicles_sinks=textlines[stdout],textlines[nocolors,dynamic]
PRODUCTION_PARAMETERS := -d:production

$(STATUS_CLIENT_APPIMAGE): override RESOURCES_LAYOUT := $(PRODUCTION_PARAMETERS)
$(STATUS_CLIENT_APPIMAGE): nim_status_client $(APPIMAGE_TOOL) nim-status.desktop $(FCITX5_QT)
Expand Down
16 changes: 15 additions & 1 deletion src/app/boot/app_controller.nim
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import NimQml, sequtils, sugar, chronicles
import NimQml, sequtils, sugar, chronicles, os

import ../../app_service/service/general/service as general_service
import ../../app_service/service/keychain/service as keychain_service
Expand Down Expand Up @@ -116,6 +116,15 @@ proc connect(self: AppController) =
# not sure, but maybe we should take some actions when node stops
discard

# Handle runtime log level settings changes
if not existsEnv("LOG_LEVEL"):
self.statusFoundation.events.on(node_configuration_service.SIGNAL_NODE_LOG_LEVEL_UPDATE) do(a: Args):
let args = NodeLogLevelUpdatedArgs(a)
if args.logLevel == LogLevel.DEBUG:
setLogLevel(LogLevel.DEBUG)
elif defined(production):
setLogLevel(LogLevel.INFO)

proc newAppController*(statusFoundation: StatusFoundation): AppController =
result = AppController()
result.storeKeyPair = false
Expand Down Expand Up @@ -345,6 +354,11 @@ proc load(self: AppController) =
self.tokenService.init()
self.walletAccountService.init()

# Apply runtime log level settings
if not existsEnv("LOG_LEVEL"):
if self.nodeConfigurationService.isDebugEnabled():
setLogLevel(LogLevel.DEBUG)

# load main module
self.mainModule.load(
self.statusFoundation.events,
Expand Down
6 changes: 3 additions & 3 deletions src/app/modules/main/profile_section/advanced/controller.nim
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ proc setWakuV2LightClientEnabled*(self: Controller, enabled: bool) =
proc enableDeveloperFeatures*(self: Controller) =
discard self.settingsService.saveTelemetryServerUrl(DEFAULT_TELEMETRY_SERVER_URL)
discard self.settingsService.saveAutoMessageEnabled(true)
discard self.nodeConfigurationService.setDebugLevel(LogLevel.DEBUG)
discard self.nodeConfigurationService.setLogLevel(LogLevel.DEBUG)

quit(QuitSuccess) # quits the app TODO: change this to logout instead when supported

Expand Down Expand Up @@ -104,14 +104,14 @@ proc isAutoMessageEnabled*(self: Controller): bool =
return self.settingsService.autoMessageEnabled()

proc isDebugEnabled*(self: Controller): bool =
return self.nodeConfigurationService.getDebugLevel() == $LogLevel.DEBUG
return self.nodeConfigurationService.isDebugEnabled()

proc toggleDebug*(self: Controller) =
var logLevel = LogLevel.DEBUG
if(self.isDebugEnabled()):
logLevel = LogLevel.INFO

if(not self.nodeConfigurationService.setDebugLevel(logLevel)):
if(not self.nodeConfigurationService.setLogLevel(logLevel)):
# in the future we may do a call from here to show a popup about this error
error "an error occurred, we couldn't toggle debug level"
return
Expand Down
19 changes: 16 additions & 3 deletions src/app_service/service/node_configuration/service.nim
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,12 @@ const BLOOM_LEVEL_NORMAL* = "normal"
const BLOOM_LEVEL_FULL* = "full"
const BLOOM_LEVEL_LIGHT* = "light"

const SIGNAL_NODE_LOG_LEVEL_UPDATE* = "nodeLogLevelUpdated"

type
NodeLogLevelUpdatedArgs* = ref object of Args
logLevel*: LogLevel

type
ErrorArgs* = ref object of Args
msg*: string
Expand Down Expand Up @@ -244,13 +250,20 @@ proc setV2LightMode*(self: Service, enabled: bool): bool =
newConfiguration.WakuV2Config.LightClient = enabled
return self.saveConfiguration(newConfiguration)

proc getDebugLevel*(self: Service): string =
proc getLogLevel(self: Service): string =
return self.configuration.LogLevel

proc setDebugLevel*(self: Service, logLevel: LogLevel): bool =
proc isDebugEnabled*(self: Service): bool =
return self.getLogLevel() == $LogLevel.DEBUG

proc setLogLevel*(self: Service, logLevel: LogLevel): bool =
var newConfiguration = self.configuration
newConfiguration.LogLevel = $logLevel
return self.saveConfiguration(newConfiguration)
if self.saveConfiguration(newConfiguration):
self.events.emit(SIGNAL_NODE_LOG_LEVEL_UPDATE, NodeLogLevelUpdatedArgs(logLevel: logLevel))
return true
else:
return false

proc isV2LightMode*(self: Service): bool =
return self.configuration.WakuV2Config.LightClient
Expand Down
17 changes: 8 additions & 9 deletions src/nim_status_client.nim
Original file line number Diff line number Diff line change
Expand Up @@ -52,17 +52,16 @@ proc prepareLogging() =
except:
logLoggingFailure(cstring(msg), getCurrentException())

# do not create log file
when not defined(production):
# log level can be overriden by LOG_LEVEL env parameter
let logLvl = try: parseEnum[LogLevel](getEnv("LOG_LEVEL"))
except: NONE
let defaultLogLvl = if defined(production): LogLevel.INFO else: LogLevel.DEBUG
# default log level can be overriden by LOG_LEVEL env parameter
let logLvl = try: parseEnum[LogLevel](getEnv("LOG_LEVEL"))
except: defaultLogLvl

setLogLevel(logLvl)
setLogLevel(logLvl)

let formattedDate = now().format("yyyyMMdd'_'HHmmss")
let logFile = fmt"app_{formattedDate}.log"
discard defaultChroniclesStream.outputs[1].open(LOGDIR & logFile, fmAppend)
let formattedDate = now().format("yyyyMMdd'_'HHmmss")
let logFile = fmt"app_{formattedDate}.log"
discard defaultChroniclesStream.outputs[1].open(LOGDIR & logFile, fmAppend)

proc setupRemoteSignalsHandling() =
# Please note that this must use the `cdecl` calling convention because
Expand Down

0 comments on commit ce08265

Please sign in to comment.