-
Notifications
You must be signed in to change notification settings - Fork 3
feat: allow runtime debugging specific app(s) #908
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
Open
susnux
wants to merge
1
commit into
main
Choose a base branch
from
feat/allow-debug-specific-app
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,86 @@ | ||
| /** | ||
| * SPDX-FileCopyrightText: 2025 Nextcloud GmbH and Nextcloud contributors | ||
| * SPDX-License-Identifier: GPL-3.0-or-later | ||
| */ | ||
|
|
||
| import type { IContext, ILogger } from './contracts.ts' | ||
|
|
||
| import { LogLevel } from './contracts.ts' | ||
|
|
||
| /** | ||
| * Abstract base logger implementing common functionality | ||
| */ | ||
| export abstract class ALogger implements ILogger { | ||
| /** | ||
| * The initial logging context set by the constructor (LoggerBuilder factory) | ||
| */ | ||
| protected abstract context: IContext | ||
|
|
||
| /** | ||
| * Log a message with the specified level and context | ||
| * | ||
| * @param level - The log level requested | ||
| * @param message - The log message | ||
| * @param context - The logging context | ||
| */ | ||
| protected abstract log(level: LogLevel, message: string, context: IContext): void | ||
|
|
||
| public debug(message: string | Error, context?: IContext): void { | ||
| this.logIfNeeded(LogLevel.Debug, message, { ...context, ...this.context }) | ||
| } | ||
|
|
||
| public info(message: string | Error, context?: IContext): void { | ||
| this.logIfNeeded(LogLevel.Info, message, { ...context, ...this.context }) | ||
| } | ||
|
|
||
| public warn(message: string | Error, context?: IContext): void { | ||
| this.logIfNeeded(LogLevel.Warn, message, { ...context, ...this.context }) | ||
| } | ||
|
|
||
| public error(message: string | Error, context?: IContext): void { | ||
| this.logIfNeeded(LogLevel.Error, message, { ...context, ...this.context }) | ||
| } | ||
|
|
||
| public fatal(message: string | Error, context?: IContext): void { | ||
| this.logIfNeeded(LogLevel.Fatal, message, { ...context, ...this.context }) | ||
| } | ||
|
|
||
| /** | ||
| * Check if the message should be logged and prepare the context | ||
| * | ||
| * @param level - The logging level requested | ||
| * @param message - The log message or Error object | ||
| * @param context - The logging context | ||
| */ | ||
| private logIfNeeded(level: LogLevel, message: string | Error, context: IContext): void { | ||
| // Skip if level is configured and this is below the level | ||
| if (typeof this.context?.level === 'number' && level < this.context?.level && !this.debuggingEnabled()) { | ||
| return | ||
| } | ||
|
|
||
| // Handle logging when only an error was passed as log message | ||
| if (typeof message === 'object') { | ||
| if (context.error) { | ||
| context.error = [context.error, message] | ||
| } else { | ||
| context.error = message | ||
| } | ||
| if (level === LogLevel.Debug || this.debuggingEnabled()) { | ||
| context.stacktrace = message.stack | ||
| } | ||
| return this.log(level, `${message.name}: ${message.message}`, context) | ||
| } | ||
|
|
||
| this.log(level, message, context) | ||
| } | ||
|
|
||
| /** | ||
| * Check if debugging is enabled for the current app | ||
| */ | ||
| private debuggingEnabled(): boolean { | ||
| const debugContexts = window.__NC_LOGGER_DEBUG__ | ||
| return typeof this.context.app === 'string' | ||
| && Array.isArray(debugContexts) | ||
| && debugContexts.includes(this.context.app) | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,4 @@ | ||
| { | ||
| "extends": "../tsconfig.json", | ||
| "include": ["../lib", "."] | ||
| } |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Does it mean there is no feature support like in the linked issue, but only per-app support?
So if you want to have a debug flag for a specific feature, you need to call it another app, correct?
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In the issue the proposal was to have an object with boolean flags. It's quite convenient because:
in contrast, with the array of strings:
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Also, why make it a
__BUILD_TIME_CONST__or_private_variable_like and not a public?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Basically the idea is not to break existing loggers and need for refactoring your code base.
But instead allow to selectively enable debug logging for specific apps instead of all apps that would flood the logs.
Reduce risks here to break anything as this is a global variable.
Alternative would be to move to
OCAbut then onlyOCA.Corewould be kind of safe, as other name spaces could be used by an app (e.g. proposedOCA.Loggercould be used by an app calledlogger).There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Was @max-nextcloud proposal breaking?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Like you have to create a new logger that what I meant (as described below I might have a different use case)