Skip to content

Commit 7b4091f

Browse files
feat(logging): migrate to SLF4J/logback (#3)
* feat(logging): migrate to SLF4J/logback - Replace custom Debug/logger implementations with SLF4J - Add centralized ErrorHandler with dialog - Configure Logback with file rotation * feat(logging): switch to JSON logs with logstash-logback-encoder Migrated from plain text to structured JSON logging using logstash-logback-encoder. Simplified logback.xml, added colored console output, and enabled JSON files for structured logs. * docs(logging): update README with new NDJSON log format configuration Updates documentation to reflect the switch from plain text to NDJSON logging format. --------- Co-authored-by: Riccardo Bertelli <riccardo@codetotime.com>
1 parent b220534 commit 7b4091f

22 files changed

+643
-374
lines changed

README.md

Lines changed: 59 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,15 @@
33
EPPClient è un'applicazione desktop Java per l'interazione con i server EPP (Extensible Provisioning Protocol) del Registro .it, a supporto dei Registrar nella gestione di domini, contatti e messaggi EPP. Fornisce un'interfaccia grafica e strumenti idonei alle principali operazioni di registrazione e mantenimento.
44

55
## Cos'è e a cosa serve
6+
67
- Gestione dei domini .it tramite EPP (creazione, aggiornamento, trasferimento, ecc.).
78
- Gestione della rubrica contatti e della messaggistica EPP.
89
- Funzionalità operative a supporto dell'attività quotidiana del Registrar.
910

1011
## Origini del progetto
12+
1113
Il progetto nasce come rimodernizzazione del software originale sviluppato dall'associazione [AssoTLD](https://www.assotld.it/) per i propri soci. Il software è stato aggiornato e rilasciato come software libero, con l'aggiunta di varie funzionalità, tra cui il supporto a DNSSEC, la gestione dei domini .gov.it e .edu.it e l'esportazione del database in formato CSV, oltre all'aggiornamento di tutte le dipendenze obsolete.
14+
1215
## Licenze
1316

1417
- Le informazioni dettagliate sono disponibili nella cartella `LICENSES/` alla radice del progetto e nel file `REUSE.toml` (convenzioni [REUSE](https://reuse.software/)).
@@ -31,16 +34,21 @@ Il nome esatto del JAR da utilizzare è indicato nel file `build.gradle` alla se
3134
Per la compilazione e l'esecuzione in ambiente di sviluppo si utilizza Gradle.
3235

3336
### Requisiti
37+
3438
- Java 21
3539

3640
### Esecuzione in sviluppo
41+
3742
Per avviare l'applicazione direttamente tramite Gradle, eseguire:
43+
3844
```bash
3945
./gradlew run
4046
```
4147

4248
### Compilazione
49+
4350
Per compilare il progetto senza eseguirlo:
51+
4452
```bash
4553
./gradlew build
4654
```
@@ -52,24 +60,62 @@ Per compilare il progetto senza eseguirlo:
5260
Il "fat jar" è un file JAR che include tutte le dipendenze necessarie per eseguire l'applicazione in modo autonomo.
5361

5462
### Generazione del Jar eseguibile
63+
5564
Per generare il fat jar, eseguire il comando:
65+
5666
```bash
5767
./gradlew shadowJar
5868
```
69+
5970
Al termine, il file generato sarà disponibile nella cartella:
6071
`build/libs/`
6172

6273
Il nome del file sarà simile a:
6374
`eppclient-<versione>-all.jar`
6475

65-
(Esempio: `eppclient-2.3.1-SNAPSHOT-all.jar`)
76+
(Esempio: `eppclient-2.3.1-all.jar`)
6677

6778
### Esecuzione del Fat Jar
79+
6880
Per eseguire l'applicazione utilizzare il comando `java -jar`:
81+
6982
```bash
7083
java -jar build/libs/eppclient-<versione>-all.jar
7184
```
72-
*(Verificare il nome del file generato presente nella cartella build/libs)*
85+
86+
_(Verificare il nome del file generato presente nella cartella build/libs)_
87+
88+
---
89+
90+
## Opzioni di log e debug
91+
92+
L'applicazione registra i messaggi sia su console che su file simultaneamente. Il livello di log predefinito è `INFO`.
93+
94+
### Configurazione del livello di log
95+
96+
Per cambiare il livello di log, utilizzare il flag `-Deppclient.logLevel`:
97+
98+
```bash
99+
java -Deppclient.logLevel=DEBUG -jar build/libs/eppclient-<versione>-all.jar
100+
```
101+
102+
### Logging su file (NDJSON)
103+
104+
I log vengono salvati in formato NDJSON nel file `logs/eppclient.log` con rotazione giornaliera (mantenuti per un massimo di 30 giorni).
105+
Questo formato strutturato include i campi: `timestamp`, `loglevel`, `logger`, `message`, `thread`, `stackTrace`.
106+
107+
### Livelli di log disponibili
108+
109+
- `ERROR` - Solo errori
110+
- `WARN` - Warning e errori
111+
- `INFO` - Info, warning e errori
112+
- `DEBUG` - Messaggi di debug completi
113+
- `TRACE` - Trace dettagliato
114+
- `OFF` - Disabilita il logging
115+
116+
### Visualizzatore log integrato
117+
118+
Quando il debug logging è abilitato, appare automaticamente il pulsante "Apri Log" nella schermata principale che apre il visualizzatore dei log con filtro per livello.
73119

74120
---
75121

@@ -98,18 +144,23 @@ Il progetto Derby è stato abbandonato nel 2025. Per il momento si è deciso di
98144
## Software Bill of Materials (SBOM)
99145

100146
Componenti e versioni principali attualmente in uso (si veda `build.gradle`):
101-
- org.apache.xmlbeans:xmlbeans:3.1.0
102-
- org.apache.httpcomponents:httpclient:4.5.14
103-
- org.apache.httpcomponents:httpcore:4.4.16
104-
- epp-client-cmd-line:1.19.1 (Fornito dal Registro .it, JAR locale da collocare in `libs/`)
147+
148+
- ch.qos.logback:logback-classic:1.5.32
149+
- ch.qos.logback:logback-core:1.5.32
150+
- com.google.code.gson:gson:2.13.2
151+
- com.mysql:mysql-connector-j:9.6.0
105152
- org.apache.derby:derby:10.17.1.0
106153
- org.apache.derby:derbytools:10.17.1.0
154+
- org.apache.httpcomponents:httpclient:4.5.14
155+
- org.apache.httpcomponents:httpcore:4.4.16
156+
- org.apache.xmlbeans:xmlbeans:3.1.0
157+
- net.logstash.logback:logstash-logback-encoder:9.0
107158
- org.slf4j:slf4j-api:2.0.17
108-
- org.slf4j:slf4j-simple:2.0.17
109-
- com.google.code.gson:gson:2.13.2
159+
- epp-client-cmd-line:1.19.1 (Fornito dal Registro .it, JAR locale da collocare in `libs/`)
110160
- test: org.junit:junit-bom:5.10.0; org.junit.jupiter:junit-jupiter
111161

112162
Runtime/Build:
163+
113164
- Java 21
114165

115166
---

build.gradle

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -24,16 +24,18 @@ repositories {
2424
}
2525

2626
dependencies {
27-
implementation('org.apache.xmlbeans:xmlbeans:3.1.0')
28-
implementation('org.apache.httpcomponents:httpclient:4.5.14')
29-
implementation('org.apache.httpcomponents:httpcore:4.4.16')
30-
implementation(files('libs/epp-client-cmd-line-1.19.1.jar'))
27+
implementation('ch.qos.logback:logback-classic:1.5.32')
28+
implementation('ch.qos.logback:logback-core:1.5.32')
29+
implementation('com.google.code.gson:gson:2.13.2')
30+
implementation('org.mariadb.jdbc:mariadb-java-client:3.5.7')
3131
implementation('org.apache.derby:derby:10.17.1.0')
3232
implementation('org.apache.derby:derbytools:10.17.1.0')
33+
implementation('org.apache.httpcomponents:httpclient:4.5.14')
34+
implementation('org.apache.httpcomponents:httpcore:4.4.16')
35+
implementation('org.apache.xmlbeans:xmlbeans:3.1.0')
36+
implementation('net.logstash.logback:logstash-logback-encoder:9.0')
3337
implementation('org.slf4j:slf4j-api:2.0.17')
34-
implementation('org.slf4j:slf4j-simple:2.0.17')
35-
implementation('com.google.code.gson:gson:2.13.2')
36-
implementation('org.mariadb.jdbc:mariadb-java-client:3.5.7')
38+
implementation(files('libs/epp-client-cmd-line-1.19.1.jar'))
3739

3840
testImplementation platform('org.junit:junit-bom:5.10.0')
3941
testImplementation 'org.junit.jupiter:junit-jupiter'
@@ -104,4 +106,4 @@ jar {
104106
manifest {
105107
attributes('Main-Class': application.mainClass)
106108
}
107-
}
109+
}
Lines changed: 93 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,93 @@
1+
/*
2+
*
3+
* SPDX-License-Identifier: GPL-3.0-or-later
4+
*
5+
* This file is part of EPPClient.
6+
*
7+
* 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.
8+
*
9+
* 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.
10+
*
11+
* You should have received a copy of the GNU General Public License along with EPPClient. If not, see <https://www.gnu.org/licenses/>.
12+
*/
13+
14+
package EPPClient;
15+
16+
import java.awt.Component;
17+
import javax.swing.JDialog;
18+
import javax.swing.JFrame;
19+
import javax.swing.JOptionPane;
20+
import org.slf4j.Logger;
21+
22+
/**
23+
* Centralized error handling utility class.
24+
* Provides dialog display for errors - logging is done directly via SLF4J.
25+
*/
26+
public class ErrorHandler
27+
{
28+
29+
/**
30+
* Default message shown to users when an error occurs.
31+
*/
32+
public static final String DEFAULT_USER_MESSAGE = "Si è verificato un errore durante l'operazione.\n\n" + "Consultare i log per maggiori dettagli.";
33+
34+
/**
35+
* Logs an error and shows a dialog to the user.
36+
* The exception is logged at ERROR level with full stack trace.
37+
*
38+
* @param logger The SLF4J logger instance
39+
* @param exception The exception that occurred
40+
* @param userTitle The title for the error dialog
41+
* @param parent The parent frame for the dialog
42+
*/
43+
public static void error(Logger logger, Exception exception, String userTitle, JFrame parent)
44+
{
45+
logger.error("Error occurred: {}", exception.getMessage(), exception);
46+
showErrorDialog(parent, userTitle);
47+
}
48+
49+
/**
50+
* Logs an error without showing a dialog.
51+
*
52+
* @param logger The SLF4J logger instance
53+
* @param exception The exception that occurred
54+
*/
55+
public static void logError(Logger logger, Exception exception)
56+
{
57+
logger.error("Error occurred: {}", exception.getMessage(), exception);
58+
}
59+
60+
/**
61+
* Shows an error dialog to the user
62+
*
63+
* @param parent The parent component for the dialog
64+
* @param title The title of the dialog
65+
*/
66+
public static void showErrorDialog(Component parent, String title, String message) {
67+
JOptionPane optionPane = new JOptionPane(
68+
message,
69+
JOptionPane.ERROR_MESSAGE,
70+
JOptionPane.DEFAULT_OPTION,
71+
null,
72+
new Object[]{"OK"},
73+
"OK"
74+
);
75+
76+
JDialog dialog = optionPane.createDialog(parent, title);
77+
dialog.setResizable(false);
78+
dialog.setVisible(true);
79+
dialog.dispose();
80+
}
81+
82+
/**
83+
* Shows an error dialog to the user with the default message.
84+
* Delegates to {@link #showErrorDialog(Component, String, String)}.
85+
*
86+
* @param parent The parent component for the dialog
87+
* @param title The title of the dialog
88+
*/
89+
public static void showErrorDialog(Component parent, String title)
90+
{
91+
showErrorDialog(parent, title, DEFAULT_USER_MESSAGE);
92+
}
93+
}

src/main/java/EPPClient/UpdateChecker.java

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,9 +27,13 @@
2727
import java.net.URL;
2828
import java.util.ArrayList;
2929
import java.util.List;
30+
import org.slf4j.Logger;
31+
import org.slf4j.LoggerFactory;
3032

3133
public class UpdateChecker {
3234

35+
private static final Logger log = LoggerFactory.getLogger(UpdateChecker.class);
36+
3337
private static final String GITHUB_API_URL = "https://api.github.com/repos/CodeToTime/EPPClient/releases";
3438

3539
public static void checkForUpdates(Component parent, String currentVersion) {
@@ -46,7 +50,7 @@ public static void checkForUpdates(Component parent, String currentVersion) {
4650
}
4751
} catch (Exception e) {
4852
// Silenziosamente ignora errori di rete
49-
System.err.println("Errore durante il controllo aggiornamenti: " + e.getMessage());
53+
log.warn("Errore durante il controllo aggiornamenti: {}", e.getMessage());
5054
}
5155
}).start();
5256
}

0 commit comments

Comments
 (0)