#1874 Introduce individual ConsoleLogger instance per class (#1875)

* #1874 Introduce individual ConsoleLogger instance per class
- Create ConsoleLoggerFactory from which a separate logger can be created for each class
- Allows to support individual log level settings in the future

* Fix CodeStyle issue

* Replace full class name with import

* Update usages after merge from master
This commit is contained in:
ljacqu
2019-08-06 15:15:16 +02:00
committed by Gabriele C
parent 254d4d75a2
commit c34f00f759
98 changed files with 853 additions and 387 deletions
@@ -2,6 +2,7 @@ package fr.xephi.authme.mail;
import fr.xephi.authme.ConsoleLogger;
import fr.xephi.authme.initialization.DataFolder;
import fr.xephi.authme.output.ConsoleLoggerFactory;
import fr.xephi.authme.settings.Settings;
import fr.xephi.authme.settings.properties.EmailSettings;
import fr.xephi.authme.settings.properties.PluginSettings;
@@ -22,6 +23,8 @@ import java.io.IOException;
*/
public class EmailService {
private final ConsoleLogger logger = ConsoleLoggerFactory.get(EmailService.class);
private final File dataFolder;
private final Settings settings;
private final SendMailSsl sendMailSsl;
@@ -48,7 +51,7 @@ public class EmailService {
*/
public boolean sendPasswordMail(String name, String mailAddress, String newPass) {
if (!hasAllInformation()) {
ConsoleLogger.warning("Cannot perform email registration: not all email settings are complete");
logger.warning("Cannot perform email registration: not all email settings are complete");
return false;
}
@@ -56,7 +59,7 @@ public class EmailService {
try {
email = sendMailSsl.initializeMail(mailAddress);
} catch (EmailException e) {
ConsoleLogger.logException("Failed to create email with the given settings:", e);
logger.logException("Failed to create email with the given settings:", e);
return false;
}
@@ -68,7 +71,7 @@ public class EmailService {
file = generatePasswordImage(name, newPass);
mailText = embedImageIntoEmailContent(file, email, mailText);
} catch (IOException | EmailException e) {
ConsoleLogger.logException(
logger.logException(
"Unable to send new password as image for email " + mailAddress + ":", e);
}
}
@@ -88,7 +91,7 @@ public class EmailService {
*/
public boolean sendVerificationMail(String name, String mailAddress, String code) {
if (!hasAllInformation()) {
ConsoleLogger.warning("Cannot send verification email: not all email settings are complete");
logger.warning("Cannot send verification email: not all email settings are complete");
return false;
}
@@ -96,7 +99,7 @@ public class EmailService {
try {
email = sendMailSsl.initializeMail(mailAddress);
} catch (EmailException e) {
ConsoleLogger.logException("Failed to create verification email with the given settings:", e);
logger.logException("Failed to create verification email with the given settings:", e);
return false;
}
@@ -118,7 +121,7 @@ public class EmailService {
try {
htmlEmail = sendMailSsl.initializeMail(email);
} catch (EmailException e) {
ConsoleLogger.logException("Failed to create email for recovery code:", e);
logger.logException("Failed to create email for recovery code:", e);
return false;
}
@@ -1,6 +1,7 @@
package fr.xephi.authme.mail;
import fr.xephi.authme.ConsoleLogger;
import fr.xephi.authme.output.ConsoleLoggerFactory;
import fr.xephi.authme.output.LogLevel;
import fr.xephi.authme.settings.Settings;
import fr.xephi.authme.settings.properties.EmailSettings;
@@ -26,6 +27,8 @@ import static fr.xephi.authme.settings.properties.EmailSettings.MAIL_PASSWORD;
*/
public class SendMailSsl {
private ConsoleLogger logger = ConsoleLoggerFactory.get(SendMailSsl.class);
@Inject
private Settings settings;
@@ -96,14 +99,14 @@ public class SendMailSsl {
email.setHtmlMsg(content);
email.setTextMsg(content);
} catch (EmailException e) {
ConsoleLogger.logException("Your email.html config contains an error and cannot be sent:", e);
logger.logException("Your email.html config contains an error and cannot be sent:", e);
return false;
}
try {
email.send();
return true;
} catch (EmailException e) {
ConsoleLogger.logException("Failed to send a mail to " + email.getToAddresses() + ":", e);
logger.logException("Failed to send a mail to " + email.getToAddresses() + ":", e);
return false;
}
}