Files
YukiHookAPI/assets/logger.html-C9kwF_yM.js
github-actions[bot] aac9e42e84 Deploy to GitHub pages
2025-08-02 18:17:09 +00:00

52 lines
21 KiB
JavaScript

import{_ as a,r as n,o as l,c as t,b as s,d as e,e as p,a as i}from"./app-BpUB8-Q8.js";const c={},r=s("h1",{id:"debug-logs",tabindex:"-1"},[s("a",{class:"header-anchor",href:"#debug-logs","aria-hidden":"true"},"#"),e(" Debug Logs")],-1),d=s("blockquote",null,[s("p",null,[e("Log is the most important part of the debugging process, "),s("code",null,"YukiHookAPI"),e(" encapsulates a set of stable and efficient debugging log functions for developers.")])],-1),u={class:"custom-container tip"},g=s("p",{class:"custom-container-title"},"Tips",-1),h=s("code",null,"KavaRef",-1),y={href:"https://highcapable.github.io/KavaRef/en/library/kavaref-core#log-management",target:"_blank",rel:"noopener noreferrer"},m=s("code",null,"KavaRef",-1),b=s("p",null,[s("code",null,"YukiHookAPI"),e(" has taken over the logging function of "),s("code",null,"KavaRef"),e(" by default, and you can also configure the logging function of "),s("code",null,"KavaRef"),e(" yourself.")],-1),v=i(`<h2 id="normal-logs" tabindex="-1"><a class="header-anchor" href="#normal-logs" aria-hidden="true">#</a> Normal Logs</h2><p>You can call <code>YLog.debug</code>, <code>YLog.info</code>, <code>YLog.warn</code> to print normal logs to the console.</p><p>The usage method is as follows.</p><blockquote><p>The following example</p></blockquote><div class="language-kotlin line-numbers-mode" data-ext="kt"><pre class="shiki github-dark-dimmed" style="background-color:#22272e;" tabindex="0"><code><span class="line"><span style="color:#ADBAC7;">YLog.</span><span style="color:#DCBDFB;">debug</span><span style="color:#ADBAC7;">(msg </span><span style="color:#F47067;">=</span><span style="color:#ADBAC7;"> </span><span style="color:#96D0FF;">&quot;This is a log&quot;</span><span style="color:#ADBAC7;">)</span></span>
<span class="line"></span></code></pre><div class="line-numbers" aria-hidden="true"><div class="line-number"></div></div></div><p>At this ponit, <code>YukiHookAPI</code> will call <code>android.util.Log</code> and log function in (Xposed) Host environment to print this log at the same time.</p><p>The default <code>TAG</code> of the log is the value you set in <code>YLog.Configs.tag</code>.</p><p>You can also customize this value dynamically, but it is not recommended to modify <code>TAG</code> easily to prevent logs from being filtered.</p><blockquote><p>The following example</p></blockquote><div class="language-kotlin line-numbers-mode" data-ext="kt"><pre class="shiki github-dark-dimmed" style="background-color:#22272e;" tabindex="0"><code><span class="line"><span style="color:#ADBAC7;">YLog.</span><span style="color:#DCBDFB;">debug</span><span style="color:#ADBAC7;">(tag </span><span style="color:#F47067;">=</span><span style="color:#ADBAC7;"> </span><span style="color:#96D0FF;">&quot;YukiHookAPI&quot;</span><span style="color:#ADBAC7;">, msg </span><span style="color:#F47067;">=</span><span style="color:#ADBAC7;"> </span><span style="color:#96D0FF;">&quot;This is a log&quot;</span><span style="color:#ADBAC7;">)</span></span>
<span class="line"></span></code></pre><div class="line-numbers" aria-hidden="true"><div class="line-number"></div></div></div><p>The printed result is as shown below.</p><blockquote><p>The following example</p></blockquote><div class="language-text" data-ext="text"><pre class="shiki github-dark-dimmed" style="background-color:#22272e;" tabindex="0"><code><span class="line"><span style="color:#adbac7;">[YukiHookAPI][D][host package name] This is a log</span></span>
<span class="line"><span style="color:#adbac7;"></span></span></code></pre></div><p>You can also use <code>YLog.EnvType</code> to customize the type of log printing.</p><p>You can choose to use <code>android.util.Log</code> or the log function in the (Xposed) Host environment to print logs.</p><p>The default type is <code>YLog.EnvType.BOTH</code>, which means that both methods are used to print logs.</p><p>For example we only use <code>android.util.Log</code> to print logs.</p><blockquote><p>The following example</p></blockquote><div class="language-kotlin line-numbers-mode" data-ext="kt"><pre class="shiki github-dark-dimmed" style="background-color:#22272e;" tabindex="0"><code><span class="line"><span style="color:#ADBAC7;">YLog.</span><span style="color:#DCBDFB;">debug</span><span style="color:#ADBAC7;">(tag </span><span style="color:#F47067;">=</span><span style="color:#ADBAC7;"> </span><span style="color:#96D0FF;">&quot;YukiHookAPI&quot;</span><span style="color:#ADBAC7;">, msg </span><span style="color:#F47067;">=</span><span style="color:#ADBAC7;"> </span><span style="color:#96D0FF;">&quot;This is a log&quot;</span><span style="color:#ADBAC7;">, env </span><span style="color:#F47067;">=</span><span style="color:#ADBAC7;"> YLog.EnvType.LOGD)</span></span>
<span class="line"></span></code></pre><div class="line-numbers" aria-hidden="true"><div class="line-number"></div></div></div><p>Or just use the log function that in the (Xposed) Host environment to print the log, this method can only be used in the (Xposed) Host environment.</p><blockquote><p>The following example</p></blockquote><div class="language-kotlin line-numbers-mode" data-ext="kt"><pre class="shiki github-dark-dimmed" style="background-color:#22272e;" tabindex="0"><code><span class="line"><span style="color:#ADBAC7;">YLog.</span><span style="color:#DCBDFB;">debug</span><span style="color:#ADBAC7;">(tag </span><span style="color:#F47067;">=</span><span style="color:#ADBAC7;"> </span><span style="color:#96D0FF;">&quot;YukiHookAPI&quot;</span><span style="color:#ADBAC7;">, msg </span><span style="color:#F47067;">=</span><span style="color:#ADBAC7;"> </span><span style="color:#96D0FF;">&quot;This is a log&quot;</span><span style="color:#ADBAC7;">, env </span><span style="color:#F47067;">=</span><span style="color:#ADBAC7;"> YLog.EnvType.XPOSED_ENVIRONMENT)</span></span>
<span class="line"></span></code></pre><div class="line-numbers" aria-hidden="true"><div class="line-number"></div></div></div><p>If you want to intelligently distinguish the (Xposed) Host environment from the Module environment, you can write it in the following form.</p><blockquote><p>The following example</p></blockquote><div class="language-kotlin line-numbers-mode" data-ext="kt"><pre class="shiki github-dark-dimmed" style="background-color:#22272e;" tabindex="0"><code><span class="line"><span style="color:#ADBAC7;">YLog.</span><span style="color:#DCBDFB;">debug</span><span style="color:#ADBAC7;">(tag </span><span style="color:#F47067;">=</span><span style="color:#ADBAC7;"> </span><span style="color:#96D0FF;">&quot;YukiHookAPI&quot;</span><span style="color:#ADBAC7;">, msg </span><span style="color:#F47067;">=</span><span style="color:#ADBAC7;"> </span><span style="color:#96D0FF;">&quot;This is a log&quot;</span><span style="color:#ADBAC7;">, env </span><span style="color:#F47067;">=</span><span style="color:#ADBAC7;"> YLog.EnvType.SCOPE)</span></span>
<span class="line"></span></code></pre><div class="line-numbers" aria-hidden="true"><div class="line-number"></div></div></div><p>In this way, the API will intelligently select the specified method type to print this log in different environments.</p><div class="custom-container tip"><p class="custom-container-title">Tips</p><p>For more functions, please refer to <a href="../public/com/highcapable/yukihookapi/hook/log/YLog#debug-method">YLog.debug</a>, <a href="../public/com/highcapable/yukihookapi/hook/log/YLog#info-method">YLog.info</a> and <a href="../public/com/highcapable/yukihookapi/hook/log/YLog#warn-method">YLog.warn</a> methods.</p></div><h2 id="error-logs" tabindex="-1"><a class="header-anchor" href="#error-logs" aria-hidden="true">#</a> Error Logs</h2><p>You can call <code>YLog.error</code> to print <code>E</code> level logs to the console.</p><p>The usage method is as follows.</p><blockquote><p>The following example</p></blockquote><div class="language-kotlin line-numbers-mode" data-ext="kt"><pre class="shiki github-dark-dimmed" style="background-color:#22272e;" tabindex="0"><code><span class="line"><span style="color:#ADBAC7;">YLog.</span><span style="color:#DCBDFB;">error</span><span style="color:#ADBAC7;">(msg </span><span style="color:#F47067;">=</span><span style="color:#ADBAC7;"> </span><span style="color:#96D0FF;">&quot;This is an error&quot;</span><span style="color:#ADBAC7;">)</span></span>
<span class="line"></span></code></pre><div class="line-numbers" aria-hidden="true"><div class="line-number"></div></div></div><p>The error log is the highest level, regardless of whether you have filtered only <code>E</code> level logs.</p><p>For error-level logging, you can also append an exception stack.</p><div class="language-kotlin line-numbers-mode" data-ext="kt"><pre class="shiki github-dark-dimmed" style="background-color:#22272e;" tabindex="0"><code><span class="line"><span style="color:#768390;">// Assume this is the exception that was thrown</span></span>
<span class="line"><span style="color:#F47067;">val</span><span style="color:#ADBAC7;"> throwable </span><span style="color:#F47067;">=</span><span style="color:#ADBAC7;"> </span><span style="color:#DCBDFB;">Throwable</span><span style="color:#ADBAC7;">(</span><span style="color:#F47067;">..</span><span style="color:#ADBAC7;">.)</span></span>
<span class="line"><span style="color:#768390;">// Print log</span></span>
<span class="line"><span style="color:#ADBAC7;">YLog.</span><span style="color:#DCBDFB;">error</span><span style="color:#ADBAC7;">(msg </span><span style="color:#F47067;">=</span><span style="color:#ADBAC7;"> </span><span style="color:#96D0FF;">&quot;This is an error&quot;</span><span style="color:#ADBAC7;">, e </span><span style="color:#F47067;">=</span><span style="color:#ADBAC7;"> throwable)</span></span>
<span class="line"></span></code></pre><div class="line-numbers" aria-hidden="true"><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div></div></div><p>The printed result is as shown below.</p><blockquote><p>The following example</p></blockquote><div class="language-text" data-ext="text"><pre class="shiki github-dark-dimmed" style="background-color:#22272e;" tabindex="0"><code><span class="line"><span style="color:#adbac7;">[YukiHookAPI][E][host package name] This is an error</span></span>
<span class="line"><span style="color:#adbac7;"></span></span></code></pre></div><p>At the same time, the log will help you print the entire exception stack.</p><blockquote><p>The following example</p></blockquote><div class="language-text" data-ext="text"><pre class="shiki github-dark-dimmed" style="background-color:#22272e;" tabindex="0"><code><span class="line"><span style="color:#adbac7;">java.lang.Throwable</span></span>
<span class="line"><span style="color:#adbac7;"> at com.demo.Test.&lt;init&gt;(...)</span></span>
<span class="line"><span style="color:#adbac7;"> at com.demo.Test.doTask(...)</span></span>
<span class="line"><span style="color:#adbac7;"> at com.demo.Test.stop(...)</span></span>
<span class="line"><span style="color:#adbac7;"> at com.demo.Test.init(...)</span></span>
<span class="line"><span style="color:#adbac7;"> at a.a.a(...)</span></span>
<span class="line"><span style="color:#adbac7;"> ... 3 more</span></span>
<span class="line"><span style="color:#adbac7;"></span></span></code></pre></div><p>In the error log, you can also use <code>YLog.EnvType</code> to specify the method type currently used to print the log.</p><div class="custom-container tip"><p class="custom-container-title">Tips</p><p>For more functions, please refer to the <a href="../public/com/highcapable/yukihookapi/hook/log/YLog#error-method">YLog.error</a> method.</p></div><h2 id="save-logs-and-custom-elements" tabindex="-1"><a class="header-anchor" href="#save-logs-and-custom-elements" aria-hidden="true">#</a> Save Logs and Custom Elements</h2><p>You can save all currently printed logs directly to a file using the <code>YLog.saveToFile</code> method.</p><blockquote><p>The following example</p></blockquote><div class="language-kotlin line-numbers-mode" data-ext="kt"><pre class="shiki github-dark-dimmed" style="background-color:#22272e;" tabindex="0"><code><span class="line"><span style="color:#768390;">// Please note</span></span>
<span class="line"><span style="color:#768390;">// The saved file path must have read and write permissions</span></span>
<span class="line"><span style="color:#768390;">// Otherwise an exception will be thrown</span></span>
<span class="line"><span style="color:#ADBAC7;">YLog.</span><span style="color:#DCBDFB;">saveToFile</span><span style="color:#ADBAC7;">(</span><span style="color:#96D0FF;">&quot;/sdcard/Documents/debug_log.log&quot;</span><span style="color:#ADBAC7;">)</span></span>
<span class="line"></span></code></pre><div class="line-numbers" aria-hidden="true"><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div></div></div><p>You can also use <code>YLog.contents</code> to get all the log file contents that have been printed so far.</p><blockquote><p>The following example</p></blockquote><div class="language-kotlin line-numbers-mode" data-ext="kt"><pre class="shiki github-dark-dimmed" style="background-color:#22272e;" tabindex="0"><code><span class="line"><span style="color:#768390;">// Get the contents of all log files that have been printed so far</span></span>
<span class="line"><span style="color:#F47067;">val</span><span style="color:#ADBAC7;"> fileContent </span><span style="color:#F47067;">=</span><span style="color:#ADBAC7;"> YLog.contents</span></span>
<span class="line"></span></code></pre><div class="line-numbers" aria-hidden="true"><div class="line-number"></div><div class="line-number"></div></div></div><p>If you need an array of real-time log data structures, you can directly get the content of <code>YLog.inMemoryData</code>.</p><blockquote><p>The following example</p></blockquote><div class="language-kotlin line-numbers-mode" data-ext="kt"><pre class="shiki github-dark-dimmed" style="background-color:#22272e;" tabindex="0"><code><span class="line"><span style="color:#768390;">// Get the currently printed real-time log data structure array</span></span>
<span class="line"><span style="color:#ADBAC7;">YLog.inMemoryData.</span><span style="color:#DCBDFB;">forEach</span><span style="color:#ADBAC7;"> {</span></span>
<span class="line"><span style="color:#ADBAC7;"> it.timestamp </span><span style="color:#768390;">// Get timestamp</span></span>
<span class="line"><span style="color:#ADBAC7;"> it.time </span><span style="color:#768390;">// Get UTC time</span></span>
<span class="line"><span style="color:#ADBAC7;"> it.priority </span><span style="color:#768390;">// Get priority</span></span>
<span class="line"><span style="color:#ADBAC7;"> it.msg </span><span style="color:#768390;">// Get message</span></span>
<span class="line"><span style="color:#ADBAC7;"> it.throwable </span><span style="color:#768390;">// Get exception</span></span>
<span class="line"><span style="color:#ADBAC7;"> </span><span style="color:#768390;">// ...</span></span>
<span class="line"><span style="color:#ADBAC7;">}</span></span>
<span class="line"></span></code></pre><div class="line-numbers" aria-hidden="true"><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div></div></div><p>If you want to format or save the obtained custom log data to a file, you only need to use the following method.</p><blockquote><p>The following example</p></blockquote><div class="language-kotlin line-numbers-mode" data-ext="kt"><pre class="shiki github-dark-dimmed" style="background-color:#22272e;" tabindex="0"><code><span class="line"><span style="color:#768390;">// Assume this is the custom log data you get</span></span>
<span class="line"><span style="color:#F47067;">val</span><span style="color:#ADBAC7;"> </span><span style="color:#F47067;">data</span><span style="color:#ADBAC7;">: </span><span style="color:#F69D50;">List</span><span style="color:#ADBAC7;">&lt;</span><span style="color:#F69D50;">YLogData</span><span style="color:#ADBAC7;">&gt;</span></span>
<span class="line"><span style="color:#768390;">// Format log data to String</span></span>
<span class="line"><span style="color:#F47067;">val</span><span style="color:#ADBAC7;"> dataString </span><span style="color:#F47067;">=</span><span style="color:#ADBAC7;"> YLog.</span><span style="color:#DCBDFB;">contents</span><span style="color:#ADBAC7;">(</span><span style="color:#F47067;">data</span><span style="color:#ADBAC7;">)</span></span>
<span class="line"><span style="color:#768390;">// Save log data to file</span></span>
<span class="line"><span style="color:#768390;">// Please note</span></span>
<span class="line"><span style="color:#768390;">// The saved file path must have read and write permissions</span></span>
<span class="line"><span style="color:#768390;">// Otherwise an exception will be thrown</span></span>
<span class="line"><span style="color:#ADBAC7;">YLog.</span><span style="color:#DCBDFB;">saveToFile</span><span style="color:#ADBAC7;">(</span><span style="color:#96D0FF;">&quot;/sdcard/Documents/debug_log.log&quot;</span><span style="color:#ADBAC7;">, </span><span style="color:#F47067;">data</span><span style="color:#ADBAC7;">)</span></span>
<span class="line"></span></code></pre><div class="line-numbers" aria-hidden="true"><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div></div></div><div class="custom-container danger"><p class="custom-container-title">Pay Attention</p><p>You need to enable <strong>YLog.Configs.isRecord</strong> to get the contents of <strong>YLog.inMemoryData</strong>.</p><p>The obtained log data is isolated from each other in the Host App and the Module App&#39;s process.</p><p>You can only get the corresponding log data in the corresponding process.</p><p>If you need to get these log data in real time anywhere, please refer to <a href="xposed-channel">Xposed Module and Host Channel</a>, <a href="host-inject#register-module-app-s-activity">Register Module App&#39;s Activity</a>.</p><p>If you only want to get log data in real time through Module App or Host App, Please refer to the optional solution <a href="../public/com/highcapable/yukihookapi/hook/xposed/channel/YukiHookDataChannel#obtainloggerinmemorydata-method">YukiHookDataChannel.obtainLoggerInMemoryData</a> method.</p></div><p>You can also use <code>YLog.Configs.elements</code> to customize the elements that debug logs display externally.</p><p>This function requires <code>YukiHookAPI.Configs</code> to be configured in <code>onInit</code> of the Hook entry class.</p><blockquote><p>The following example</p></blockquote><div class="language-kotlin line-numbers-mode" data-ext="kt"><pre class="shiki github-dark-dimmed" style="background-color:#22272e;" tabindex="0"><code><span class="line"><span style="color:#F47067;">override</span><span style="color:#ADBAC7;"> </span><span style="color:#F47067;">fun</span><span style="color:#ADBAC7;"> </span><span style="color:#DCBDFB;">onInit</span><span style="color:#ADBAC7;">() </span><span style="color:#F47067;">=</span><span style="color:#ADBAC7;"> </span><span style="color:#DCBDFB;">configs</span><span style="color:#ADBAC7;"> {</span></span>
<span class="line"><span style="color:#ADBAC7;"> </span><span style="color:#DCBDFB;">debugLog</span><span style="color:#ADBAC7;"> {</span></span>
<span class="line"><span style="color:#ADBAC7;"> </span><span style="color:#768390;">// ...</span></span>
<span class="line"><span style="color:#ADBAC7;"> </span><span style="color:#DCBDFB;">elements</span><span style="color:#ADBAC7;">(TAG, PRIORITY, PACKAGE_NAME, USER_ID)</span></span>
<span class="line"><span style="color:#ADBAC7;"> }</span></span>
<span class="line"><span style="color:#ADBAC7;"> </span><span style="color:#768390;">// ...</span></span>
<span class="line"><span style="color:#ADBAC7;">}</span></span>
<span class="line"></span></code></pre><div class="line-numbers" aria-hidden="true"><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div></div></div><div class="custom-container tip"><p class="custom-container-title">Tips</p><p>For more functions, please refer to <a href="../public/com/highcapable/yukihookapi/hook/log/YLog#inmemorydata-field">YLog.inMemoryData</a>, <a href="../public/com/highcapable/yukihookapi/hook/log/YLog#contents-field">YLog.contents</a>, <a href="../public/com/highcapable/yukihookapi/hook/log/YLog#contents-method">YLog.contents</a>, <a href="../public/com/highcapable/yukihookapi/hook/log/YLog#savetofile-method">YLog.saveToFile</a> methods and <a href="../public/com/highcapable/yukihookapi/hook/log/YLog#configs-object">YLog.Configs</a>.</p></div>`,62);function A(k,D){const o=n("ExternalLinkIcon");return l(),t("div",null,[r,d,s("div",u,[g,s("p",null,[e("The logs of "),h,e(" can be managed separately by itself. For detailed configuration plans, you can refer to "),s("a",y,[e("here"),p(o)]),e(", which will jump to the "),m,e(" document.")]),b]),v])}const B=a(c,[["render",A],["__file","logger.html.vue"]]);export{B as default};