-
Notifications
You must be signed in to change notification settings - Fork 3
feat(logging): migrate to SLF4J/logback #3
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
Merged
Merged
Changes from 10 commits
Commits
Show all changes
14 commits
Select commit
Hold shift + click to select a range
4cfa977
feat(debug): add Debug utility class
matteotrubini 85dba4c
feat(logging): migrate to SLF4J/logback and add log viewer
matteotrubini 43ca3ed
Merge branch 'main' into feat/debug
matteotrubini c34ac61
Merge branch 'main' into feat/debug
matteotrubini 1545724
chore: remove copyright headers from source files
matteotrubini d6650e6
feat(logging): switch to JSON logs with logstash-logback-encoder
matteotrubini 27728d9
docs(logging): update README with new NDJSON log format configuration
matteotrubini a5c90db
feat(error-handler): replace restart-with-debug with log viewer
matteotrubini 3a6d34f
docs: remove outdated section from README
matteotrubini 0b9496a
chore: remove dead code
matteotrubini b35607b
revert: stylistic-only changes introduced in 85dba4c
matteotrubini 1e76bad
docs(error-handler): remove outdated error handling docs from Javadoc
matteotrubini 6eda294
refactor(error-handler): simplify IOException handling
matteotrubini 8339051
Remove LogViewer and simplify error dialogs
bicodrex 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
|
matteotrubini marked this conversation as resolved.
|
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,129 @@ | ||
| /* | ||
| * | ||
| * SPDX-License-Identifier: GPL-3.0-or-later | ||
| * | ||
| * This file is part of EPPClient. | ||
| * | ||
| * EPPClient is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. | ||
| * | ||
| * EPPClient is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. | ||
| * | ||
| * You should have received a copy of the GNU General Public License along with EPPClient. If not, see <https://www.gnu.org/licenses/>. | ||
| */ | ||
|
|
||
| package EPPClient; | ||
|
|
||
| import java.awt.Component; | ||
| import javax.swing.JButton; | ||
| import javax.swing.JDialog; | ||
| import javax.swing.JFrame; | ||
| import javax.swing.JOptionPane; | ||
| import javax.swing.SwingUtilities; | ||
| import org.slf4j.Logger; | ||
|
|
||
| /** | ||
| * Centralized error handling utility class. | ||
| * Provides dialog display for errors - logging is done directly via SLF4J. | ||
| * | ||
| * The user receives a generic error message and is invited to view the log file for detailed information. | ||
| * | ||
| * File logging is controlled by system property -Deppclient.logLevel | ||
| * Console output for errors can be enabled with -Deppclient.console=true | ||
|
matteotrubini marked this conversation as resolved.
Outdated
|
||
| */ | ||
| public class ErrorHandler | ||
| { | ||
|
|
||
| /** | ||
| * Default message shown to users when an error occurs. | ||
| */ | ||
| public static final String DEFAULT_USER_MESSAGE = "Si è verificato un errore durante l'operazione.\n\n" + "Clicca \"Visualizza log\" per aprire il visualizzatore dei log.\n\n" + "Consultare i file di log per maggiori dettagli."; | ||
|
|
||
| /** | ||
| * Logs an error and shows a dialog to the user. | ||
| * The exception is logged at ERROR level with full stack trace. | ||
| * | ||
| * @param logger The SLF4J logger instance | ||
| * @param exception The exception that occurred | ||
| * @param userTitle The title for the error dialog | ||
| * @param parent The parent frame for the dialog | ||
| */ | ||
| public static void error(Logger logger, Exception exception, String userTitle, JFrame parent) | ||
| { | ||
| logger.error("Error occurred: {}", exception.getMessage(), exception); | ||
| showErrorDialog(parent, userTitle); | ||
| } | ||
|
|
||
| /** | ||
| * Logs an error without showing a dialog. | ||
| * | ||
| * @param logger The SLF4J logger instance | ||
| * @param exception The exception that occurred | ||
| */ | ||
| public static void logError(Logger logger, Exception exception) | ||
| { | ||
| logger.error("Error occurred: {}", exception.getMessage(), exception); | ||
| } | ||
|
|
||
| /** | ||
| * Shows an error dialog to the user with the default message. | ||
| * | ||
| * @param parent The parent component for the dialog | ||
| * @param title The title of the dialog | ||
| */ | ||
| public static void showErrorDialog(java.awt.Component parent, String title) | ||
| { | ||
| showErrorDialogWithLogViewer(parent, title, DEFAULT_USER_MESSAGE); | ||
| } | ||
|
|
||
| /** | ||
| * Shows an error dialog with a "Show logs" button that opens the LogViewer. | ||
| * | ||
| * @param parent The parent component for the dialog | ||
| * @param title The title of the dialog | ||
| * @param message The message to display | ||
| */ | ||
| private static void showErrorDialogWithLogViewer(Component parent, String title, String message) | ||
| { | ||
| // Create buttons: OK and View Log | ||
| JButton viewLogButton = new JButton("Visualizza log"); | ||
| viewLogButton.setFocusPainted(false); | ||
|
|
||
| // Create option pane with custom buttons | ||
| JOptionPane optionPane = new JOptionPane(message, JOptionPane.ERROR_MESSAGE, JOptionPane.OK_CANCEL_OPTION, null, new Object[] | ||
| {viewLogButton, "OK"}, "OK"); | ||
|
|
||
| // Create and configure the dialog | ||
| JDialog dialog = optionPane.createDialog(parent, title); | ||
| dialog.setResizable(false); | ||
|
|
||
| // Handle button click | ||
| viewLogButton.addActionListener(e -> { | ||
| dialog.dispose(); | ||
| openLogViewer(parent); | ||
| }); | ||
|
|
||
| // Show dialog | ||
| dialog.setVisible(true); | ||
| } | ||
|
|
||
| /** | ||
| * Opens the log viewer dialog. | ||
| * | ||
| * @param parent The parent component for the log viewer | ||
| */ | ||
| private static void openLogViewer(Component parent) | ||
| { | ||
| // Get the parent frame for the log viewer | ||
| JFrame frame = null; | ||
| if (parent instanceof JFrame) | ||
| { | ||
| frame = (JFrame) parent; | ||
| } | ||
| else if (parent != null) | ||
| { | ||
| frame = (JFrame) SwingUtilities.getWindowAncestor(parent); | ||
| } | ||
|
|
||
| LogViewer.showLogViewer(frame); | ||
| } | ||
| } | ||
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.