APIdia Launch Partner
Top Description Inners Fields Constructors Methods
jdk.internal.net.http.common

pack-priv final Class DebugLogger

extends Object
implements Logger
Class Inheritance
All Implemented Interfaces
jdk.internal.net.http.common.Logger, java.lang.System.Logger
Imports
java.io.PrintStream, java.util.Objects, .ResourceBundle, java.util.function.Supplier

A System.Logger that forwards all messages to an underlying System.Logger, after adding some decoration. The logger also has the ability to additionally send the logged messages to System.err or System.out, whether the underlying logger is activated or not. In addition instance of DebugLogger support both String#format(String, Object...) and java.text.MessageFormat#format(String, Object...) formatting. String-like formatting is enabled by the presence of "%s" or "%d" in the format string. MessageFormat-like formatting is enabled by the presence of "{0" or "{1".

See Utils#getDebugLogger(Supplier) and Utils#getHpackLogger(Supplier).

Nested and Inner Type Summary

Modifier and TypeClass and Description
public static record
DebugLogger.LoggerConfig

A DebugLogger configuration is composed of three levels.

Field Summary

Modifier and TypeField and Description
private final DebugLogger.LoggerConfig
private final Supplier<String>
private final boolean
pack-priv static final System.Logger
pack-priv static final String
pack-priv static final System.Logger
pack-priv static final String
private final System.Logger
private final int
private static final DebugLogger
private static final DebugLogger
private static final DebugLogger
pack-priv static final long
private final boolean
pack-priv static final System.Logger
pack-priv static final String

Constructor Summary

AccessConstructor and Description
private
DebugLogger(System.Logger
The internal logger to which messages will be forwarded. This is typically either WS, HPACK, or HTTP;
logger
,
Supplier<String>
A lambda that returns a string that identifies the caller (e.g: "SocketTube(3)", or "Http2Connection(SocketTube(3))")
dbgTag
,
DebugLogger.LoggerConfig
The levels at or above which messages will be printed to the corresponding destination.
config
)

Create a logger for debug traces.The logger should only be used with levels whose severity is <= DEBUG.

Method Summary

Modifier and TypeMethod and Description
public static DebugLogger
public static DebugLogger
public static DebugLogger
private StringBuilder
private StringBuilder
format(StringBuilder sb, String format, Object[] params)

public String
getName()

Implements java.lang.System.Logger.getName.

Returns the name of this logger.

private boolean
public boolean
isLoggable(System.Logger.Level level)

Implements java.lang.System.Logger.isLoggable.

Checks if a message of the given level would be logged by this logger.

private static boolean
public void
log(System.Logger.Level level, ResourceBundle unused, String format, Object... params)

Implements java.lang.System.Logger.log.

Logs a message with resource bundle and an optional list of parameters.

public void
log(System.Logger.Level level, ResourceBundle unused, String msg, Throwable thrown)

Implements java.lang.System.Logger.log.

Logs a localized message associated with a given throwable.

public final boolean
on()

Overrides default jdk.internal.net.http.common.Logger.on.

Tells whether this logger is on.

private boolean
Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

configback to summary
private final DebugLogger.LoggerConfig config
dbgTagback to summary
private final Supplier<String> dbgTag
debugOnback to summary
private final boolean debugOn
HPACKback to summary
pack-priv static final System.Logger HPACK
HPACK_NAMEback to summary
pack-priv static final String HPACK_NAME
HTTPback to summary
pack-priv static final System.Logger HTTP
HTTP_NAMEback to summary
pack-priv static final String HTTP_NAME
loggerback to summary
private final System.Logger logger
minSeverityback to summary
private final int minSeverity
NO_HPACK_LOGGERback to summary
private static final DebugLogger NO_HPACK_LOGGER
NO_HTTP_LOGGERback to summary
private static final DebugLogger NO_HTTP_LOGGER
NO_WS_LOGGERback to summary
private static final DebugLogger NO_WS_LOGGER
START_NANOSback to summary
pack-priv static final long START_NANOS
traceOnback to summary
private final boolean traceOn
WSback to summary
pack-priv static final System.Logger WS
WS_NAMEback to summary
pack-priv static final String WS_NAME

Constructor Detail

DebugLoggerback to summary
private DebugLogger(System.Logger logger, Supplier<String> dbgTag, DebugLogger.LoggerConfig config)

Create a logger for debug traces.The logger should only be used with levels whose severity is <= DEBUG.

By default, this logger will print message whose severity is above the severity configured in the logger config

  • If config.outLevel() is not Level.OFF, messages whose severity are at or above that severity will be directly printed on System.out
  • If config.errLevel() is not Level.OFF, messages whose severity are at or above that severity will be directly printed on System.err
  • If config.logLevel() is not Level.OFF, messages whose severity are at or above that severity will be forwarded to the supplied logger.

The logger will add some decoration to the printed message, in the form of <Level>:[<thread-name>] [<elapsed-time>] <dbgTag>: <formatted message>

API Note

To obtain a logger that will always print things on stderr in addition to forwarding to the internal logger, use new DebugLogger(logger, this::dbgTag, LoggerConfig.LOG.withErrLevel(Level.ALL));. To obtain a logger that will only forward to the internal logger, use new DebugLogger(logger, this::dbgTag, LoggerConfig.LOG);.

Parameters
logger:System.Logger

The internal logger to which messages will be forwarded. This is typically either WS, HPACK, or HTTP;

dbgTag:Supplier<String>

A lambda that returns a string that identifies the caller (e.g: "SocketTube(3)", or "Http2Connection(SocketTube(3))")

config:DebugLogger.LoggerConfig

The levels at or above which messages will be printed to the corresponding destination.

Method Detail

createHpackLoggerback to summary
public static DebugLogger createHpackLogger(Supplier<String> dbgTag, DebugLogger.LoggerConfig config)
createHttpLoggerback to summary
public static DebugLogger createHttpLogger(Supplier<String> dbgTag, DebugLogger.LoggerConfig config)
createWebSocketLoggerback to summary
public static DebugLogger createWebSocketLogger(Supplier<String> dbgTag, DebugLogger.LoggerConfig config)
decorateback to summary
private StringBuilder decorate(StringBuilder sb, String msg)
formatback to summary
private StringBuilder format(StringBuilder sb, String format, Object[] params)
getNameback to summary
public String getName()

Implements java.lang.System.Logger.getName.

Doc from java.lang.System.Logger.getName.

Returns the name of this logger.

Annotations
@Override
isEnabledback to summary
private boolean isEnabled(System.Logger.Level level)
isLoggableback to summary
public boolean isLoggable(System.Logger.Level level)

Implements java.lang.System.Logger.isLoggable.

Doc from java.lang.System.Logger.isLoggable.

Checks if a message of the given level would be logged by this logger.

Annotations
@Override
levelEnabledForback to summary
private static boolean levelEnabledFor(System.Logger.Level level, DebugLogger.LoggerConfig config, System.Logger logger)
logback to summary
public void log(System.Logger.Level level, ResourceBundle unused, String format, Object... params)

Implements java.lang.System.Logger.log.

Doc from java.lang.System.Logger.log.

Logs a message with resource bundle and an optional list of parameters. If the given resource bundle is non-null, the format string is localized using the given resource bundle. Otherwise the format string is not localized.

Annotations
@Override
logback to summary
public void log(System.Logger.Level level, ResourceBundle unused, String msg, Throwable thrown)

Implements java.lang.System.Logger.log.

Doc from java.lang.System.Logger.log.

Logs a localized message associated with a given throwable. If the given resource bundle is non-null, the msg string is localized using the given resource bundle. Otherwise the msg string is not localized.

Annotations
@Override
onback to summary
public final boolean on()

Overrides default jdk.internal.net.http.common.Logger.on.

Doc from jdk.internal.net.http.common.Logger.on.

Tells whether this logger is on.

Annotations
@Override
useStringFormatback to summary
private boolean useStringFormat(String format)
jdk.internal.net.http.common back to summary

public final Record DebugLogger.LoggerConfig

extends Record
Class Inheritance
Record Components
outLevel:System.Logger.Level
the level at or above which messages will be directly printed to System#out
errLevel:System.Logger.Level
the level at or above which messages will be directly printed to System#err
logLevel:System.Logger.Level
the level at or above which messages will be forwarded to an underlying System.Logger

A DebugLogger configuration is composed of three levels. The three levels can be configured independently, but are typically either Level.ALL or Level.OFF.

Field Summary

Modifier and TypeField and Description
private final System.Logger.Level
errLevel

Record Component accessed by errLevel().

the level at or above which messages will be directly printed to System#err
public static final DebugLogger.LoggerConfig
ERRLOG

logs on both System.err and System.Logger

public static final DebugLogger.LoggerConfig
ERROUT

logs on both System.err and System.out

public static final DebugLogger.LoggerConfig
LOG

Forward to System.Logger, doesn't log directly to System.out or System.err

private final System.Logger.Level
logLevel

Record Component accessed by logLevel().

the level at or above which messages will be forwarded to an underlying System.Logger
public static final DebugLogger.LoggerConfig
OFF

does not log anywhere

private final System.Logger.Level
outLevel

Record Component accessed by outLevel().

the level at or above which messages will be directly printed to System#out
public static final DebugLogger.LoggerConfig
STDERR

Logs on System#err only, does not forward to System.Logger

public static final DebugLogger.LoggerConfig
STDOUT

Logs on System#out only, does not forward to System.Logger

Constructor Summary

AccessConstructor and Description
public

Method Summary

Modifier and TypeMethod and Description
public final boolean
equals(Object o)

Implements abstract java.lang.Record.equals.

Indicates whether some other object is "equal to" this one.

public System.Logger.Level
errLevel()

Record Component getter of errLevel.

Record Component the level at or above which messages will be directly printed to System#err

public final int
hashCode()

Implements abstract java.lang.Record.hashCode.

Returns a hash code value for the record.

public boolean
public System.Logger.Level
logLevel()

Record Component getter of logLevel.

Record Component the level at or above which messages will be forwarded to an underlying System.Logger

public int
public static DebugLogger.LoggerConfig
public boolean
on()

public System.Logger.Level
outLevel()

Record Component getter of outLevel.

Record Component the level at or above which messages will be directly printed to System#out

public final String
toString()

Implements abstract java.lang.Record.toString.

Returns a string representation of the record.

public DebugLogger.LoggerConfig
public DebugLogger.LoggerConfig
public DebugLogger.LoggerConfig

Field Detail

errLevelback to summary
private final System.Logger.Level errLevel

Record Component accessed by errLevel().

the level at or above which messages will be directly printed to System#err

ERRLOGback to summary
public static final DebugLogger.LoggerConfig ERRLOG

logs on both System.err and System.Logger

ERROUTback to summary
public static final DebugLogger.LoggerConfig ERROUT

logs on both System.err and System.out

LOGback to summary
public static final DebugLogger.LoggerConfig LOG

Forward to System.Logger, doesn't log directly to System.out or System.err

logLevelback to summary
private final System.Logger.Level logLevel

Record Component accessed by logLevel().

the level at or above which messages will be forwarded to an underlying System.Logger

OFFback to summary
public static final DebugLogger.LoggerConfig OFF

does not log anywhere

outLevelback to summary
private final System.Logger.Level outLevel

Record Component accessed by outLevel().

the level at or above which messages will be directly printed to System#out

STDERRback to summary
public static final DebugLogger.LoggerConfig STDERR

Logs on System#err only, does not forward to System.Logger

STDOUTback to summary
public static final DebugLogger.LoggerConfig STDOUT

Logs on System#out only, does not forward to System.Logger

Constructor Detail

LoggerConfigback to summary
public LoggerConfig(System.Logger.Level outLevel, System.Logger.Level errLevel, System.Logger.Level logLevel)

Method Detail

equalsback to summary
public final boolean equals(Object o)

Implements abstract java.lang.Record.equals.

Doc from java.lang.Record.equals.

Indicates whether some other object is "equal to" this one. In addition to the general contract of Object.equals, record classes must further obey the invariant that when a record instance is "copied" by passing the result of the record component accessor methods to the canonical constructor, as follows:

    R copy = new R(r.c1(), r.c2(), ..., r.cn());
then it must be the case that r.equals(copy).
errLevelback to summary
public System.Logger.Level errLevel()

Record Component getter of errLevel.

Record Component
the level at or above which messages will be directly printed to System#err
hashCodeback to summary
public final int hashCode()

Implements abstract java.lang.Record.hashCode.

Doc from java.lang.Record.hashCode.

Returns a hash code value for the record. Obeys the general contract of Object.hashCode. For records, hashing behavior is constrained by the refined contract of Record.equals, so that any two records created from the same components must have the same hash code.

levelEnabledForback to summary
public boolean levelEnabledFor(System.Logger.Level level, System.Logger logger)
logLevelback to summary
public System.Logger.Level logLevel()

Record Component getter of logLevel.

Record Component
the level at or above which messages will be forwarded to an underlying System.Logger
minSeverityback to summary
public int minSeverity()
ofback to summary
public static DebugLogger.LoggerConfig of(DebugLogger.LoggerConfig config)
onback to summary
public boolean on()
outLevelback to summary
public System.Logger.Level outLevel()

Record Component getter of outLevel.

Record Component
the level at or above which messages will be directly printed to System#out
toStringback to summary
public final String toString()

Implements abstract java.lang.Record.toString.

Doc from java.lang.Record.toString.

Returns a string representation of the record. In accordance with the general contract of Object#toString(), the toString method returns a string that "textually represents" this record. The result should be a concise but informative representation that is easy for a person to read.

In addition to this general contract, record classes must further participate in the invariant that any two records which are equal must produce equal strings. This invariant is necessarily relaxed in the rare case where corresponding equal component values might fail to produce equal strings for themselves.

withErrLevelback to summary
public DebugLogger.LoggerConfig withErrLevel(System.Logger.Level errLevel)
withLogLevelback to summary
public DebugLogger.LoggerConfig withLogLevel(System.Logger.Level logLevel)
withOutLevelback to summary
public DebugLogger.LoggerConfig withOutLevel(System.Logger.Level outLevel)