Skip to content

Commit 6d809f7

Browse files
committed
JavaMail log must be written when GeneXus debug is enabled
Issue: 96047
1 parent 19cf896 commit 6d809f7

File tree

2 files changed

+10
-51
lines changed

2 files changed

+10
-51
lines changed

gxmail/src/main/java/com/genexus/internet/POP3SessionJavaMail.java

Lines changed: 5 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,12 @@
66
import java.io.FileOutputStream;
77
import java.io.IOException;
88
import java.io.InputStream;
9-
import java.io.PrintStream;
10-
import java.util.Arrays;
119
import java.util.Enumeration;
1210
import java.util.Hashtable;
1311
import java.util.Properties;
1412

13+
import com.genexus.diagnostics.core.ILogger;
14+
import com.genexus.diagnostics.core.LogManager;
1515
import jakarta.mail.Flags;
1616
import jakarta.mail.Folder;
1717
import jakarta.mail.Header;
@@ -31,9 +31,7 @@
3131

3232
public class POP3SessionJavaMail implements GXInternetConstants,IPOP3Session
3333
{
34-
35-
static private boolean DEBUG = GXInternetConstants.DEBUG;
36-
static private PrintStream logOutput;
34+
public static final ILogger logger = LogManager.getLogger(POP3SessionJavaMail.class);
3735

3836
private String user;
3937
private String password;
@@ -57,21 +55,6 @@ public class POP3SessionJavaMail implements GXInternetConstants,IPOP3Session
5755
Message[] messages;
5856
POP3Folder emailFolder;
5957

60-
static
61-
{
62-
if (DEBUG)
63-
{
64-
try
65-
{
66-
logOutput = new PrintStream(new FileOutputStream(new File("_gx_pop3.log"), true));
67-
}
68-
catch (IOException e)
69-
{
70-
System.out.println("Can't open POP3 log file pop3.log");
71-
}
72-
}
73-
}
74-
7558
public POP3SessionJavaMail()
7659
{
7760
}
@@ -101,10 +84,9 @@ public void login(GXPOP3Session sessionInfo)
10184
props.setProperty("mail.pop3.ssl.enable", String.valueOf(secureConnection));
10285

10386
session = Session.getInstance(props);
104-
if (DEBUG)
87+
if (logger.isDebugEnabled())
10588
{
10689
session.setDebug(true);
107-
session.setDebugOut(logOutput);
10890
}
10991
try
11092
{
@@ -407,8 +389,6 @@ public void setAttachmentsPath(String _attachmentsPath)
407389

408390
private void log(String text)
409391
{
410-
if (DEBUG)
411-
if (logOutput != null)
412-
logOutput.println(text);
392+
logger.debug(text);
413393
}
414394
}

gxmail/src/main/java/com/genexus/internet/SMTPSessionJavaMail.java

Lines changed: 5 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -8,15 +8,15 @@
88
import jakarta.mail.internet.MimeMultipart;
99

1010
import com.genexus.CommonUtil;
11+
import com.genexus.diagnostics.core.ILogger;
12+
import com.genexus.diagnostics.core.LogManager;
1113

1214
import jakarta.mail.internet.MimeBodyPart;
1315
import jakarta.activation.*;
1416

1517
public final class SMTPSessionJavaMail implements GXInternetConstants,ISMTPSession
1618
{
17-
static private boolean DEBUG = GXInternetConstants.DEBUG;
18-
19-
static private PrintStream logOutput;
19+
public static final ILogger logger = LogManager.getLogger(SMTPSessionJavaMail.class);
2020

2121
protected String host;
2222
protected int port;
@@ -36,21 +36,6 @@ public final class SMTPSessionJavaMail implements GXInternetConstants,ISMTPSessi
3636
private Session session;
3737
private Transport t;
3838
MimeMessage mailMessage;
39-
40-
static
41-
{
42-
if (DEBUG)
43-
{
44-
try
45-
{
46-
logOutput = new PrintStream(new FileOutputStream(new File("_gx_smtp.log"), true));
47-
}
48-
catch (IOException e)
49-
{
50-
System.out.println("Can't open SMTP log file smtp.log");
51-
}
52-
}
53-
}
5439

5540
public SMTPSessionJavaMail()
5641
{
@@ -96,10 +81,9 @@ public void login(GXSMTPSession sessionInfo, boolean useTLS)
9681
props.setProperty("mail.smtp.user", user);
9782
}
9883
session = Session.getInstance(props);
99-
if (DEBUG)
84+
if (logger.isDebugEnabled())
10085
{
10186
session.setDebug(true);
102-
session.setDebugOut(logOutput);
10387
}
10488
try
10589
{
@@ -287,11 +271,6 @@ public void setAttachments(String attachments)
287271

288272
protected void log(String text)
289273
{
290-
if (DEBUG)
291-
if (logOutput != null)
292-
{
293-
logOutput.println(text);
294-
logOutput.flush();
295-
}
274+
logger.debug(text);
296275
}
297276
}

0 commit comments

Comments
 (0)