Top Description Fields Constructors Methods
jakarta.mail

pack-priv final Class MailLogger

extends Object
Class Inheritance
Imports
java.io.PrintStream, java.text.MessageFormat, java.util.logging.Level, .Logger

A simplified logger used by Jakarta Mail to handle logging to a PrintStream and logging through a java.util.logging.Logger. If debug is set, messages are written to the PrintStream and prefixed by the specified prefix (which is not included in Logger messages). Messages are logged by the Logger based on the configuration of the logging system.

Field Summary

Modifier and TypeField and Description
private final boolean
debug

Produce debug output?

private final Logger
logger

For log messages.

private final PrintStream
out

Stream for debug output.

private final String
prefix

For debug output.

Constructor Summary

AccessConstructor and Description
public
MailLogger(String
the Logger name
name
,
String
the prefix for debug output, or null for none
prefix
,
boolean
if true, write to PrintStream
debug
,
PrintStream
the PrintStream to write to
out
)

Construct a new MailLogger using the specified Logger name, debug prefix (e.g., "DEBUG"), debug flag, and PrintStream.

public
MailLogger(Class<?>
the Logger name is the package name of this class
clazz
,
String
the prefix for debug output, or null for none
prefix
,
boolean
if true, write to PrintStream
debug
,
PrintStream
the PrintStream to write to
out
)

Construct a new MailLogger using the specified class' package name as the Logger name, debug prefix (e.g., "DEBUG"), debug flag, and PrintStream.

public
MailLogger(Class<?>
the Logger name is the package name of this class
clazz
,
String
the Logger name relative to this Logger name
subname
,
String
the prefix for debug output, or null for none
prefix
,
boolean
if true, write to PrintStream
debug
,
PrintStream
the PrintStream to write to
out
)

Construct a new MailLogger using the specified class' package name combined with the specified subname as the Logger name, debug prefix (e.g., "DEBUG"), debug flag, and PrintStream.

public
MailLogger(String
the Logger name
name
,
String
the prefix for debug output, or null for none
prefix
,
Session
where to get the debug flag and PrintStream
session
)
Deprecated

Construct a new MailLogger using the specified Logger name and debug prefix (e.g., "DEBUG").

public
MailLogger(Class<?>
the Logger name is the package name of this class
clazz
,
String
the prefix for debug output, or null for none
prefix
,
Session
where to get the debug flag and PrintStream
session
)
Deprecated

Construct a new MailLogger using the specified class' package name as the Logger name and the specified debug prefix (e.g., "DEBUG").

Method Summary

Modifier and TypeMethod and Description
public void
config(String
the message.
msg
)

Log a message at the CONFIG level.

private void
debugOut(String
the message to log.
msg
)

Common formatting for debug output.

public void
fine(String
the message.
msg
)

Log a message at the FINE level.

public void
finer(String
the message.
msg
)

Log a message at the FINER level.

public void
finest(String
the message.
msg
)

Log a message at the FINEST level.

public MailLogger

Returns:

a MailLogger for the given name and prefix.
getLogger
(String
the Logger name
name
,
String
the prefix for debug output, or null for none
prefix
)

Create a MailLogger that uses a Logger with the specified name and prefix.

public MailLogger

Returns:

a MailLogger for the given name and prefix.
getLogger
(Class<?>
the Logger name is the package name of this class
clazz
,
String
the prefix for debug output, or null for none
prefix
)

Create a MailLogger using the specified class' package name as the Logger name and the specified prefix.

public MailLogger

Returns:

a MailLogger for the given name and prefix.
getSubLogger
(String
the Logger name relative to this Logger name
subname
,
String
the prefix for debug output, or null for none
prefix
)

Create a MailLogger that uses a Logger whose name is composed of this MailLogger's name plus the specified sub-name, separated by a dot.

public MailLogger

Returns:

a MailLogger for the given name and prefix.
getSubLogger
(String
the Logger name relative to this Logger name
subname
,
String
the prefix for debug output, or null for none
prefix
,
boolean
the debug flag for the sub-logger
debug
)

Create a MailLogger that uses a Logger whose name is composed of this MailLogger's name plus the specified sub-name, separated by a dot.

private void
ifDebugOut(String
the message to log.
msg
)

Common code to conditionally log debug statements.

private StackTraceElement

Returns:

StackTraceElement that logged the message. Treat as read-only.
inferCaller
()

A disadvantage of not being able to use Logger directly in Jakarta Mail code is that the "source class" information that Logger guesses will always refer to this class instead of our caller.

public boolean

Returns:

true if loggable.
isLoggable
(Level
the log level.
level
)

If "debug" is set, or our embedded Logger is loggable at the given level, return true.

private boolean

Returns:

true if the class name is part of the MailLogger bridge.
isLoggerImplFrame
(String
the class name.
cname
)

Frames to ignore as part of the MailLogger to JUL bridge.

public void
log(Level
the log level.
level
,
String
the message.
msg
)

Log the message at the specified level.

public void
log(Level
the log level.
level
,
String
the message.
msg
,
Object
the additional parameter.
param1
)

Log the message at the specified level.

public void
log(Level
the log level.
level
,
String
the message.
msg
,
Object...
the message parameters.
params
)

Log the message at the specified level.

public void
log(Level
the log level.
level
,
String
the message.
msg
,
Throwable
the throwable to log.
thrown
)

Log the message at the specified level.

public void
logf(Level
the log level.
level
,
String
the message format string.
msg
,
Object...
the message parameters.
params
)

Log the message at the specified level using a format string.

private String

Returns:

the package name or an empty string.
packageOf
(Class<?>
the class source.
clazz
)

Return the package name of the class.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

debugback to summary
private final boolean debug

Produce debug output?

loggerback to summary
private final Logger logger

For log messages.

outback to summary
private final PrintStream out

Stream for debug output.

prefixback to summary
private final String prefix

For debug output.

Constructor Detail

MailLoggerback to summary
public MailLogger(String name, String prefix, boolean debug, PrintStream out)

Construct a new MailLogger using the specified Logger name, debug prefix (e.g., "DEBUG"), debug flag, and PrintStream.

Parameters
name:String

the Logger name

prefix:String

the prefix for debug output, or null for none

debug:boolean

if true, write to PrintStream

out:PrintStream

the PrintStream to write to

MailLoggerback to summary
public MailLogger(Class<?> clazz, String prefix, boolean debug, PrintStream out)

Construct a new MailLogger using the specified class' package name as the Logger name, debug prefix (e.g., "DEBUG"), debug flag, and PrintStream.

Parameters
clazz:Class<?>

the Logger name is the package name of this class

prefix:String

the prefix for debug output, or null for none

debug:boolean

if true, write to PrintStream

out:PrintStream

the PrintStream to write to

MailLoggerback to summary
public MailLogger(Class<?> clazz, String subname, String prefix, boolean debug, PrintStream out)

Construct a new MailLogger using the specified class' package name combined with the specified subname as the Logger name, debug prefix (e.g., "DEBUG"), debug flag, and PrintStream.

Parameters
clazz:Class<?>

the Logger name is the package name of this class

subname:String

the Logger name relative to this Logger name

prefix:String

the prefix for debug output, or null for none

debug:boolean

if true, write to PrintStream

out:PrintStream

the PrintStream to write to

MailLoggerback to summary
public MailLogger(String name, String prefix, Session session)

Deprecated

Construct a new MailLogger using the specified Logger name and debug prefix (e.g., "DEBUG"). Get the debug flag and PrintStream from the Session.

Parameters
name:String

the Logger name

prefix:String

the prefix for debug output, or null for none

session:Session

where to get the debug flag and PrintStream

Annotations
@Deprecated
MailLoggerback to summary
public MailLogger(Class<?> clazz, String prefix, Session session)

Deprecated

Construct a new MailLogger using the specified class' package name as the Logger name and the specified debug prefix (e.g., "DEBUG"). Get the debug flag and PrintStream from the Session.

Parameters
clazz:Class<?>

the Logger name is the package name of this class

prefix:String

the prefix for debug output, or null for none

session:Session

where to get the debug flag and PrintStream

Annotations
@Deprecated

Method Detail

configback to summary
public void config(String msg)

Log a message at the CONFIG level.

Parameters
msg:String

the message.

debugOutback to summary
private void debugOut(String msg)

Common formatting for debug output.

Parameters
msg:String

the message to log.

fineback to summary
public void fine(String msg)

Log a message at the FINE level.

Parameters
msg:String

the message.

finerback to summary
public void finer(String msg)

Log a message at the FINER level.

Parameters
msg:String

the message.

finestback to summary
public void finest(String msg)

Log a message at the FINEST level.

Parameters
msg:String

the message.

getLoggerback to summary
public MailLogger getLogger(String name, String prefix)

Create a MailLogger that uses a Logger with the specified name and prefix. The new MailLogger uses the same debug flag and PrintStream as this MailLogger.

Parameters
name:String

the Logger name

prefix:String

the prefix for debug output, or null for none

Returns:MailLogger

a MailLogger for the given name and prefix.

getLoggerback to summary
public MailLogger getLogger(Class<?> clazz, String prefix)

Create a MailLogger using the specified class' package name as the Logger name and the specified prefix. The new MailLogger uses the same debug flag and PrintStream as this MailLogger.

Parameters
clazz:Class<?>

the Logger name is the package name of this class

prefix:String

the prefix for debug output, or null for none

Returns:MailLogger

a MailLogger for the given name and prefix.

getSubLoggerback to summary
public MailLogger getSubLogger(String subname, String prefix)

Create a MailLogger that uses a Logger whose name is composed of this MailLogger's name plus the specified sub-name, separated by a dot. The new MailLogger uses the new prefix for debug output. This is used primarily by the protocol trace code that wants a different prefix (none).

Parameters
subname:String

the Logger name relative to this Logger name

prefix:String

the prefix for debug output, or null for none

Returns:MailLogger

a MailLogger for the given name and prefix.

getSubLoggerback to summary
public MailLogger getSubLogger(String subname, String prefix, boolean debug)

Create a MailLogger that uses a Logger whose name is composed of this MailLogger's name plus the specified sub-name, separated by a dot. The new MailLogger uses the new prefix for debug output. This is used primarily by the protocol trace code that wants a different prefix (none).

Parameters
subname:String

the Logger name relative to this Logger name

prefix:String

the prefix for debug output, or null for none

debug:boolean

the debug flag for the sub-logger

Returns:MailLogger

a MailLogger for the given name and prefix.

ifDebugOutback to summary
private void ifDebugOut(String msg)

Common code to conditionally log debug statements.

Parameters
msg:String

the message to log.

inferCallerback to summary
private StackTraceElement inferCaller()

A disadvantage of not being able to use Logger directly in Jakarta Mail code is that the "source class" information that Logger guesses will always refer to this class instead of our caller. This method duplicates what Logger does to try to find *our* caller, so that Logger doesn't have to do it (and get the wrong answer), and because our caller is what's wanted.

Returns:StackTraceElement

StackTraceElement that logged the message. Treat as read-only.

isLoggableback to summary
public boolean isLoggable(Level level)

If "debug" is set, or our embedded Logger is loggable at the given level, return true.

Parameters
level:Level

the log level.

Returns:boolean

true if loggable.

isLoggerImplFrameback to summary
private boolean isLoggerImplFrame(String cname)

Frames to ignore as part of the MailLogger to JUL bridge.

Parameters
cname:String

the class name.

Returns:boolean

true if the class name is part of the MailLogger bridge.

logback to summary
public void log(Level level, String msg)

Log the message at the specified level.

Parameters
level:Level

the log level.

msg:String

the message.

logback to summary
public void log(Level level, String msg, Object param1)

Log the message at the specified level.

Parameters
level:Level

the log level.

msg:String

the message.

param1:Object

the additional parameter.

logback to summary
public void log(Level level, String msg, Object... params)

Log the message at the specified level.

Parameters
level:Level

the log level.

msg:String

the message.

params:Object[]

the message parameters.

logback to summary
public void log(Level level, String msg, Throwable thrown)

Log the message at the specified level.

Parameters
level:Level

the log level.

msg:String

the message.

thrown:Throwable

the throwable to log.

logfback to summary
public void logf(Level level, String msg, Object... params)

Log the message at the specified level using a format string.

Parameters
level:Level

the log level.

msg:String

the message format string.

params:Object[]

the message parameters.

Since
JavaMail 1.5.4
packageOfback to summary
private String packageOf(Class<?> clazz)

Return the package name of the class. Sometimes there will be no Package object for the class, e.g., if the class loader hasn't created one (see Class.getPackage()).

Parameters
clazz:Class<?>

the class source.

Returns:String

the package name or an empty string.