-
Notifications
You must be signed in to change notification settings - Fork 7
Expand file tree
/
Copy pathLoggingHelpers.java.html
More file actions
78 lines (71 loc) · 4.25 KB
/
Copy pathLoggingHelpers.java.html
File metadata and controls
78 lines (71 loc) · 4.25 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
<?xml version="1.0" encoding="UTF-8"?><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"><html xmlns="http://www.w3.org/1999/xhtml" lang=""><head><meta http-equiv="Content-Type" content="text/html;charset=UTF-8"/><link rel="stylesheet" href="../jacoco-resources/report.css" type="text/css"/><link rel="shortcut icon" href="../jacoco-resources/report.gif" type="image/gif"/><title>LoggingHelpers.java</title><link rel="stylesheet" href="../jacoco-resources/prettify.css" type="text/css"/><script type="text/javascript" src="../jacoco-resources/prettify.js"></script></head><body onload="window['PR_TAB_WIDTH']=4;prettyPrint()"><div class="breadcrumb" id="breadcrumb"><span class="info"><a href="../jacoco-sessions.html" class="el_session">Sessions</a></span><a href="../index.html" class="el_report">GitHub Copilot SDK :: Java</a> > <a href="index.source.html" class="el_package">com.github.copilot</a> > <span class="el_source">LoggingHelpers.java</span></div><h1>LoggingHelpers.java</h1><pre class="source lang-java linenums">/*---------------------------------------------------------------------------------------------
* Copyright (c) Microsoft Corporation. All rights reserved.
*--------------------------------------------------------------------------------------------*/
package com.github.copilot;
import java.util.concurrent.TimeUnit;
import java.util.logging.Level;
import java.util.logging.Logger;
/**
* Internal helper for timing-based diagnostic logging.
*/
final class LoggingHelpers {
private LoggingHelpers() {
// Utility class
}
/**
* Formats elapsed time as a human-readable duration string.
*
* @param startNanos
* the start time from {@link System#nanoTime()}
* @return formatted duration (e.g. "PT0.123S")
*/
static String formatElapsed(long startNanos) {
<span class="fc" id="L28"> long elapsedNanos = System.nanoTime() - startNanos;</span>
<span class="fc" id="L29"> long millis = TimeUnit.NANOSECONDS.toMillis(elapsedNanos);</span>
<span class="fc" id="L30"> return String.format("PT%d.%03dS", millis / 1000, millis % 1000);</span>
}
/**
* Logs a timing message at the given level if the logger accepts it.
*
* @param logger
* the logger to use
* @param level
* the log level
* @param message
* the message template
* @param startNanos
* the start time from {@link System#nanoTime()}
*/
static void logTiming(Logger logger, Level level, String message, long startNanos) {
<span class="pc bpc" id="L46" title="1 of 2 branches missed."> if (!logger.isLoggable(level)) {</span>
<span class="fc" id="L47"> return;</span>
}
<span class="nc" id="L49"> logger.log(level, message.replace("{Elapsed}", formatElapsed(startNanos)));</span>
<span class="nc" id="L50"> }</span>
/**
* Logs a timing message at the given level with an exception.
*
* @param logger
* the logger to use
* @param level
* the log level
* @param exception
* the exception, may be {@code null}
* @param message
* the message template
* @param startNanos
* the start time from {@link System#nanoTime()}
*/
static void logTiming(Logger logger, Level level, Throwable exception, String message, long startNanos) {
<span class="pc bpc" id="L67" title="1 of 2 branches missed."> if (!logger.isLoggable(level)) {</span>
<span class="nc" id="L68"> return;</span>
}
<span class="fc" id="L70"> String formatted = message.replace("{Elapsed}", formatElapsed(startNanos));</span>
<span class="pc bpc" id="L71" title="1 of 2 branches missed."> if (exception != null) {</span>
<span class="fc" id="L72"> logger.log(level, formatted, exception);</span>
} else {
<span class="nc" id="L74"> logger.log(level, formatted);</span>
}
<span class="fc" id="L76"> }</span>
}
</pre><div class="footer"><span class="right">Created with <a href="http://www.jacoco.org/jacoco">JaCoCo</a> 0.8.14.202510111229</span></div></body></html>