36 import java.io.Closeable; |
36 import java.io.Closeable; |
37 import java.io.IOException; |
37 import java.io.IOException; |
38 import java.io.PrintStream; |
38 import java.io.PrintStream; |
39 import java.io.UncheckedIOException; |
39 import java.io.UncheckedIOException; |
40 import java.io.UnsupportedEncodingException; |
40 import java.io.UnsupportedEncodingException; |
41 import java.lang.System.Logger; |
|
42 import java.lang.System.Logger.Level; |
41 import java.lang.System.Logger.Level; |
43 import java.net.InetSocketAddress; |
42 import java.net.InetSocketAddress; |
44 import java.net.URI; |
43 import java.net.URI; |
45 import java.net.URLPermission; |
44 import java.net.URLPermission; |
46 import java.net.http.HttpHeaders; |
45 import java.net.http.HttpHeaders; |
765 * with levels whose severity is {@code <= DEBUG}. |
764 * with levels whose severity is {@code <= DEBUG}. |
766 * |
765 * |
767 * By default, this logger will forward all messages logged to an internal |
766 * By default, this logger will forward all messages logged to an internal |
768 * logger named "jdk.internal.httpclient.hpack.debug". |
767 * logger named "jdk.internal.httpclient.hpack.debug". |
769 * In addition, if the message severity level is >= to |
768 * In addition, if the message severity level is >= to |
770 * the provided {@code outLevel} it will print the messages on stdout. |
769 * the provided {@code errLevel} it will print the messages on stderr. |
771 * The logger will add some decoration to the printed message, in the form of |
770 * The logger will add some decoration to the printed message, in the form of |
772 * {@code <Level>:[<thread-name>] [<elapsed-time>] <dbgTag>: <formatted message>} |
771 * {@code <Level>:[<thread-name>] [<elapsed-time>] <dbgTag>: <formatted message>} |
773 * |
772 * |
774 * @apiNote To obtain a logger that will always print things on stdout in |
773 * @apiNote To obtain a logger that will always print things on stderr in |
775 * addition to forwarding to the internal logger, use |
774 * addition to forwarding to the internal logger, use |
776 * {@code getHpackLogger(this::dbgTag, Level.ALL);}. |
775 * {@code getHpackLogger(this::dbgTag, Level.ALL);}. |
777 * This is also equivalent to calling |
776 * This is also equivalent to calling |
778 * {@code getHpackLogger(this::dbgTag, true);}. |
777 * {@code getHpackLogger(this::dbgTag, true);}. |
779 * To obtain a logger that will only forward to the internal logger, |
778 * To obtain a logger that will only forward to the internal logger, |
781 * This is also equivalent to calling |
780 * This is also equivalent to calling |
782 * {@code getHpackLogger(this::dbgTag, false);}. |
781 * {@code getHpackLogger(this::dbgTag, false);}. |
783 * |
782 * |
784 * @param dbgTag A lambda that returns a string that identifies the caller |
783 * @param dbgTag A lambda that returns a string that identifies the caller |
785 * (e.g: "Http2Connection(SocketTube(3))/hpack.Decoder(3)") |
784 * (e.g: "Http2Connection(SocketTube(3))/hpack.Decoder(3)") |
786 * @param outLevel The level above which messages will be also printed on |
785 * @param errLevel The level above which messages will be also printed on |
787 * stdout (in addition to be forwarded to the internal logger). |
786 * stderr (in addition to be forwarded to the internal logger). |
788 * |
787 * |
789 * @return A logger for HPACK internal debug traces |
788 * @return A logger for HPACK internal debug traces |
790 */ |
789 */ |
791 public static Logger getHpackLogger(Supplier<String> dbgTag, Level outLevel) { |
790 public static Logger getHpackLogger(Supplier<String> dbgTag, Level errLevel) { |
792 Level errLevel = Level.OFF; |
791 Level outLevel = Level.OFF; |
793 return DebugLogger.createHpackLogger(dbgTag, outLevel, errLevel); |
792 return DebugLogger.createHpackLogger(dbgTag, outLevel, errLevel); |
794 } |
793 } |
795 |
794 |
796 /** |
795 /** |
797 * Get a logger for debug HPACK traces.The logger should only be used |
796 * Get a logger for debug HPACK traces.The logger should only be used |
798 * with levels whose severity is {@code <= DEBUG}. |
797 * with levels whose severity is {@code <= DEBUG}. |
799 * |
798 * |
800 * By default, this logger will forward all messages logged to an internal |
799 * By default, this logger will forward all messages logged to an internal |
801 * logger named "jdk.internal.httpclient.hpack.debug". |
800 * logger named "jdk.internal.httpclient.hpack.debug". |
802 * In addition, the provided boolean {@code on==true}, it will print the |
801 * In addition, the provided boolean {@code on==true}, it will print the |
803 * messages on stdout. |
802 * messages on stderr. |
804 * The logger will add some decoration to the printed message, in the form of |
803 * The logger will add some decoration to the printed message, in the form of |
805 * {@code <Level>:[<thread-name>] [<elapsed-time>] <dbgTag>: <formatted message>} |
804 * {@code <Level>:[<thread-name>] [<elapsed-time>] <dbgTag>: <formatted message>} |
806 * |
805 * |
807 * @apiNote To obtain a logger that will always print things on stdout in |
806 * @apiNote To obtain a logger that will always print things on stderr in |
808 * addition to forwarding to the internal logger, use |
807 * addition to forwarding to the internal logger, use |
809 * {@code getHpackLogger(this::dbgTag, true);}. |
808 * {@code getHpackLogger(this::dbgTag, true);}. |
810 * This is also equivalent to calling |
809 * This is also equivalent to calling |
811 * {@code getHpackLogger(this::dbgTag, Level.ALL);}. |
810 * {@code getHpackLogger(this::dbgTag, Level.ALL);}. |
812 * To obtain a logger that will only forward to the internal logger, |
811 * To obtain a logger that will only forward to the internal logger, |
815 * {@code getHpackLogger(this::dbgTag, Level.OFF);}. |
814 * {@code getHpackLogger(this::dbgTag, Level.OFF);}. |
816 * |
815 * |
817 * @param dbgTag A lambda that returns a string that identifies the caller |
816 * @param dbgTag A lambda that returns a string that identifies the caller |
818 * (e.g: "Http2Connection(SocketTube(3))/hpack.Decoder(3)") |
817 * (e.g: "Http2Connection(SocketTube(3))/hpack.Decoder(3)") |
819 * @param on Whether messages should also be printed on |
818 * @param on Whether messages should also be printed on |
820 * stdout (in addition to be forwarded to the internal logger). |
819 * stderr (in addition to be forwarded to the internal logger). |
821 * |
820 * |
822 * @return A logger for HPACK internal debug traces |
821 * @return A logger for HPACK internal debug traces |
823 */ |
822 */ |
824 public static Logger getHpackLogger(Supplier<String> dbgTag, boolean on) { |
823 public static Logger getHpackLogger(Supplier<String> dbgTag, boolean on) { |
825 Level outLevel = on ? Level.ALL : Level.OFF; |
824 Level errLevel = on ? Level.ALL : Level.OFF; |
826 return getHpackLogger(dbgTag, outLevel); |
825 return getHpackLogger(dbgTag, errLevel); |
827 } |
826 } |
828 |
827 |
829 /** |
828 /** |
830 * Get a logger for debug WebSocket traces.The logger should only be used |
829 * Get a logger for debug WebSocket traces.The logger should only be used |
831 * with levels whose severity is {@code <= DEBUG}. |
830 * with levels whose severity is {@code <= DEBUG}. |