mirror of
https://github.com/openharmony/hiviewdfx_hilog_lite.git
synced 2026-07-01 06:41:57 -04:00
update openharmony 1.0.1
This commit is contained in:
@@ -1,13 +0,0 @@
|
||||
### 该问题是怎么引起的?
|
||||
|
||||
|
||||
|
||||
### 重现步骤
|
||||
|
||||
|
||||
|
||||
### 报错信息
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -1,15 +0,0 @@
|
||||
### 相关的Issue
|
||||
|
||||
|
||||
### 原因(目的、解决的问题等)
|
||||
|
||||
|
||||
### 描述(做了什么,变更了什么)
|
||||
|
||||
|
||||
### 测试用例(新增、改动、可能影响的功能)
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -1,177 +1,177 @@
|
||||
|
||||
Apache License
|
||||
Version 2.0, January 2004
|
||||
http://www.apache.org/licenses/
|
||||
|
||||
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
||||
|
||||
1. Definitions.
|
||||
|
||||
"License" shall mean the terms and conditions for use, reproduction,
|
||||
and distribution as defined by Sections 1 through 9 of this document.
|
||||
|
||||
"Licensor" shall mean the copyright owner or entity authorized by
|
||||
the copyright owner that is granting the License.
|
||||
|
||||
"Legal Entity" shall mean the union of the acting entity and all
|
||||
other entities that control, are controlled by, or are under common
|
||||
control with that entity. For the purposes of this definition,
|
||||
"control" means (i) the power, direct or indirect, to cause the
|
||||
direction or management of such entity, whether by contract or
|
||||
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
||||
outstanding shares, or (iii) beneficial ownership of such entity.
|
||||
|
||||
"You" (or "Your") shall mean an individual or Legal Entity
|
||||
exercising permissions granted by this License.
|
||||
|
||||
"Source" form shall mean the preferred form for making modifications,
|
||||
including but not limited to software source code, documentation
|
||||
source, and configuration files.
|
||||
|
||||
"Object" form shall mean any form resulting from mechanical
|
||||
transformation or translation of a Source form, including but
|
||||
not limited to compiled object code, generated documentation,
|
||||
and conversions to other media types.
|
||||
|
||||
"Work" shall mean the work of authorship, whether in Source or
|
||||
Object form, made available under the License, as indicated by a
|
||||
copyright notice that is included in or attached to the work
|
||||
(an example is provided in the Appendix below).
|
||||
|
||||
"Derivative Works" shall mean any work, whether in Source or Object
|
||||
form, that is based on (or derived from) the Work and for which the
|
||||
editorial revisions, annotations, elaborations, or other modifications
|
||||
represent, as a whole, an original work of authorship. For the purposes
|
||||
of this License, Derivative Works shall not include works that remain
|
||||
separable from, or merely link (or bind by name) to the interfaces of,
|
||||
the Work and Derivative Works thereof.
|
||||
|
||||
"Contribution" shall mean any work of authorship, including
|
||||
the original version of the Work and any modifications or additions
|
||||
to that Work or Derivative Works thereof, that is intentionally
|
||||
submitted to Licensor for inclusion in the Work by the copyright owner
|
||||
or by an individual or Legal Entity authorized to submit on behalf of
|
||||
the copyright owner. For the purposes of this definition, "submitted"
|
||||
means any form of electronic, verbal, or written communication sent
|
||||
to the Licensor or its representatives, including but not limited to
|
||||
communication on electronic mailing lists, source code control systems,
|
||||
and issue tracking systems that are managed by, or on behalf of, the
|
||||
Licensor for the purpose of discussing and improving the Work, but
|
||||
excluding communication that is conspicuously marked or otherwise
|
||||
designated in writing by the copyright owner as "Not a Contribution."
|
||||
|
||||
"Contributor" shall mean Licensor and any individual or Legal Entity
|
||||
on behalf of whom a Contribution has been received by Licensor and
|
||||
subsequently incorporated within the Work.
|
||||
|
||||
2. Grant of Copyright License. Subject to the terms and conditions of
|
||||
this License, each Contributor hereby grants to You a perpetual,
|
||||
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
||||
copyright license to reproduce, prepare Derivative Works of,
|
||||
publicly display, publicly perform, sublicense, and distribute the
|
||||
Work and such Derivative Works in Source or Object form.
|
||||
|
||||
3. Grant of Patent License. Subject to the terms and conditions of
|
||||
this License, each Contributor hereby grants to You a perpetual,
|
||||
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
||||
(except as stated in this section) patent license to make, have made,
|
||||
use, offer to sell, sell, import, and otherwise transfer the Work,
|
||||
where such license applies only to those patent claims licensable
|
||||
by such Contributor that are necessarily infringed by their
|
||||
Contribution(s) alone or by combination of their Contribution(s)
|
||||
with the Work to which such Contribution(s) was submitted. If You
|
||||
institute patent litigation against any entity (including a
|
||||
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
||||
or a Contribution incorporated within the Work constitutes direct
|
||||
or contributory patent infringement, then any patent licenses
|
||||
granted to You under this License for that Work shall terminate
|
||||
as of the date such litigation is filed.
|
||||
|
||||
4. Redistribution. You may reproduce and distribute copies of the
|
||||
Work or Derivative Works thereof in any medium, with or without
|
||||
modifications, and in Source or Object form, provided that You
|
||||
meet the following conditions:
|
||||
|
||||
(a) You must give any other recipients of the Work or
|
||||
Derivative Works a copy of this License; and
|
||||
|
||||
(b) You must cause any modified files to carry prominent notices
|
||||
stating that You changed the files; and
|
||||
|
||||
(c) You must retain, in the Source form of any Derivative Works
|
||||
that You distribute, all copyright, patent, trademark, and
|
||||
attribution notices from the Source form of the Work,
|
||||
excluding those notices that do not pertain to any part of
|
||||
the Derivative Works; and
|
||||
|
||||
(d) If the Work includes a "NOTICE" text file as part of its
|
||||
distribution, then any Derivative Works that You distribute must
|
||||
include a readable copy of the attribution notices contained
|
||||
within such NOTICE file, excluding those notices that do not
|
||||
pertain to any part of the Derivative Works, in at least one
|
||||
of the following places: within a NOTICE text file distributed
|
||||
as part of the Derivative Works; within the Source form or
|
||||
documentation, if provided along with the Derivative Works; or,
|
||||
within a display generated by the Derivative Works, if and
|
||||
wherever such third-party notices normally appear. The contents
|
||||
of the NOTICE file are for informational purposes only and
|
||||
do not modify the License. You may add Your own attribution
|
||||
notices within Derivative Works that You distribute, alongside
|
||||
or as an addendum to the NOTICE text from the Work, provided
|
||||
that such additional attribution notices cannot be construed
|
||||
as modifying the License.
|
||||
|
||||
You may add Your own copyright statement to Your modifications and
|
||||
may provide additional or different license terms and conditions
|
||||
for use, reproduction, or distribution of Your modifications, or
|
||||
for any such Derivative Works as a whole, provided Your use,
|
||||
reproduction, and distribution of the Work otherwise complies with
|
||||
the conditions stated in this License.
|
||||
|
||||
5. Submission of Contributions. Unless You explicitly state otherwise,
|
||||
any Contribution intentionally submitted for inclusion in the Work
|
||||
by You to the Licensor shall be under the terms and conditions of
|
||||
this License, without any additional terms or conditions.
|
||||
Notwithstanding the above, nothing herein shall supersede or modify
|
||||
the terms of any separate license agreement you may have executed
|
||||
with Licensor regarding such Contributions.
|
||||
|
||||
6. Trademarks. This License does not grant permission to use the trade
|
||||
names, trademarks, service marks, or product names of the Licensor,
|
||||
except as required for reasonable and customary use in describing the
|
||||
origin of the Work and reproducing the content of the NOTICE file.
|
||||
|
||||
7. Disclaimer of Warranty. Unless required by applicable law or
|
||||
agreed to in writing, Licensor provides the Work (and each
|
||||
Contributor provides its Contributions) on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
||||
implied, including, without limitation, any warranties or conditions
|
||||
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
||||
PARTICULAR PURPOSE. You are solely responsible for determining the
|
||||
appropriateness of using or redistributing the Work and assume any
|
||||
risks associated with Your exercise of permissions under this License.
|
||||
|
||||
8. Limitation of Liability. In no event and under no legal theory,
|
||||
whether in tort (including negligence), contract, or otherwise,
|
||||
unless required by applicable law (such as deliberate and grossly
|
||||
negligent acts) or agreed to in writing, shall any Contributor be
|
||||
liable to You for damages, including any direct, indirect, special,
|
||||
incidental, or consequential damages of any character arising as a
|
||||
result of this License or out of the use or inability to use the
|
||||
Work (including but not limited to damages for loss of goodwill,
|
||||
work stoppage, computer failure or malfunction, or any and all
|
||||
other commercial damages or losses), even if such Contributor
|
||||
has been advised of the possibility of such damages.
|
||||
|
||||
9. Accepting Warranty or Additional Liability. While redistributing
|
||||
the Work or Derivative Works thereof, You may choose to offer,
|
||||
and charge a fee for, acceptance of support, warranty, indemnity,
|
||||
or other liability obligations and/or rights consistent with this
|
||||
License. However, in accepting such obligations, You may act only
|
||||
on Your own behalf and on Your sole responsibility, not on behalf
|
||||
of any other Contributor, and only if You agree to indemnify,
|
||||
defend, and hold each Contributor harmless for any liability
|
||||
incurred by, or claims asserted against, such Contributor by reason
|
||||
of your accepting any such warranty or additional liability.
|
||||
|
||||
|
||||
Apache License
|
||||
Version 2.0, January 2004
|
||||
http://www.apache.org/licenses/
|
||||
|
||||
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
||||
|
||||
1. Definitions.
|
||||
|
||||
"License" shall mean the terms and conditions for use, reproduction,
|
||||
and distribution as defined by Sections 1 through 9 of this document.
|
||||
|
||||
"Licensor" shall mean the copyright owner or entity authorized by
|
||||
the copyright owner that is granting the License.
|
||||
|
||||
"Legal Entity" shall mean the union of the acting entity and all
|
||||
other entities that control, are controlled by, or are under common
|
||||
control with that entity. For the purposes of this definition,
|
||||
"control" means (i) the power, direct or indirect, to cause the
|
||||
direction or management of such entity, whether by contract or
|
||||
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
||||
outstanding shares, or (iii) beneficial ownership of such entity.
|
||||
|
||||
"You" (or "Your") shall mean an individual or Legal Entity
|
||||
exercising permissions granted by this License.
|
||||
|
||||
"Source" form shall mean the preferred form for making modifications,
|
||||
including but not limited to software source code, documentation
|
||||
source, and configuration files.
|
||||
|
||||
"Object" form shall mean any form resulting from mechanical
|
||||
transformation or translation of a Source form, including but
|
||||
not limited to compiled object code, generated documentation,
|
||||
and conversions to other media types.
|
||||
|
||||
"Work" shall mean the work of authorship, whether in Source or
|
||||
Object form, made available under the License, as indicated by a
|
||||
copyright notice that is included in or attached to the work
|
||||
(an example is provided in the Appendix below).
|
||||
|
||||
"Derivative Works" shall mean any work, whether in Source or Object
|
||||
form, that is based on (or derived from) the Work and for which the
|
||||
editorial revisions, annotations, elaborations, or other modifications
|
||||
represent, as a whole, an original work of authorship. For the purposes
|
||||
of this License, Derivative Works shall not include works that remain
|
||||
separable from, or merely link (or bind by name) to the interfaces of,
|
||||
the Work and Derivative Works thereof.
|
||||
|
||||
"Contribution" shall mean any work of authorship, including
|
||||
the original version of the Work and any modifications or additions
|
||||
to that Work or Derivative Works thereof, that is intentionally
|
||||
submitted to Licensor for inclusion in the Work by the copyright owner
|
||||
or by an individual or Legal Entity authorized to submit on behalf of
|
||||
the copyright owner. For the purposes of this definition, "submitted"
|
||||
means any form of electronic, verbal, or written communication sent
|
||||
to the Licensor or its representatives, including but not limited to
|
||||
communication on electronic mailing lists, source code control systems,
|
||||
and issue tracking systems that are managed by, or on behalf of, the
|
||||
Licensor for the purpose of discussing and improving the Work, but
|
||||
excluding communication that is conspicuously marked or otherwise
|
||||
designated in writing by the copyright owner as "Not a Contribution."
|
||||
|
||||
"Contributor" shall mean Licensor and any individual or Legal Entity
|
||||
on behalf of whom a Contribution has been received by Licensor and
|
||||
subsequently incorporated within the Work.
|
||||
|
||||
2. Grant of Copyright License. Subject to the terms and conditions of
|
||||
this License, each Contributor hereby grants to You a perpetual,
|
||||
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
||||
copyright license to reproduce, prepare Derivative Works of,
|
||||
publicly display, publicly perform, sublicense, and distribute the
|
||||
Work and such Derivative Works in Source or Object form.
|
||||
|
||||
3. Grant of Patent License. Subject to the terms and conditions of
|
||||
this License, each Contributor hereby grants to You a perpetual,
|
||||
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
||||
(except as stated in this section) patent license to make, have made,
|
||||
use, offer to sell, sell, import, and otherwise transfer the Work,
|
||||
where such license applies only to those patent claims licensable
|
||||
by such Contributor that are necessarily infringed by their
|
||||
Contribution(s) alone or by combination of their Contribution(s)
|
||||
with the Work to which such Contribution(s) was submitted. If You
|
||||
institute patent litigation against any entity (including a
|
||||
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
||||
or a Contribution incorporated within the Work constitutes direct
|
||||
or contributory patent infringement, then any patent licenses
|
||||
granted to You under this License for that Work shall terminate
|
||||
as of the date such litigation is filed.
|
||||
|
||||
4. Redistribution. You may reproduce and distribute copies of the
|
||||
Work or Derivative Works thereof in any medium, with or without
|
||||
modifications, and in Source or Object form, provided that You
|
||||
meet the following conditions:
|
||||
|
||||
(a) You must give any other recipients of the Work or
|
||||
Derivative Works a copy of this License; and
|
||||
|
||||
(b) You must cause any modified files to carry prominent notices
|
||||
stating that You changed the files; and
|
||||
|
||||
(c) You must retain, in the Source form of any Derivative Works
|
||||
that You distribute, all copyright, patent, trademark, and
|
||||
attribution notices from the Source form of the Work,
|
||||
excluding those notices that do not pertain to any part of
|
||||
the Derivative Works; and
|
||||
|
||||
(d) If the Work includes a "NOTICE" text file as part of its
|
||||
distribution, then any Derivative Works that You distribute must
|
||||
include a readable copy of the attribution notices contained
|
||||
within such NOTICE file, excluding those notices that do not
|
||||
pertain to any part of the Derivative Works, in at least one
|
||||
of the following places: within a NOTICE text file distributed
|
||||
as part of the Derivative Works; within the Source form or
|
||||
documentation, if provided along with the Derivative Works; or,
|
||||
within a display generated by the Derivative Works, if and
|
||||
wherever such third-party notices normally appear. The contents
|
||||
of the NOTICE file are for informational purposes only and
|
||||
do not modify the License. You may add Your own attribution
|
||||
notices within Derivative Works that You distribute, alongside
|
||||
or as an addendum to the NOTICE text from the Work, provided
|
||||
that such additional attribution notices cannot be construed
|
||||
as modifying the License.
|
||||
|
||||
You may add Your own copyright statement to Your modifications and
|
||||
may provide additional or different license terms and conditions
|
||||
for use, reproduction, or distribution of Your modifications, or
|
||||
for any such Derivative Works as a whole, provided Your use,
|
||||
reproduction, and distribution of the Work otherwise complies with
|
||||
the conditions stated in this License.
|
||||
|
||||
5. Submission of Contributions. Unless You explicitly state otherwise,
|
||||
any Contribution intentionally submitted for inclusion in the Work
|
||||
by You to the Licensor shall be under the terms and conditions of
|
||||
this License, without any additional terms or conditions.
|
||||
Notwithstanding the above, nothing herein shall supersede or modify
|
||||
the terms of any separate license agreement you may have executed
|
||||
with Licensor regarding such Contributions.
|
||||
|
||||
6. Trademarks. This License does not grant permission to use the trade
|
||||
names, trademarks, service marks, or product names of the Licensor,
|
||||
except as required for reasonable and customary use in describing the
|
||||
origin of the Work and reproducing the content of the NOTICE file.
|
||||
|
||||
7. Disclaimer of Warranty. Unless required by applicable law or
|
||||
agreed to in writing, Licensor provides the Work (and each
|
||||
Contributor provides its Contributions) on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
||||
implied, including, without limitation, any warranties or conditions
|
||||
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
||||
PARTICULAR PURPOSE. You are solely responsible for determining the
|
||||
appropriateness of using or redistributing the Work and assume any
|
||||
risks associated with Your exercise of permissions under this License.
|
||||
|
||||
8. Limitation of Liability. In no event and under no legal theory,
|
||||
whether in tort (including negligence), contract, or otherwise,
|
||||
unless required by applicable law (such as deliberate and grossly
|
||||
negligent acts) or agreed to in writing, shall any Contributor be
|
||||
liable to You for damages, including any direct, indirect, special,
|
||||
incidental, or consequential damages of any character arising as a
|
||||
result of this License or out of the use or inability to use the
|
||||
Work (including but not limited to damages for loss of goodwill,
|
||||
work stoppage, computer failure or malfunction, or any and all
|
||||
other commercial damages or losses), even if such Contributor
|
||||
has been advised of the possibility of such damages.
|
||||
|
||||
9. Accepting Warranty or Additional Liability. While redistributing
|
||||
the Work or Derivative Works thereof, You may choose to offer,
|
||||
and charge a fee for, acceptance of support, warranty, indemnity,
|
||||
or other liability obligations and/or rights consistent with this
|
||||
License. However, in accepting such obligations, You may act only
|
||||
on Your own behalf and on Your sole responsibility, not on behalf
|
||||
of any other Contributor, and only if You agree to indemnify,
|
||||
defend, and hold each Contributor harmless for any liability
|
||||
incurred by, or claims asserted against, such Contributor by reason
|
||||
of your accepting any such warranty or additional liability.
|
||||
|
||||
END OF TERMS AND CONDITIONS
|
||||
@@ -0,0 +1,302 @@
|
||||
# Hilog\_lite<a name="EN-US_TOPIC_0000001078674780"></a>
|
||||
|
||||
- [Introduction](#s9c9ad6e6d5494719ad0f6630a0a1add4)
|
||||
- [Directory Structure](#s4edd47ec6791449aa2d6362fed84325e)
|
||||
- [Constraints](#s7f347323ea45437ca31edae5c10f2991)
|
||||
- [Log Function for the Mini System](#sd6e99f792bc942f9bb5aa92111be7aff)
|
||||
- [Small System](#s33e0a62bc1dd4a2a9578fc22bd023f11)
|
||||
- [Repositories Involved](#s999c697ebde345449386ce8dc1df1db0)
|
||||
|
||||
## Introduction<a name="s9c9ad6e6d5494719ad0f6630a0a1add4"></a>
|
||||
|
||||
Hilog\_lite provides the log function of the DFX subsystem for the mini and small systems.
|
||||
|
||||
## Directory Structure<a name="s4edd47ec6791449aa2d6362fed84325e"></a>
|
||||
|
||||
**Table 1** Directory structure for Hilog\_lite in the DFX subsystem
|
||||
|
||||
<a name="ta443dcf0f0dd4e07834b95e031c9fb12"></a>
|
||||
<table><thead align="left"><tr id="ra41be074cf4949d284a843a90e781f33"><th class="cellrowborder" valign="top" width="30.34%" id="mcps1.2.3.1.1"><p id="a727aecc17b674751a9d5d7ebdd391310"><a name="a727aecc17b674751a9d5d7ebdd391310"></a><a name="a727aecc17b674751a9d5d7ebdd391310"></a>Directory</p>
|
||||
</th>
|
||||
<th class="cellrowborder" valign="top" width="69.66%" id="mcps1.2.3.1.2"><p id="ad32d72628b854c53ae4b7c54edfc8afe"><a name="ad32d72628b854c53ae4b7c54edfc8afe"></a><a name="ad32d72628b854c53ae4b7c54edfc8afe"></a>Description</p>
|
||||
</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody><tr id="rc4c61aa63a33430fb82263e2bda83e02"><td class="cellrowborder" valign="top" width="30.34%" headers="mcps1.2.3.1.1 "><p id="a08bb3cab9f18422bbebabac53be94111"><a name="a08bb3cab9f18422bbebabac53be94111"></a><a name="a08bb3cab9f18422bbebabac53be94111"></a>interfaces/native/kits/hilog</p>
|
||||
</td>
|
||||
<td class="cellrowborder" valign="top" width="69.66%" headers="mcps1.2.3.1.2 "><p id="a4603eff664a64d7e80db8d890957522c"><a name="a4603eff664a64d7e80db8d890957522c"></a><a name="a4603eff664a64d7e80db8d890957522c"></a>Defines external APIs that provide the log function for the small system.</p>
|
||||
</td>
|
||||
</tr>
|
||||
<tr id="rf932828a7faa477e894fc6ac1405c5c2"><td class="cellrowborder" valign="top" width="30.34%" headers="mcps1.2.3.1.1 "><p id="aa165ba46894b44e396163892a274c308"><a name="aa165ba46894b44e396163892a274c308"></a><a name="aa165ba46894b44e396163892a274c308"></a>interfaces/native/kits/hilog_lite</p>
|
||||
</td>
|
||||
<td class="cellrowborder" valign="top" width="69.66%" headers="mcps1.2.3.1.2 "><p id="af97241f84b4649de924f32608d0298da"><a name="af97241f84b4649de924f32608d0298da"></a><a name="af97241f84b4649de924f32608d0298da"></a>Defines external APIs that provide the log function for the mini system.</p>
|
||||
</td>
|
||||
</tr>
|
||||
<tr id="r81c09daddf724dc088992dc6fb5caeae"><td class="cellrowborder" valign="top" width="30.34%" headers="mcps1.2.3.1.1 "><p id="a915128b09aeb4e25b1f7aba042c42459"><a name="a915128b09aeb4e25b1f7aba042c42459"></a><a name="a915128b09aeb4e25b1f7aba042c42459"></a>services/hilogcat</p>
|
||||
</td>
|
||||
<td class="cellrowborder" valign="top" width="69.66%" headers="mcps1.2.3.1.2 "><p id="a7645a6df6f164244b3292347b1f7ad04"><a name="a7645a6df6f164244b3292347b1f7ad04"></a><a name="a7645a6df6f164244b3292347b1f7ad04"></a>Stores log-related services and commands for the small system.</p>
|
||||
</td>
|
||||
</tr>
|
||||
<tr id="r4fa9d620df3c4e24bd1a94c79ccabcae"><td class="cellrowborder" valign="top" width="30.34%" headers="mcps1.2.3.1.1 "><p id="a95c8bfabb4424e38a11d03a59162ae14"><a name="a95c8bfabb4424e38a11d03a59162ae14"></a><a name="a95c8bfabb4424e38a11d03a59162ae14"></a>services/apphilogcat</p>
|
||||
</td>
|
||||
<td class="cellrowborder" valign="top" width="69.66%" headers="mcps1.2.3.1.2 "><p id="a25c0853c8d0446839ea2b900856696cd"><a name="a25c0853c8d0446839ea2b900856696cd"></a><a name="a25c0853c8d0446839ea2b900856696cd"></a>Provides the log flushing service for the small system.</p>
|
||||
</td>
|
||||
</tr>
|
||||
<tr id="r0a82ab924ac24725bcb24cf3fa523010"><td class="cellrowborder" valign="top" width="30.34%" headers="mcps1.2.3.1.1 "><p id="aba63f8bc7c0a469f94e6f8d177b5c91c"><a name="aba63f8bc7c0a469f94e6f8d177b5c91c"></a><a name="aba63f8bc7c0a469f94e6f8d177b5c91c"></a>command</p>
|
||||
</td>
|
||||
<td class="cellrowborder" valign="top" width="69.66%" headers="mcps1.2.3.1.2 "><p id="a1f274cd4df2949589ebe8a29c4e9a241"><a name="a1f274cd4df2949589ebe8a29c4e9a241"></a><a name="a1f274cd4df2949589ebe8a29c4e9a241"></a>Provides log query commands for the mini system.</p>
|
||||
</td>
|
||||
</tr>
|
||||
<tr id="rb359a73bb38e47c8952cf3a809b7d38d"><td class="cellrowborder" valign="top" width="30.34%" headers="mcps1.2.3.1.1 "><p id="a3a7a4fbfa61e45a5ba3bc4c4af4d82c2"><a name="a3a7a4fbfa61e45a5ba3bc4c4af4d82c2"></a><a name="a3a7a4fbfa61e45a5ba3bc4c4af4d82c2"></a>frameworks/featured</p>
|
||||
</td>
|
||||
<td class="cellrowborder" valign="top" width="69.66%" headers="mcps1.2.3.1.2 "><p id="a307bdb53cf7545d4bd663fb62dd0ca38"><a name="a307bdb53cf7545d4bd663fb62dd0ca38"></a><a name="a307bdb53cf7545d4bd663fb62dd0ca38"></a>Implements the APIs that provide the log function for the small system.</p>
|
||||
</td>
|
||||
</tr>
|
||||
<tr id="rbb7fc424f05a4df181595f633455e8a8"><td class="cellrowborder" valign="top" width="30.34%" headers="mcps1.2.3.1.1 "><p id="a32392112d5b04f7e8baceca6353b9ecf"><a name="a32392112d5b04f7e8baceca6353b9ecf"></a><a name="a32392112d5b04f7e8baceca6353b9ecf"></a>frameworks/mini</p>
|
||||
</td>
|
||||
<td class="cellrowborder" valign="top" width="69.66%" headers="mcps1.2.3.1.2 "><p id="af1f91dea1e6b46dd983e659f936f22a7"><a name="af1f91dea1e6b46dd983e659f936f22a7"></a><a name="af1f91dea1e6b46dd983e659f936f22a7"></a>Implements the APIs that provide the log function for the mini system.</p>
|
||||
</td>
|
||||
</tr>
|
||||
</tbody>
|
||||
</table>
|
||||
|
||||
## Constraints<a name="s7f347323ea45437ca31edae5c10f2991"></a>
|
||||
|
||||
The overall code of the mini system is developed based on the C standard library.
|
||||
|
||||
## Log Function for the Mini System<a name="sd6e99f792bc942f9bb5aa92111be7aff"></a>
|
||||
|
||||
- To add a module \(for example, Module A\) and print logs, perform the following steps:
|
||||
1. **Add the module ID. **
|
||||
|
||||
Add **HILOG\_MODULE\_A** to **base/hiviewdfx/interfaces/hilog\_lite/interfaces/native/kits/hilog\_lite**.
|
||||
|
||||
```
|
||||
typedef enum {
|
||||
/** DFX */
|
||||
HILOG_MODULE_HIVIEW = 0,
|
||||
/** System Module A */
|
||||
HILOG_MODULE_A,
|
||||
/** Maximum number of modules */
|
||||
HILOG_MODULE_MAX
|
||||
} HiLogModuleType;
|
||||
```
|
||||
|
||||
|
||||
1. **Register the module.**
|
||||
|
||||
Add the following code to the initialization process of Module A to register it with the log framework:
|
||||
|
||||
```
|
||||
HiLogRegisterModule(HILOG_MODULE_A, "A");
|
||||
```
|
||||
|
||||
|
||||
1. **Modify the static configuration of the DFX framework.**
|
||||
|
||||
Modify **g\_hiviewConfig** in the following file as required. By default, modification is not required and logs are output to the serial port.
|
||||
|
||||
```
|
||||
utils/lite/hiview_config.c
|
||||
```
|
||||
|
||||
<a name="td247e4651b964f66b48433481b4d4ec3"></a>
|
||||
<table><thead align="left"><tr id="r2d18b74da660408380d46a6048a9e8be"><th class="cellrowborder" valign="top" width="25.180000000000003%" id="mcps1.1.3.1.1"><p id="a3d342605963b49f0bbc054a45a0f6c33"><a name="a3d342605963b49f0bbc054a45a0f6c33"></a><a name="a3d342605963b49f0bbc054a45a0f6c33"></a>Configuration Item</p>
|
||||
</th>
|
||||
<th class="cellrowborder" valign="top" width="74.82%" id="mcps1.1.3.1.2"><p id="a40c1ea12a15d43d6b53412f1db99cf3d"><a name="a40c1ea12a15d43d6b53412f1db99cf3d"></a><a name="a40c1ea12a15d43d6b53412f1db99cf3d"></a>Description</p>
|
||||
</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody><tr id="re41b7052898d4451a271af54fc0444c9"><td class="cellrowborder" valign="top" width="25.180000000000003%" headers="mcps1.1.3.1.1 "><p id="ade652f31f1924b89a6043e0d8f2e2f8e"><a name="ade652f31f1924b89a6043e0d8f2e2f8e"></a><a name="ade652f31f1924b89a6043e0d8f2e2f8e"></a>outputOption</p>
|
||||
</td>
|
||||
<td class="cellrowborder" valign="top" width="74.82%" headers="mcps1.1.3.1.2 "><p id="a831cff5b5e4640bba83434a0eb26c2e8"><a name="a831cff5b5e4640bba83434a0eb26c2e8"></a><a name="a831cff5b5e4640bba83434a0eb26c2e8"></a>Log output mode. The value can be:</p>
|
||||
<a name="ul11276181319272"></a><a name="ul11276181319272"></a><ul id="ul11276181319272"><li><strong id="b1027691316279"><a name="b1027691316279"></a><a name="b1027691316279"></a>OUTPUT_OPTION_DEBUG</strong>: Logs are directly output to the serial port without cross-task scheduling. This value is used only for temporary debugging.</li></ul>
|
||||
<a name="ul659914264273"></a><a name="ul659914264273"></a><ul id="ul659914264273"><li><strong id="b1359818268279"><a name="b1359818268279"></a><a name="b1359818268279"></a>OUTPUT_OPTION_FLOW</strong> (default value): Logs are output as data flow to the serial port.</li></ul>
|
||||
<a name="ul283283282711"></a><a name="ul283283282711"></a><ul id="ul283283282711"><li><strong id="b18831133217271"><a name="b18831133217271"></a><a name="b18831133217271"></a>OUTPUT_OPTION_TEXT_FILE</strong>: Logs are output as text files.</li></ul>
|
||||
</td>
|
||||
</tr>
|
||||
<tr id="rd29a278d00134ad4af1dde3b0957bf1e"><td class="cellrowborder" valign="top" width="25.180000000000003%" headers="mcps1.1.3.1.1 "><p id="a0930c997c3724317a1de154038668048"><a name="a0930c997c3724317a1de154038668048"></a><a name="a0930c997c3724317a1de154038668048"></a>level</p>
|
||||
</td>
|
||||
<td class="cellrowborder" valign="top" width="74.82%" headers="mcps1.1.3.1.2 "><p id="a60b30c4ddebf41e895ef4eacb832629d"><a name="a60b30c4ddebf41e895ef4eacb832629d"></a><a name="a60b30c4ddebf41e895ef4eacb832629d"></a>Log level for output. Only the logs whose levels are higher than or equal to the level specified by this parameter can be output. The value can be <strong id="en-us_topic_0000001051742157_b388817225412"><a name="en-us_topic_0000001051742157_b388817225412"></a><a name="en-us_topic_0000001051742157_b388817225412"></a>HILOG_LV_DEBUG</strong>, <strong id="en-us_topic_0000001051742157_b1010817302414"><a name="en-us_topic_0000001051742157_b1010817302414"></a><a name="en-us_topic_0000001051742157_b1010817302414"></a>HILOG_LV_INFO</strong>, <strong id="en-us_topic_0000001051742157_b1888283212411"><a name="en-us_topic_0000001051742157_b1888283212411"></a><a name="en-us_topic_0000001051742157_b1888283212411"></a>HILOG_LV_WARN</strong>, <strong id="en-us_topic_0000001051742157_b863582564112"><a name="en-us_topic_0000001051742157_b863582564112"></a><a name="en-us_topic_0000001051742157_b863582564112"></a>HILOG_LV_ERROR</strong>, or <strong id="en-us_topic_0000001051742157_b108501827164112"><a name="en-us_topic_0000001051742157_b108501827164112"></a><a name="en-us_topic_0000001051742157_b108501827164112"></a>HILOG_LV_FATAL</strong>.</p>
|
||||
</td>
|
||||
</tr>
|
||||
<tr id="r6b11c6bf7a0b4937a663ef5ec344ab50"><td class="cellrowborder" valign="top" width="25.180000000000003%" headers="mcps1.1.3.1.1 "><p id="aad1cbc77fa614e36a2481198278ad2d4"><a name="aad1cbc77fa614e36a2481198278ad2d4"></a><a name="aad1cbc77fa614e36a2481198278ad2d4"></a>logSwitch</p>
|
||||
</td>
|
||||
<td class="cellrowborder" valign="top" width="74.82%" headers="mcps1.1.3.1.2 "><p id="ad714e073f17e4f33b5843c01de0a9c87"><a name="ad714e073f17e4f33b5843c01de0a9c87"></a><a name="ad714e073f17e4f33b5843c01de0a9c87"></a>Log switch. The HiLog module can be successfully initialized even if this switch is turned off before compilation. By default, this switch is turned on. The value can be <strong id="en-us_topic_0000001051742157_b860151584911"><a name="en-us_topic_0000001051742157_b860151584911"></a><a name="en-us_topic_0000001051742157_b860151584911"></a>HIVIEW_FEATURE_ON</strong> or <strong id="en-us_topic_0000001051742157_b63541819493"><a name="en-us_topic_0000001051742157_b63541819493"></a><a name="en-us_topic_0000001051742157_b63541819493"></a>HIVIEW_FEATURE_OFF</strong>.</p>
|
||||
</td>
|
||||
</tr>
|
||||
<tr id="re811d5b688a94e2796630e601f0ee6c6"><td class="cellrowborder" valign="top" width="25.180000000000003%" headers="mcps1.1.3.1.1 "><p id="a20d547f657cf49a2b8ab3b4622d4aba0"><a name="a20d547f657cf49a2b8ab3b4622d4aba0"></a><a name="a20d547f657cf49a2b8ab3b4622d4aba0"></a>dumpSwitch</p>
|
||||
</td>
|
||||
<td class="cellrowborder" valign="top" width="74.82%" headers="mcps1.1.3.1.2 "><p id="ab5eef5ce590149438be7393317530fda"><a name="ab5eef5ce590149438be7393317530fda"></a><a name="ab5eef5ce590149438be7393317530fda"></a>Dump switch. If this switch is turned off before compilation, the HiDumper module will not be initialized. By default, this switch is turned off. The value can be <strong id="en-us_topic_0000001051742157_b1139516363532"><a name="en-us_topic_0000001051742157_b1139516363532"></a><a name="en-us_topic_0000001051742157_b1139516363532"></a>HIVIEW_FEATURE_ON</strong> or <strong id="en-us_topic_0000001051742157_b16939113816534"><a name="en-us_topic_0000001051742157_b16939113816534"></a><a name="en-us_topic_0000001051742157_b16939113816534"></a>HIVIEW_FEATURE_OFF</strong>.</p>
|
||||
</td>
|
||||
</tr>
|
||||
<tr id="ra276f7f5a7cb4a0b8449047b5cdff658"><td class="cellrowborder" valign="top" width="25.180000000000003%" headers="mcps1.1.3.1.1 "><p id="ac47f6a11699c401090b9c7b8fdffff30"><a name="ac47f6a11699c401090b9c7b8fdffff30"></a><a name="ac47f6a11699c401090b9c7b8fdffff30"></a>eventSwitch</p>
|
||||
</td>
|
||||
<td class="cellrowborder" valign="top" width="74.82%" headers="mcps1.1.3.1.2 "><p id="a45b2e86aed4848d18c2faaa8c22c6bd3"><a name="a45b2e86aed4848d18c2faaa8c22c6bd3"></a><a name="a45b2e86aed4848d18c2faaa8c22c6bd3"></a>Event output switch. If this switch is turned off before compilation, the HiEvent module will not be initialized. By default, this switch is turned off. The value can be <strong id="en-us_topic_0000001051742157_b146761815543"><a name="en-us_topic_0000001051742157_b146761815543"></a><a name="en-us_topic_0000001051742157_b146761815543"></a>HIVIEW_FEATURE_ON</strong> or <strong id="en-us_topic_0000001051742157_b1816422311548"><a name="en-us_topic_0000001051742157_b1816422311548"></a><a name="en-us_topic_0000001051742157_b1816422311548"></a>HIVIEW_FEATURE_OFF</strong>.</p>
|
||||
</td>
|
||||
</tr>
|
||||
</tbody>
|
||||
</table>
|
||||
|
||||
2. **Print logs.**
|
||||
|
||||
Include **\#include "log.h"** in the **.c** file where logs need to be printed. Call the following API:
|
||||
|
||||
HILOG\_INFO\(HILOG\_MODULE\_A, "log test: %d", 88\);
|
||||
|
||||
The following table describes the parameters in the API.
|
||||
|
||||
<a name="tb0e7329d09184f109c0cae274325b2f1"></a>
|
||||
<table><thead align="left"><tr id="r74cdd06495cb4915ad894e023deff4b2"><th class="cellrowborder" valign="top" width="11.57%" id="mcps1.1.5.1.1"><p id="a8cfadf9da95144fd8a9eb9dbd1362b89"><a name="a8cfadf9da95144fd8a9eb9dbd1362b89"></a><a name="a8cfadf9da95144fd8a9eb9dbd1362b89"></a>Parameter</p>
|
||||
</th>
|
||||
<th class="cellrowborder" valign="top" width="11.83%" id="mcps1.1.5.1.2"><p id="afa5ef86b0da84d6db423e3026452c36e"><a name="afa5ef86b0da84d6db423e3026452c36e"></a><a name="afa5ef86b0da84d6db423e3026452c36e"></a>Mandatory</p>
|
||||
</th>
|
||||
<th class="cellrowborder" valign="top" width="15.21%" id="mcps1.1.5.1.3"><p id="a9af4eafce7f64e28b91d13840b0ebcbe"><a name="a9af4eafce7f64e28b91d13840b0ebcbe"></a><a name="a9af4eafce7f64e28b91d13840b0ebcbe"></a>Data Type</p>
|
||||
</th>
|
||||
<th class="cellrowborder" valign="top" width="61.39%" id="mcps1.1.5.1.4"><p id="abeeb3a23760d45939183b063ebd23980"><a name="abeeb3a23760d45939183b063ebd23980"></a><a name="abeeb3a23760d45939183b063ebd23980"></a>Description</p>
|
||||
</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody><tr id="r7e6639aad87e416ab86b866f8e41f99e"><td class="cellrowborder" valign="top" width="11.57%" headers="mcps1.1.5.1.1 "><p id="a2e815fd48b364454993f15e71fe77098"><a name="a2e815fd48b364454993f15e71fe77098"></a><a name="a2e815fd48b364454993f15e71fe77098"></a>mod</p>
|
||||
</td>
|
||||
<td class="cellrowborder" valign="top" width="11.83%" headers="mcps1.1.5.1.2 "><p id="a69360b58343843629f44854149aedac6"><a name="a69360b58343843629f44854149aedac6"></a><a name="a69360b58343843629f44854149aedac6"></a>Yes</p>
|
||||
</td>
|
||||
<td class="cellrowborder" valign="top" width="15.21%" headers="mcps1.1.5.1.3 "><p id="a73824d7214b945baa2e8ed3cfc8ec3d2"><a name="a73824d7214b945baa2e8ed3cfc8ec3d2"></a><a name="a73824d7214b945baa2e8ed3cfc8ec3d2"></a>uint8</p>
|
||||
</td>
|
||||
<td class="cellrowborder" valign="top" width="61.39%" headers="mcps1.1.5.1.4 "><p id="a306257d426c040ebb352413f0ad22730"><a name="a306257d426c040ebb352413f0ad22730"></a><a name="a306257d426c040ebb352413f0ad22730"></a>Module or service ID.</p>
|
||||
<p id="ac6cda7a8fb154e08bb81c97c329c12e6"><a name="ac6cda7a8fb154e08bb81c97c329c12e6"></a><a name="ac6cda7a8fb154e08bb81c97c329c12e6"></a>IDs are planned and allocated in a unified manner. A maximum of 64 IDs are supported. Third-party applications use <strong id="en-us_topic_0000001051742157_b0632102212343"><a name="en-us_topic_0000001051742157_b0632102212343"></a><a name="en-us_topic_0000001051742157_b0632102212343"></a>HILOG_MODULE_APP</strong> as their module ID.</p>
|
||||
</td>
|
||||
</tr>
|
||||
<tr id="r94a3462cd6a2429baabd1f1c2ec46868"><td class="cellrowborder" valign="top" width="11.57%" headers="mcps1.1.5.1.1 "><p id="a1d00ea1c726040b4b018fb84f30ea0a7"><a name="a1d00ea1c726040b4b018fb84f30ea0a7"></a><a name="a1d00ea1c726040b4b018fb84f30ea0a7"></a>fmt</p>
|
||||
</td>
|
||||
<td class="cellrowborder" valign="top" width="11.83%" headers="mcps1.1.5.1.2 "><p id="a41bdb7eaba30400e876efbef6fd419ea"><a name="a41bdb7eaba30400e876efbef6fd419ea"></a><a name="a41bdb7eaba30400e876efbef6fd419ea"></a>Yes</p>
|
||||
</td>
|
||||
<td class="cellrowborder" valign="top" width="15.21%" headers="mcps1.1.5.1.3 "><p id="a29306f4446424bc1878e6ec62d528725"><a name="a29306f4446424bc1878e6ec62d528725"></a><a name="a29306f4446424bc1878e6ec62d528725"></a>char *</p>
|
||||
</td>
|
||||
<td class="cellrowborder" valign="top" width="61.39%" headers="mcps1.1.5.1.4 "><p id="aa050915fc17e4308a596eac11126f7f1"><a name="aa050915fc17e4308a596eac11126f7f1"></a><a name="aa050915fc17e4308a596eac11126f7f1"></a>Format specifier for output.</p>
|
||||
<p id="a0b8e453d8f79476f836d740bf321f248"><a name="a0b8e453d8f79476f836d740bf321f248"></a><a name="a0b8e453d8f79476f836d740bf321f248"></a>1. A maximum of six variable parameters are supported. <strong id="b820071113185"><a name="b820071113185"></a><a name="b820071113185"></a>%s</strong> is not supported.</p>
|
||||
<p id="a965a11a4bc1d4051b6df1e6e7379b691"><a name="a965a11a4bc1d4051b6df1e6e7379b691"></a><a name="a965a11a4bc1d4051b6df1e6e7379b691"></a>2. The maximum length of a formatted log record is 128 bytes. If the maximum length is exceeded, new logs cannot be printed.</p>
|
||||
</td>
|
||||
</tr>
|
||||
<tr id="r6332c90d65704e7e86f4d621a9fcfe74"><td class="cellrowborder" valign="top" width="11.57%" headers="mcps1.1.5.1.1 "><p id="a518fca3b03cb4431bb83b3eaa9309eb1"><a name="a518fca3b03cb4431bb83b3eaa9309eb1"></a><a name="a518fca3b03cb4431bb83b3eaa9309eb1"></a>Variable parameters</p>
|
||||
</td>
|
||||
<td class="cellrowborder" valign="top" width="11.83%" headers="mcps1.1.5.1.2 "><p id="aa5fbcb8d1d8742a39ee76b96ef6d4d56"><a name="aa5fbcb8d1d8742a39ee76b96ef6d4d56"></a><a name="aa5fbcb8d1d8742a39ee76b96ef6d4d56"></a>No</p>
|
||||
</td>
|
||||
<td class="cellrowborder" valign="top" width="15.21%" headers="mcps1.1.5.1.3 "><p id="a6f4d9ca5beaa4e8187e6b50d478af7eb"><a name="a6f4d9ca5beaa4e8187e6b50d478af7eb"></a><a name="a6f4d9ca5beaa4e8187e6b50d478af7eb"></a>int32</p>
|
||||
</td>
|
||||
<td class="cellrowborder" valign="top" width="61.39%" headers="mcps1.1.5.1.4 "><p id="a7ebc1ecb043044d08dba95031abc5700"><a name="a7ebc1ecb043044d08dba95031abc5700"></a><a name="a7ebc1ecb043044d08dba95031abc5700"></a>Variable parameters. Only numeric types are supported. A maximum of six variable parameters are allowed.</p>
|
||||
</td>
|
||||
</tr>
|
||||
</tbody>
|
||||
</table>
|
||||
|
||||
|
||||
|
||||
## Small System<a name="s33e0a62bc1dd4a2a9578fc22bd023f11"></a>
|
||||
|
||||
**Native C and C++ APIs**
|
||||
|
||||
Available HiLog APIs are as follows:
|
||||
|
||||
```
|
||||
HILOG_DEBUG(type, ...)
|
||||
HILOG_INFO(type, ...)
|
||||
HILOG_WARN(type, ...)
|
||||
HILOG_ERROR(type, ...)
|
||||
HILOG_FATAL(type, ...)
|
||||
```
|
||||
|
||||
Usage guidelines:
|
||||
|
||||
1. Define the log tag.
|
||||
|
||||
2. Perform local debugging. \(The domain value **0** can be used.\)
|
||||
|
||||
3. Include the header file using **\#include <hilog/log.h\>**.
|
||||
|
||||
4. Add the dependency library **libhilog** to **BUILD.gn**.
|
||||
|
||||
API rules:
|
||||
|
||||
1. The format specifier is labeled public by default, for example, **HILOGI\("Hello World\\n"\); \>\> Hello World**.
|
||||
|
||||
2. The formatted parameter is labeled private by default, for example, **HILOGI\("Age is %d\\n", 10\); \>\> Age is <private\>**.
|
||||
|
||||
3. Parameters labeled **%\{private\}** are private data, for example, **HILOGI\("Age is %\{private\}d\\n", 10\); \>\> Age is <private\>**.
|
||||
|
||||
4. Parameters labeled **%\{public\}** are public data, for example, **HILOGI\("Age is %\{public\}d\\n", 10\); \>\>Age is 10**.
|
||||
|
||||
Parameter description
|
||||
|
||||
<a name="t3027cfdb064a423d815607ebc0790c5b"></a>
|
||||
<table><thead align="left"><tr id="r7c745f75ae7c4caca52d02b8ea7d922f"><th class="cellrowborder" valign="top" width="25.94%" id="mcps1.1.3.1.1"><p id="ae90a5f6e584048898aca3c9e8b92546a"><a name="ae90a5f6e584048898aca3c9e8b92546a"></a><a name="ae90a5f6e584048898aca3c9e8b92546a"></a>Parameter</p>
|
||||
</th>
|
||||
<th class="cellrowborder" valign="top" width="74.06%" id="mcps1.1.3.1.2"><p id="add5f3970c65244a2af03fbbbb4e8dd9f"><a name="add5f3970c65244a2af03fbbbb4e8dd9f"></a><a name="add5f3970c65244a2af03fbbbb4e8dd9f"></a>Description</p>
|
||||
</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody><tr id="r2046ed95b2bf458e8ef3425b6c597174"><td class="cellrowborder" valign="top" width="25.94%" headers="mcps1.1.3.1.1 "><p id="a1feb6efbb48547d28a8e71ee0a61242a"><a name="a1feb6efbb48547d28a8e71ee0a61242a"></a><a name="a1feb6efbb48547d28a8e71ee0a61242a"></a>domain</p>
|
||||
</td>
|
||||
<td class="cellrowborder" valign="top" width="74.06%" headers="mcps1.1.3.1.2 "><p id="a8027bbc4329d4d32a7a45b294531d213"><a name="a8027bbc4329d4d32a7a45b294531d213"></a><a name="a8027bbc4329d4d32a7a45b294531d213"></a>Domain ID</p>
|
||||
</td>
|
||||
</tr>
|
||||
<tr id="rdbcb919a55204f55b16c186c625c493f"><td class="cellrowborder" valign="top" width="25.94%" headers="mcps1.1.3.1.1 "><p id="a716122a0fa304d089dcd248301a5b7e4"><a name="a716122a0fa304d089dcd248301a5b7e4"></a><a name="a716122a0fa304d089dcd248301a5b7e4"></a>tag</p>
|
||||
</td>
|
||||
<td class="cellrowborder" valign="top" width="74.06%" headers="mcps1.1.3.1.2 "><p id="a527cd7253b79449cadba49bae525d7e9"><a name="a527cd7253b79449cadba49bae525d7e9"></a><a name="a527cd7253b79449cadba49bae525d7e9"></a>Log tag</p>
|
||||
</td>
|
||||
</tr>
|
||||
<tr id="ree2e47f74c664e66930f773a88c5955d"><td class="cellrowborder" valign="top" width="25.94%" headers="mcps1.1.3.1.1 "><p id="a3b7919fb6fe349cda481b7e49809c9b1"><a name="a3b7919fb6fe349cda481b7e49809c9b1"></a><a name="a3b7919fb6fe349cda481b7e49809c9b1"></a>isFmtPrivate</p>
|
||||
</td>
|
||||
<td class="cellrowborder" valign="top" width="74.06%" headers="mcps1.1.3.1.2 "><p id="ae858f47965f442298e5200b9db805c2f"><a name="ae858f47965f442298e5200b9db805c2f"></a><a name="ae858f47965f442298e5200b9db805c2f"></a>Whether the format specifier is private (Value <strong id="b188181937113818"><a name="b188181937113818"></a><a name="b188181937113818"></a>yes</strong> means that the format specifier is private.)</p>
|
||||
</td>
|
||||
</tr>
|
||||
<tr id="r7c847c32fa1d42b98a6321aa03683f9b"><td class="cellrowborder" valign="top" width="25.94%" headers="mcps1.1.3.1.1 "><p id="a5af240669e8649a1a979655a2c4fc904"><a name="a5af240669e8649a1a979655a2c4fc904"></a><a name="a5af240669e8649a1a979655a2c4fc904"></a>fmt</p>
|
||||
</td>
|
||||
<td class="cellrowborder" valign="top" width="74.06%" headers="mcps1.1.3.1.2 "><p id="a9a09fcea9ba54456bb9769dd5fccd8f2"><a name="a9a09fcea9ba54456bb9769dd5fccd8f2"></a><a name="a9a09fcea9ba54456bb9769dd5fccd8f2"></a>Format specifier</p>
|
||||
</td>
|
||||
</tr>
|
||||
<tr id="ra7a3bc01bac24a97b5296680ea5ec315"><td class="cellrowborder" valign="top" width="25.94%" headers="mcps1.1.3.1.1 "><p id="a4158d666b3e84d1c95ae796afd9371a2"><a name="a4158d666b3e84d1c95ae796afd9371a2"></a><a name="a4158d666b3e84d1c95ae796afd9371a2"></a>args</p>
|
||||
</td>
|
||||
<td class="cellrowborder" valign="top" width="74.06%" headers="mcps1.1.3.1.2 "><p id="ac27db004bb6b4e21aebe139c89347e11"><a name="ac27db004bb6b4e21aebe139c89347e11"></a><a name="ac27db004bb6b4e21aebe139c89347e11"></a>Parameters to be displayed using the format specifier</p>
|
||||
</td>
|
||||
</tr>
|
||||
</tbody>
|
||||
</table>
|
||||
|
||||
**Viewing logs**
|
||||
|
||||
1. Go to the **/storage/data/log/** directory to view hilog logs generated during debugging.
|
||||
|
||||
2. Run the **hilogcat** command to view hilog logs in real time.
|
||||
|
||||
|
||||
**Log system architecture**
|
||||
|
||||

|
||||
|
||||
1. hilogtask: log task in the kernel
|
||||
- This is a task or thread of the Linux kernel. It is initialized during system startup.
|
||||
- When a module in the kernel calls the log API, the formatted log content is transferred to the task and stored in a ringbuffer.
|
||||
- When the log API is called in the user space, the formatted log content is written into the driver node by calling **ioctl**. The driver node then sends the log content to hilogtask, and hilogtask stores the log content in the ringbuffer.
|
||||
|
||||
2. hilogcatd: storage for logs in user space
|
||||
- This is a user-space process. It periodically reads the log content from the ringbuffer and stores it in the log file.
|
||||
- Log files can be compressed in **gzip** format by using **zlib**.
|
||||
- The size of a single file and the number of files can be configured during compilation.
|
||||
|
||||
3. hilogcat: command line tool for viewing logs
|
||||
|
||||
This tool reads the log content in the ringbuffer via the kernel driver API, and then outputs the content to **stdout**.
|
||||
|
||||
4. ringbuffer: configurable buffer for logs
|
||||
- The ringbuffer size can be configured during compilation.
|
||||
|
||||
|
||||
## Repositories Involved<a name="s999c697ebde345449386ce8dc1df1db0"></a>
|
||||
|
||||
hievent\_lite
|
||||
|
||||
hilog\_lite
|
||||
|
||||
hiview\_lite
|
||||
|
||||
+256
@@ -0,0 +1,256 @@
|
||||
# Hilog\_lite组件介绍<a name="ZH-CN_TOPIC_0000001078674780"></a>
|
||||
|
||||
- [简介](#s9c9ad6e6d5494719ad0f6630a0a1add4)
|
||||
- [目录](#s4edd47ec6791449aa2d6362fed84325e)
|
||||
- [约束](#s7f347323ea45437ca31edae5c10f2991)
|
||||
- [使用-轻量系统](#sd6e99f792bc942f9bb5aa92111be7aff)
|
||||
- [使用-小型系统](#s33e0a62bc1dd4a2a9578fc22bd023f11)
|
||||
- [涉及仓](#s999c697ebde345449386ce8dc1df1db0)
|
||||
|
||||
## 简介<a name="s9c9ad6e6d5494719ad0f6630a0a1add4"></a>
|
||||
|
||||
提供DFX子系统在轻量系统和小型系统的流水日志功能。
|
||||
|
||||
## 目录<a name="s4edd47ec6791449aa2d6362fed84325e"></a>
|
||||
|
||||
**表 1** DFX子系统hilog\_lite组件代码目录结构
|
||||
|
||||
<a name="ta443dcf0f0dd4e07834b95e031c9fb12"></a>
|
||||
<table><thead align="left"><tr id="ra41be074cf4949d284a843a90e781f33"><th class="cellrowborder" valign="top" width="30.34%" id="mcps1.2.3.1.1"><p id="a727aecc17b674751a9d5d7ebdd391310"><a name="a727aecc17b674751a9d5d7ebdd391310"></a><a name="a727aecc17b674751a9d5d7ebdd391310"></a>名称</p>
|
||||
</th>
|
||||
<th class="cellrowborder" valign="top" width="69.66%" id="mcps1.2.3.1.2"><p id="ad32d72628b854c53ae4b7c54edfc8afe"><a name="ad32d72628b854c53ae4b7c54edfc8afe"></a><a name="ad32d72628b854c53ae4b7c54edfc8afe"></a>描述</p>
|
||||
</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody><tr id="rc4c61aa63a33430fb82263e2bda83e02"><td class="cellrowborder" valign="top" width="30.34%" headers="mcps1.2.3.1.1 "><p id="a08bb3cab9f18422bbebabac53be94111"><a name="a08bb3cab9f18422bbebabac53be94111"></a><a name="a08bb3cab9f18422bbebabac53be94111"></a>interfaces/native/kits/hilog</p>
|
||||
</td>
|
||||
<td class="cellrowborder" valign="top" width="69.66%" headers="mcps1.2.3.1.2 "><p id="a4603eff664a64d7e80db8d890957522c"><a name="a4603eff664a64d7e80db8d890957522c"></a><a name="a4603eff664a64d7e80db8d890957522c"></a>小型系统流水日志对外接口定义</p>
|
||||
</td>
|
||||
</tr>
|
||||
<tr id="rf932828a7faa477e894fc6ac1405c5c2"><td class="cellrowborder" valign="top" width="30.34%" headers="mcps1.2.3.1.1 "><p id="aa165ba46894b44e396163892a274c308"><a name="aa165ba46894b44e396163892a274c308"></a><a name="aa165ba46894b44e396163892a274c308"></a>interfaces/native/kits/hilog_lite</p>
|
||||
</td>
|
||||
<td class="cellrowborder" valign="top" width="69.66%" headers="mcps1.2.3.1.2 "><p id="af97241f84b4649de924f32608d0298da"><a name="af97241f84b4649de924f32608d0298da"></a><a name="af97241f84b4649de924f32608d0298da"></a>轻量系统流水日志对外接口定义</p>
|
||||
</td>
|
||||
</tr>
|
||||
<tr id="r81c09daddf724dc088992dc6fb5caeae"><td class="cellrowborder" valign="top" width="30.34%" headers="mcps1.2.3.1.1 "><p id="a915128b09aeb4e25b1f7aba042c42459"><a name="a915128b09aeb4e25b1f7aba042c42459"></a><a name="a915128b09aeb4e25b1f7aba042c42459"></a>services/hilogcat</p>
|
||||
</td>
|
||||
<td class="cellrowborder" valign="top" width="69.66%" headers="mcps1.2.3.1.2 "><p id="a7645a6df6f164244b3292347b1f7ad04"><a name="a7645a6df6f164244b3292347b1f7ad04"></a><a name="a7645a6df6f164244b3292347b1f7ad04"></a>小型系统流水日志相关服务和命令</p>
|
||||
</td>
|
||||
</tr>
|
||||
<tr id="r4fa9d620df3c4e24bd1a94c79ccabcae"><td class="cellrowborder" valign="top" width="30.34%" headers="mcps1.2.3.1.1 "><p id="a95c8bfabb4424e38a11d03a59162ae14"><a name="a95c8bfabb4424e38a11d03a59162ae14"></a><a name="a95c8bfabb4424e38a11d03a59162ae14"></a>services/apphilogcat</p>
|
||||
</td>
|
||||
<td class="cellrowborder" valign="top" width="69.66%" headers="mcps1.2.3.1.2 "><p id="a25c0853c8d0446839ea2b900856696cd"><a name="a25c0853c8d0446839ea2b900856696cd"></a><a name="a25c0853c8d0446839ea2b900856696cd"></a>小型系统流水日志落盘服务</p>
|
||||
</td>
|
||||
</tr>
|
||||
<tr id="r0a82ab924ac24725bcb24cf3fa523010"><td class="cellrowborder" valign="top" width="30.34%" headers="mcps1.2.3.1.1 "><p id="aba63f8bc7c0a469f94e6f8d177b5c91c"><a name="aba63f8bc7c0a469f94e6f8d177b5c91c"></a><a name="aba63f8bc7c0a469f94e6f8d177b5c91c"></a>command</p>
|
||||
</td>
|
||||
<td class="cellrowborder" valign="top" width="69.66%" headers="mcps1.2.3.1.2 "><p id="a1f274cd4df2949589ebe8a29c4e9a241"><a name="a1f274cd4df2949589ebe8a29c4e9a241"></a><a name="a1f274cd4df2949589ebe8a29c4e9a241"></a>轻量系统日志查询命令</p>
|
||||
</td>
|
||||
</tr>
|
||||
<tr id="rb359a73bb38e47c8952cf3a809b7d38d"><td class="cellrowborder" valign="top" width="30.34%" headers="mcps1.2.3.1.1 "><p id="a3a7a4fbfa61e45a5ba3bc4c4af4d82c2"><a name="a3a7a4fbfa61e45a5ba3bc4c4af4d82c2"></a><a name="a3a7a4fbfa61e45a5ba3bc4c4af4d82c2"></a>frameworks/featured</p>
|
||||
</td>
|
||||
<td class="cellrowborder" valign="top" width="69.66%" headers="mcps1.2.3.1.2 "><p id="a307bdb53cf7545d4bd663fb62dd0ca38"><a name="a307bdb53cf7545d4bd663fb62dd0ca38"></a><a name="a307bdb53cf7545d4bd663fb62dd0ca38"></a>小型系统流水日志接口实现</p>
|
||||
</td>
|
||||
</tr>
|
||||
<tr id="rbb7fc424f05a4df181595f633455e8a8"><td class="cellrowborder" valign="top" width="30.34%" headers="mcps1.2.3.1.1 "><p id="a32392112d5b04f7e8baceca6353b9ecf"><a name="a32392112d5b04f7e8baceca6353b9ecf"></a><a name="a32392112d5b04f7e8baceca6353b9ecf"></a>frameworks/mini</p>
|
||||
</td>
|
||||
<td class="cellrowborder" valign="top" width="69.66%" headers="mcps1.2.3.1.2 "><p id="af1f91dea1e6b46dd983e659f936f22a7"><a name="af1f91dea1e6b46dd983e659f936f22a7"></a><a name="af1f91dea1e6b46dd983e659f936f22a7"></a>轻量系统流水日志接口实现</p>
|
||||
</td>
|
||||
</tr>
|
||||
</tbody>
|
||||
</table>
|
||||
|
||||
## 约束<a name="s7f347323ea45437ca31edae5c10f2991"></a>
|
||||
|
||||
轻量系统整体代码使用标准C开发。
|
||||
|
||||
## 使用-轻量系统<a name="sd6e99f792bc942f9bb5aa92111be7aff"></a>
|
||||
|
||||
- **以下以A模块为例说明如何添加模块并进行日志打印。**
|
||||
1. **第一步添加模块ID**
|
||||
|
||||
在“base/hiviewdfx/hilog\_lite/interfaces/native/kits/hilog\_lite/hiview\_log.h“中添加HILOG\_MODULE\_A定义。
|
||||
|
||||
```
|
||||
typedef enum {
|
||||
/** DFX */
|
||||
HILOG_MODULE_HIVIEW = 0,
|
||||
/** System Module A */
|
||||
HILOG_MODULE_A,
|
||||
/** Maximum number of modules */
|
||||
HILOG_MODULE_MAX
|
||||
} HiLogModuleType;
|
||||
```
|
||||
|
||||
|
||||
1. **第二步模块注册**
|
||||
|
||||
在A模块的初始化流程中添加如下代码,注册模块到日志框架中:
|
||||
|
||||
```
|
||||
HiLogRegisterModule(HILOG_MODULE_A, "A");
|
||||
```
|
||||
|
||||
|
||||
1. **第三步日志打印**
|
||||
|
||||
在需要打印日志的.c文件中 \#include "log.h",调用如下接口:
|
||||
|
||||
HILOG\_INFO\(HILOG\_MODULE\_A,“log test: %d”, 88\);
|
||||
|
||||
接口参数说明:
|
||||
|
||||
<a name="tb0e7329d09184f109c0cae274325b2f1"></a>
|
||||
<table><thead align="left"><tr id="r74cdd06495cb4915ad894e023deff4b2"><th class="cellrowborder" valign="top" width="11.57%" id="mcps1.1.5.1.1"><p id="a8cfadf9da95144fd8a9eb9dbd1362b89"><a name="a8cfadf9da95144fd8a9eb9dbd1362b89"></a><a name="a8cfadf9da95144fd8a9eb9dbd1362b89"></a>参数名</p>
|
||||
</th>
|
||||
<th class="cellrowborder" valign="top" width="11.83%" id="mcps1.1.5.1.2"><p id="afa5ef86b0da84d6db423e3026452c36e"><a name="afa5ef86b0da84d6db423e3026452c36e"></a><a name="afa5ef86b0da84d6db423e3026452c36e"></a>是否必填</p>
|
||||
</th>
|
||||
<th class="cellrowborder" valign="top" width="15.21%" id="mcps1.1.5.1.3"><p id="a9af4eafce7f64e28b91d13840b0ebcbe"><a name="a9af4eafce7f64e28b91d13840b0ebcbe"></a><a name="a9af4eafce7f64e28b91d13840b0ebcbe"></a>参数类型</p>
|
||||
</th>
|
||||
<th class="cellrowborder" valign="top" width="61.39%" id="mcps1.1.5.1.4"><p id="abeeb3a23760d45939183b063ebd23980"><a name="abeeb3a23760d45939183b063ebd23980"></a><a name="abeeb3a23760d45939183b063ebd23980"></a>参数说明</p>
|
||||
</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody><tr id="r7e6639aad87e416ab86b866f8e41f99e"><td class="cellrowborder" valign="top" width="11.57%" headers="mcps1.1.5.1.1 "><p id="a2e815fd48b364454993f15e71fe77098"><a name="a2e815fd48b364454993f15e71fe77098"></a><a name="a2e815fd48b364454993f15e71fe77098"></a>mod</p>
|
||||
</td>
|
||||
<td class="cellrowborder" valign="top" width="11.83%" headers="mcps1.1.5.1.2 "><p id="a69360b58343843629f44854149aedac6"><a name="a69360b58343843629f44854149aedac6"></a><a name="a69360b58343843629f44854149aedac6"></a>是</p>
|
||||
</td>
|
||||
<td class="cellrowborder" valign="top" width="15.21%" headers="mcps1.1.5.1.3 "><p id="a73824d7214b945baa2e8ed3cfc8ec3d2"><a name="a73824d7214b945baa2e8ed3cfc8ec3d2"></a><a name="a73824d7214b945baa2e8ed3cfc8ec3d2"></a>uint8</p>
|
||||
</td>
|
||||
<td class="cellrowborder" valign="top" width="61.39%" headers="mcps1.1.5.1.4 "><p id="a306257d426c040ebb352413f0ad22730"><a name="a306257d426c040ebb352413f0ad22730"></a><a name="a306257d426c040ebb352413f0ad22730"></a>模块\服务的ID。</p>
|
||||
<p id="ac6cda7a8fb154e08bb81c97c329c12e6"><a name="ac6cda7a8fb154e08bb81c97c329c12e6"></a><a name="ac6cda7a8fb154e08bb81c97c329c12e6"></a>统一规划分配,最大支持64个,其中第三方APP统一使用HILOG_MODULE_APP作为模块ID。</p>
|
||||
</td>
|
||||
</tr>
|
||||
<tr id="r94a3462cd6a2429baabd1f1c2ec46868"><td class="cellrowborder" valign="top" width="11.57%" headers="mcps1.1.5.1.1 "><p id="a1d00ea1c726040b4b018fb84f30ea0a7"><a name="a1d00ea1c726040b4b018fb84f30ea0a7"></a><a name="a1d00ea1c726040b4b018fb84f30ea0a7"></a>fmt</p>
|
||||
</td>
|
||||
<td class="cellrowborder" valign="top" width="11.83%" headers="mcps1.1.5.1.2 "><p id="a41bdb7eaba30400e876efbef6fd419ea"><a name="a41bdb7eaba30400e876efbef6fd419ea"></a><a name="a41bdb7eaba30400e876efbef6fd419ea"></a>是</p>
|
||||
</td>
|
||||
<td class="cellrowborder" valign="top" width="15.21%" headers="mcps1.1.5.1.3 "><p id="a29306f4446424bc1878e6ec62d528725"><a name="a29306f4446424bc1878e6ec62d528725"></a><a name="a29306f4446424bc1878e6ec62d528725"></a>char *</p>
|
||||
</td>
|
||||
<td class="cellrowborder" valign="top" width="61.39%" headers="mcps1.1.5.1.4 "><p id="aa050915fc17e4308a596eac11126f7f1"><a name="aa050915fc17e4308a596eac11126f7f1"></a><a name="aa050915fc17e4308a596eac11126f7f1"></a>格式化输出字符串。</p>
|
||||
<p id="a0b8e453d8f79476f836d740bf321f248"><a name="a0b8e453d8f79476f836d740bf321f248"></a><a name="a0b8e453d8f79476f836d740bf321f248"></a>1、 最大支持6个可变参数,不支持%s。</p>
|
||||
<p id="a965a11a4bc1d4051b6df1e6e7379b691"><a name="a965a11a4bc1d4051b6df1e6e7379b691"></a><a name="a965a11a4bc1d4051b6df1e6e7379b691"></a>2、 格式化后的单条日志最大长度128字节,超过将无法打印。</p>
|
||||
</td>
|
||||
</tr>
|
||||
<tr id="r6332c90d65704e7e86f4d621a9fcfe74"><td class="cellrowborder" valign="top" width="11.57%" headers="mcps1.1.5.1.1 "><p id="a518fca3b03cb4431bb83b3eaa9309eb1"><a name="a518fca3b03cb4431bb83b3eaa9309eb1"></a><a name="a518fca3b03cb4431bb83b3eaa9309eb1"></a>可变参</p>
|
||||
</td>
|
||||
<td class="cellrowborder" valign="top" width="11.83%" headers="mcps1.1.5.1.2 "><p id="aa5fbcb8d1d8742a39ee76b96ef6d4d56"><a name="aa5fbcb8d1d8742a39ee76b96ef6d4d56"></a><a name="aa5fbcb8d1d8742a39ee76b96ef6d4d56"></a>否</p>
|
||||
</td>
|
||||
<td class="cellrowborder" valign="top" width="15.21%" headers="mcps1.1.5.1.3 "><p id="a6f4d9ca5beaa4e8187e6b50d478af7eb"><a name="a6f4d9ca5beaa4e8187e6b50d478af7eb"></a><a name="a6f4d9ca5beaa4e8187e6b50d478af7eb"></a>int32</p>
|
||||
</td>
|
||||
<td class="cellrowborder" valign="top" width="61.39%" headers="mcps1.1.5.1.4 "><p id="a7ebc1ecb043044d08dba95031abc5700"><a name="a7ebc1ecb043044d08dba95031abc5700"></a><a name="a7ebc1ecb043044d08dba95031abc5700"></a>仅支持数字类型,最大支持6个变参。</p>
|
||||
</td>
|
||||
</tr>
|
||||
</tbody>
|
||||
</table>
|
||||
|
||||
|
||||
|
||||
## 使用-小型系统<a name="s33e0a62bc1dd4a2a9578fc22bd023f11"></a>
|
||||
|
||||
**Native C/C++**接口
|
||||
|
||||
hilog 可用API
|
||||
|
||||
```
|
||||
HILOG_DEBUG(type, ...)
|
||||
HILOG_INFO(type, ...)
|
||||
HILOG_WARN(type, ...)
|
||||
HILOG_ERROR(type, ...)
|
||||
HILOG_FATAL(type, ...)
|
||||
```
|
||||
|
||||
使用介绍
|
||||
|
||||
1. 首先需要定义TAG。
|
||||
|
||||
2. 本地调试,可以临时使用domain数值 0。
|
||||
|
||||
3. 包含头文件:\#include <hilog/log.h\>
|
||||
|
||||
4. 在BUILD.gn中添加依赖库 libhilog。
|
||||
|
||||
接口规则介绍:
|
||||
|
||||
1. 格式化字符串默认是非隐私 HILOGI\("Hello World\\n"\); \>\> Hello World
|
||||
|
||||
2. 格式化参数默认是隐私 HILOGI\("Age is %d\\n", 10\); \>\> Age is <private\>
|
||||
|
||||
3. %\{private\}标识的参数是隐私 HILOGI\("Age is %\{private\}d\\n", 10\); \>\> Age is <private\>
|
||||
|
||||
4. %\{public\}标识的参数是非隐私 HILOGI\("Age is %\{public\}d\\n", 10\); \>\>Age is 10
|
||||
|
||||
接口参数介绍
|
||||
|
||||
<a name="t3027cfdb064a423d815607ebc0790c5b"></a>
|
||||
<table><thead align="left"><tr id="r7c745f75ae7c4caca52d02b8ea7d922f"><th class="cellrowborder" valign="top" width="25.94%" id="mcps1.1.3.1.1"><p id="ae90a5f6e584048898aca3c9e8b92546a"><a name="ae90a5f6e584048898aca3c9e8b92546a"></a><a name="ae90a5f6e584048898aca3c9e8b92546a"></a>参数名字</p>
|
||||
</th>
|
||||
<th class="cellrowborder" valign="top" width="74.06%" id="mcps1.1.3.1.2"><p id="add5f3970c65244a2af03fbbbb4e8dd9f"><a name="add5f3970c65244a2af03fbbbb4e8dd9f"></a><a name="add5f3970c65244a2af03fbbbb4e8dd9f"></a>参数含义</p>
|
||||
</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody><tr id="r2046ed95b2bf458e8ef3425b6c597174"><td class="cellrowborder" valign="top" width="25.94%" headers="mcps1.1.3.1.1 "><p id="a1feb6efbb48547d28a8e71ee0a61242a"><a name="a1feb6efbb48547d28a8e71ee0a61242a"></a><a name="a1feb6efbb48547d28a8e71ee0a61242a"></a>domain</p>
|
||||
</td>
|
||||
<td class="cellrowborder" valign="top" width="74.06%" headers="mcps1.1.3.1.2 "><p id="a8027bbc4329d4d32a7a45b294531d213"><a name="a8027bbc4329d4d32a7a45b294531d213"></a><a name="a8027bbc4329d4d32a7a45b294531d213"></a>领域标识ID</p>
|
||||
</td>
|
||||
</tr>
|
||||
<tr id="rdbcb919a55204f55b16c186c625c493f"><td class="cellrowborder" valign="top" width="25.94%" headers="mcps1.1.3.1.1 "><p id="a716122a0fa304d089dcd248301a5b7e4"><a name="a716122a0fa304d089dcd248301a5b7e4"></a><a name="a716122a0fa304d089dcd248301a5b7e4"></a>tag</p>
|
||||
</td>
|
||||
<td class="cellrowborder" valign="top" width="74.06%" headers="mcps1.1.3.1.2 "><p id="a527cd7253b79449cadba49bae525d7e9"><a name="a527cd7253b79449cadba49bae525d7e9"></a><a name="a527cd7253b79449cadba49bae525d7e9"></a>日志tag</p>
|
||||
</td>
|
||||
</tr>
|
||||
<tr id="ree2e47f74c664e66930f773a88c5955d"><td class="cellrowborder" valign="top" width="25.94%" headers="mcps1.1.3.1.1 "><p id="a3b7919fb6fe349cda481b7e49809c9b1"><a name="a3b7919fb6fe349cda481b7e49809c9b1"></a><a name="a3b7919fb6fe349cda481b7e49809c9b1"></a>isFmtPrivate</p>
|
||||
</td>
|
||||
<td class="cellrowborder" valign="top" width="74.06%" headers="mcps1.1.3.1.2 "><p id="ae858f47965f442298e5200b9db805c2f"><a name="ae858f47965f442298e5200b9db805c2f"></a><a name="ae858f47965f442298e5200b9db805c2f"></a>标识格式化字符串fmt是否是隐私,是yes时fmt会被认为是隐私</p>
|
||||
</td>
|
||||
</tr>
|
||||
<tr id="r7c847c32fa1d42b98a6321aa03683f9b"><td class="cellrowborder" valign="top" width="25.94%" headers="mcps1.1.3.1.1 "><p id="a5af240669e8649a1a979655a2c4fc904"><a name="a5af240669e8649a1a979655a2c4fc904"></a><a name="a5af240669e8649a1a979655a2c4fc904"></a>fmt</p>
|
||||
</td>
|
||||
<td class="cellrowborder" valign="top" width="74.06%" headers="mcps1.1.3.1.2 "><p id="a9a09fcea9ba54456bb9769dd5fccd8f2"><a name="a9a09fcea9ba54456bb9769dd5fccd8f2"></a><a name="a9a09fcea9ba54456bb9769dd5fccd8f2"></a>格式化字符串</p>
|
||||
</td>
|
||||
</tr>
|
||||
<tr id="ra7a3bc01bac24a97b5296680ea5ec315"><td class="cellrowborder" valign="top" width="25.94%" headers="mcps1.1.3.1.1 "><p id="a4158d666b3e84d1c95ae796afd9371a2"><a name="a4158d666b3e84d1c95ae796afd9371a2"></a><a name="a4158d666b3e84d1c95ae796afd9371a2"></a>args</p>
|
||||
</td>
|
||||
<td class="cellrowborder" valign="top" width="74.06%" headers="mcps1.1.3.1.2 "><p id="ac27db004bb6b4e21aebe139c89347e11"><a name="ac27db004bb6b4e21aebe139c89347e11"></a><a name="ac27db004bb6b4e21aebe139c89347e11"></a>格式化字符串参数</p>
|
||||
</td>
|
||||
</tr>
|
||||
</tbody>
|
||||
</table>
|
||||
|
||||
**日志查看**
|
||||
|
||||
1. debug版本hilog日志会保存到/storage/data/log/目录下面。
|
||||
|
||||
2. 可以执行hilogcat实时查看hilog日志。
|
||||
|
||||
|
||||
**日志系统架构**
|
||||
|
||||

|
||||
|
||||
1. hilogtask流水日志的内核任务。
|
||||
- 此功能是一个linux内核的任务或者线程,在系统启动时初始化。
|
||||
- 当内核中一个模块调用它的日志接口,将格式化好的日志内容传输给改任务,并将其存储在一个环形缓冲区中 。
|
||||
- 当用户态调用日志接口,将格式化好的日志内容通过ioctl调用写入驱动节点,驱动节点再将日志内容发送到hilogtask,hilogtask将日志内容存储到环形缓冲区中。
|
||||
|
||||
2. hilogcatd用户态日志存储服务。
|
||||
- 这是一个用户态的进程,负责定时将内核的ringbuffer读取出来,存储到日志文件中。
|
||||
- 日志文件输出支持gzip压缩,使用zlib
|
||||
- 存储文件的单个文件大小,文件个数可在编译时配置。
|
||||
|
||||
3. hilogcat日志查看命令行工具。
|
||||
|
||||
从内核驱动接口读取ringbuffer内容,输出到标准输出。
|
||||
|
||||
4. 支持日志缓冲区可配置。
|
||||
- 编译时可以配置日志缓冲区的大小。
|
||||
|
||||
|
||||
## 涉及仓<a name="s999c697ebde345449386ce8dc1df1db0"></a>
|
||||
|
||||
hievent\_lite
|
||||
|
||||
hilog\_lite
|
||||
|
||||
hiview\_lite
|
||||
|
||||
Executable
+23
@@ -0,0 +1,23 @@
|
||||
# Copyright (c) 2020 Huawei Device Co., Ltd.
|
||||
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||
# you may not use this file except in compliance with the License.
|
||||
# You may obtain a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS,
|
||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
|
||||
static_library("hilog_lite_command") {
|
||||
sources = [
|
||||
"hilog_lite_command.c",
|
||||
]
|
||||
cflags = [ "-Wall" ]
|
||||
include_dirs = [
|
||||
"//base/hiviewdfx/hilog_lite/interfaces/native/kits/hilog_lite",
|
||||
"//base/hiviewdfx/hiview_lite",
|
||||
]
|
||||
}
|
||||
Executable
+240
@@ -0,0 +1,240 @@
|
||||
/*
|
||||
* Copyright (c) 2020 Huawei Device Co., Ltd.
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#include "hilog_lite_command.h"
|
||||
|
||||
#include <ctype.h>
|
||||
|
||||
#include "securec.h"
|
||||
#include "ohos_types.h"
|
||||
#include "hiview_util.h"
|
||||
#include "hiview_config.h"
|
||||
#include "hiview_log.h"
|
||||
|
||||
#define CMD_MIN_LEN 2
|
||||
#define CMD_MAX_LEN 32
|
||||
#define CMD_HILOGCAT "hilog"
|
||||
#define OPTION_TAG '-'
|
||||
#define OPTION_LIST 'l'
|
||||
#define OPTION_SET 'c'
|
||||
#define OPTION_HELP 'h'
|
||||
#define PARA_LEVEL " level"
|
||||
#define PARA_LEVEL_LEN 6
|
||||
#define PARA_MODULE " mod"
|
||||
#define PARA_MODULE_LEN 4
|
||||
#define OP_ASSIGN '='
|
||||
#define STR_MAX_LEN 128
|
||||
|
||||
static boolean CheckCmdStr(const char *cmd);
|
||||
static void HilogHelpProc(void);
|
||||
static void HilogListProc(const char *cmd);
|
||||
static void HilogSetProc(const char *cmd);
|
||||
static void ListLevelInfo(void);
|
||||
static void ListModuleInfo(void);
|
||||
static void SetOutputLevel(const char *cmd);
|
||||
static void SetOutputModule(const char *cmd);
|
||||
|
||||
/* Command does not contain the "hilogcat". */
|
||||
void HilogCmdProc(const char *cmd)
|
||||
{
|
||||
if (cmd == NULL) {
|
||||
return;
|
||||
}
|
||||
|
||||
int32 len = strnlen(cmd, CMD_MAX_LEN + 1);
|
||||
if (len < CMD_MIN_LEN || len > CMD_MAX_LEN || (CheckCmdStr(cmd) == FALSE)) {
|
||||
HIVIEW_UartPrint("Invalid command.\n");
|
||||
return;
|
||||
}
|
||||
|
||||
if (*cmd != OPTION_TAG) {
|
||||
HIVIEW_UartPrint("Invalid command.\n");
|
||||
return;
|
||||
}
|
||||
|
||||
switch (*(++cmd)) {
|
||||
case OPTION_HELP:
|
||||
HilogHelpProc();
|
||||
return;
|
||||
case OPTION_LIST:
|
||||
HilogListProc(++cmd);
|
||||
return;
|
||||
case OPTION_SET:
|
||||
HilogSetProc(++cmd);
|
||||
return;
|
||||
default:
|
||||
HIVIEW_UartPrint("Invalid command.\n");
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
static void HilogHelpProc(void)
|
||||
{
|
||||
HIVIEW_UartPrint("hilog [-h] [-l level/mod] [-c level=<1>] [-c mod=<3>]\n");
|
||||
HIVIEW_UartPrint(" -h Help\n");
|
||||
HIVIEW_UartPrint(" -l Query the level and module definition information\n");
|
||||
HIVIEW_UartPrint(" -l level Query the level definition information\n");
|
||||
HIVIEW_UartPrint(" -l mod Query the level definition information\n");
|
||||
HIVIEW_UartPrint(" -c Enable all level logs of all modules\n");
|
||||
HIVIEW_UartPrint(" -c level=<id> Set the lowest log level\n");
|
||||
HIVIEW_UartPrint(" -c mod=<id> Enable the logs of a specified module and disable other modules\n");
|
||||
}
|
||||
|
||||
static void HilogListProc(const char *cmd)
|
||||
{
|
||||
if (*cmd == '\0') {
|
||||
ListLevelInfo();
|
||||
ListModuleInfo();
|
||||
} else if (strncmp(cmd, PARA_LEVEL, PARA_LEVEL_LEN) == 0) {
|
||||
ListLevelInfo();
|
||||
} else if (strncmp(cmd, PARA_MODULE, PARA_MODULE_LEN) == 0) {
|
||||
ListModuleInfo();
|
||||
}
|
||||
}
|
||||
|
||||
static void HilogSetProc(const char *cmd)
|
||||
{
|
||||
if (*cmd == '\0') {
|
||||
SetLogLevel(HILOG_LV_DEBUG);
|
||||
SetLogOutputModule(HILOG_MODULE_MAX);
|
||||
} else if (strncmp(cmd, PARA_LEVEL, PARA_LEVEL_LEN) == 0) {
|
||||
SetOutputLevel(cmd + PARA_LEVEL_LEN);
|
||||
} else if (strncmp(cmd, PARA_MODULE, PARA_MODULE_LEN) == 0) {
|
||||
SetOutputModule(cmd + PARA_MODULE_LEN);
|
||||
}
|
||||
}
|
||||
|
||||
static void ListLevelInfo(void)
|
||||
{
|
||||
HIVIEW_UartPrint("======Level Information======\n");
|
||||
HIVIEW_UartPrint(" 1 - DEBUG\n");
|
||||
HIVIEW_UartPrint(" 2 - INFO\n");
|
||||
HIVIEW_UartPrint(" 3 - WARN\n");
|
||||
HIVIEW_UartPrint(" 4 - ERROR\n");
|
||||
HIVIEW_UartPrint(" 5 - FATAL\n");
|
||||
HIVIEW_UartPrint(" 6 - CLOSE LOG\n");
|
||||
}
|
||||
|
||||
static void ListModuleInfo(void)
|
||||
{
|
||||
char modInfo[STR_MAX_LEN] = { '\0' };
|
||||
HIVIEW_UartPrint("======Module Information======\n");
|
||||
for (int i = 0; i < HILOG_MODULE_MAX; i++) {
|
||||
int ret = snprintf_s(modInfo, sizeof(modInfo), sizeof(modInfo) - 1,
|
||||
" %d - %s\n", i, HiLogGetModuleName(i));
|
||||
if (ret > 0) {
|
||||
modInfo[ret] = '\0';
|
||||
HIVIEW_UartPrint((const char *) modInfo);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static void SetOutputLevel(const char *cmd)
|
||||
{
|
||||
if (*cmd != OP_ASSIGN) {
|
||||
HIVIEW_UartPrint("Set the log output level failure.\n");
|
||||
return;
|
||||
}
|
||||
|
||||
char *endPtr = NULL;
|
||||
errno = 0;
|
||||
int32 level = strtol(++cmd, &endPtr, 0);
|
||||
if ((endPtr == NULL) || (cmd == endPtr) || (*endPtr != 0) || (errno == ERANGE)) {
|
||||
HIVIEW_UartPrint("Set the log output level call strtol failure!\n");
|
||||
return;
|
||||
}
|
||||
if (SetLogLevel((uint8)level) == TRUE) {
|
||||
HIVIEW_UartPrint("Set the log output level success.\n");
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
static void SetOutputModule(const char *cmd)
|
||||
{
|
||||
if (*cmd != OP_ASSIGN) {
|
||||
HIVIEW_UartPrint("Set the log output module failure.\n");
|
||||
return;
|
||||
}
|
||||
|
||||
char *endPtr = NULL;
|
||||
errno = 0;
|
||||
int32 mod = strtol(++cmd, &endPtr, 0);
|
||||
if ((endPtr == NULL) || (cmd == endPtr) || (*endPtr != 0) || (errno == ERANGE)) {
|
||||
HIVIEW_UartPrint("Set the log output module call strtol failure!\n");
|
||||
return;
|
||||
}
|
||||
if (SetLogOutputModule((uint8)mod) == TRUE) {
|
||||
HIVIEW_UartPrint("Set the log output module success.\n");
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
static boolean CheckCmdStr(const char *cmd)
|
||||
{
|
||||
while (*cmd != '\0') {
|
||||
if (!(isalnum(*cmd) || (*cmd == ' ') || (*cmd == '\n') ||
|
||||
(*cmd == '=') || (*cmd == '-'))) {
|
||||
return FALSE;
|
||||
}
|
||||
cmd++;
|
||||
}
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
boolean SetLogLevel(uint8 level)
|
||||
{
|
||||
if (level >= HILOG_LV_DEBUG && level < HILOG_MODULE_MAX) {
|
||||
g_hiviewConfig.level = level;
|
||||
return TRUE;
|
||||
}
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
void SwitchLog(uint8 flag)
|
||||
{
|
||||
(flag == HIVIEW_FEATURE_ON) ? (g_hiviewConfig.logSwitch = HIVIEW_FEATURE_ON) :
|
||||
(g_hiviewConfig.logSwitch = HIVIEW_FEATURE_OFF);
|
||||
}
|
||||
|
||||
boolean OpenLogOutputModule(uint8 mod)
|
||||
{
|
||||
if (mod < HILOG_MODULE_MAX) {
|
||||
g_hiviewConfig.logOutputModule |= (1 << mod);
|
||||
return TRUE;
|
||||
}
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
boolean CloseLogOutputModule(uint8 mod)
|
||||
{
|
||||
if (mod < HILOG_MODULE_MAX) {
|
||||
g_hiviewConfig.logOutputModule &= (~(1 << mod));
|
||||
return TRUE;
|
||||
}
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
boolean SetLogOutputModule(uint8 mod)
|
||||
{
|
||||
if (mod < HILOG_MODULE_MAX) {
|
||||
g_hiviewConfig.logOutputModule &= (1 << mod);
|
||||
return TRUE;
|
||||
} else if (mod == HILOG_MODULE_MAX) {
|
||||
g_hiviewConfig.logOutputModule = UINT64_MAX;
|
||||
return TRUE;
|
||||
} else {
|
||||
return FALSE;
|
||||
}
|
||||
}
|
||||
Executable
+70
@@ -0,0 +1,70 @@
|
||||
/*
|
||||
* Copyright (c) 2020 Huawei Device Co., Ltd.
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#ifndef HOS_LITE_HIVIEW_COMMAND_H
|
||||
#define HOS_LITE_HIVIEW_COMMAND_H
|
||||
|
||||
#include "ohos_types.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
#if __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
#endif /* End of #ifdef __cplusplus */
|
||||
|
||||
void HilogCmdProc(const char *cmd);
|
||||
void HieventCmdProc(const char *cmd);
|
||||
void DumpCmdProc(const char *cmd);
|
||||
/**
|
||||
* Dynamically adjust the Log Output Level.
|
||||
* @param level log level. Logs of this level or higher will be generated.
|
||||
* @return TRUE/FALSE
|
||||
**/
|
||||
boolean SetLogLevel(uint8 level);
|
||||
|
||||
/**
|
||||
* Enable or disable the log function.
|
||||
* @param flag HIVIEW_FEATURE_ON/HIVIEW_FEATURE_OFF
|
||||
**/
|
||||
void SwitchLog(uint8 flag);
|
||||
|
||||
/**
|
||||
* Enable the log output of a specified module.
|
||||
* @param mod module id.
|
||||
* @return TRUE/FALSE
|
||||
**/
|
||||
boolean OpenLogOutputModule(uint8 mod);
|
||||
|
||||
/**
|
||||
* Disable the log output of a specified module.
|
||||
* @param mod module id.
|
||||
* @return TRUE/FALSE
|
||||
**/
|
||||
boolean CloseLogOutputModule(uint8 mod);
|
||||
|
||||
/**
|
||||
* Enable the log output of a specified module and disable the log output of other modules.
|
||||
* @param mod module id. If the value of the module id is HILOG_MODULE_MAX, the log output of all modules is enabled.
|
||||
* @return TRUE/FALSE
|
||||
**/
|
||||
boolean SetLogOutputModule(uint8 mod);
|
||||
|
||||
#ifdef __cplusplus
|
||||
#if __cplusplus
|
||||
}
|
||||
#endif
|
||||
#endif /* End of #ifdef __cplusplus */
|
||||
|
||||
#endif /* End of #ifndef HOS_LITE_HIVIEW_COMMAND_H */
|
||||
Binary file not shown.
|
After Width: | Height: | Size: 60 KiB |
Binary file not shown.
|
After Width: | Height: | Size: 34 KiB |
@@ -21,8 +21,8 @@ hilog_sources = [
|
||||
|
||||
config("hilog_config") {
|
||||
include_dirs = [
|
||||
"//base/hiviewdfx/interfaces/innerkits/hilog",
|
||||
"//base/hiviewdfx/interfaces/innerkits",
|
||||
"//base/hiviewdfx/hilog_lite/interfaces/native/innerkits/hilog",
|
||||
"//base/hiviewdfx/hilog_lite/interfaces/native/innerkits",
|
||||
"//third_party/bounds_checking_function/include",
|
||||
]
|
||||
}
|
||||
@@ -53,7 +53,7 @@ ndk_lib("hilog_ndk") {
|
||||
":hilog_shared"
|
||||
]
|
||||
head_files = [
|
||||
"//base/hiviewdfx/interfaces/kits/hilog",
|
||||
"//base/hiviewdfx/hilog_lite/interfaces/native/kits/hilog",
|
||||
"//third_party/bounds_checking_function/include",
|
||||
]
|
||||
}
|
||||
}
|
||||
File diff suppressed because it is too large
Load Diff
@@ -14,22 +14,25 @@
|
||||
import("//build/lite/ndk/ndk.gni")
|
||||
|
||||
static_library("hilog_lite") {
|
||||
sources = [
|
||||
"hiview_log.c",
|
||||
"hiview_log_limit.c",
|
||||
"hiview_output_log.c",
|
||||
]
|
||||
cflags = [ "-Wall" ]
|
||||
include_dirs = [
|
||||
"//kernel/liteos_m/kal",
|
||||
"//base/hiviewdfx/utils/lite",
|
||||
"//base/hiviewdfx/services/hiview_lite",
|
||||
"//base/hiviewdfx/interfaces/kits/hilog_lite",
|
||||
"//foundation/distributedschedule/interfaces/kits/samgr_lite/samgr",
|
||||
]
|
||||
sources = [
|
||||
"hiview_log.c",
|
||||
"hiview_log_limit.c",
|
||||
"hiview_output_log.c",
|
||||
]
|
||||
cflags = [ "-Wall" ]
|
||||
include_dirs = [
|
||||
"//base/hiviewdfx/hiview_lite",
|
||||
"//base/hiviewdfx/hilog_lite/interfaces/native/kits/hilog_lite",
|
||||
"//foundation/distributedschedule/samgr_lite/interfaces/kits/samgr",
|
||||
]
|
||||
deps = ["//base/hiviewdfx/hiview_lite"]
|
||||
}
|
||||
|
||||
ndk_lib("hilog_lite_ndk") {
|
||||
deps = [ ":hilog_lite" ]
|
||||
head_files = [ "//base/hiviewdfx/interfaces/kits/hilog_lite" ]
|
||||
deps = [
|
||||
":hilog_lite"
|
||||
]
|
||||
head_files = [
|
||||
"//base/hiviewdfx/hilog_lite/interfaces/native/kits/hilog_lite",
|
||||
]
|
||||
}
|
||||
@@ -1,136 +1,136 @@
|
||||
/*
|
||||
* Copyright (c) 2020 Huawei Device Co., Ltd.
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#include "string.h"
|
||||
#include "stdarg.h"
|
||||
#include "hos_types.h"
|
||||
#include "hos_init.h"
|
||||
#include "hiview_def.h"
|
||||
#include "hiview_util.h"
|
||||
#include "hiview_config.h"
|
||||
#include "hiview_service.h"
|
||||
#include "hiview_log.h"
|
||||
#include "hiview_log_limit.h"
|
||||
#include "hiview_output_log.h"
|
||||
|
||||
#define LOG_IS_OUTPUT(mod) (g_hiviewConfig.logOutputModule & (1 << (mod)))
|
||||
|
||||
static HiLogModuleInfo g_logModuleInfo[HILOG_MODULE_MAX];
|
||||
const char * const FUN_ARG_S = "0123456I";
|
||||
|
||||
static boolean CheckParameters(uint8 module, uint8 level);
|
||||
|
||||
/* The first step does not involve memory allocation. */
|
||||
static void HiLogInit(void)
|
||||
{
|
||||
InitCoreLogOutput();
|
||||
|
||||
/* The module that is not registered cannot print the log. */
|
||||
if (HiLogRegisterModule(HILOG_MODULE_HIVIEW, "HIVIEW") == FALSE ||
|
||||
HiLogRegisterModule(HILOG_MODULE_SAMGR, "SAMGR") == FALSE ||
|
||||
HiLogRegisterModule(HILOG_MODULE_UPDATE, "UPDATE") == FALSE ||
|
||||
HiLogRegisterModule(HILOG_MODULE_ACE, "ACE") == FALSE ||
|
||||
HiLogRegisterModule(HILOG_MODULE_AAFWK, "AAFWK") == FALSE ||
|
||||
HiLogRegisterModule(HILOG_MODULE_APP, "APP") == FALSE ||
|
||||
HiLogRegisterModule(HILOG_MODULE_GRAPHIC, "GRAPHIC") == FALSE ||
|
||||
HiLogRegisterModule(HILOG_MODULE_MEDIA, "MEDIA") == FALSE ||
|
||||
HiLogRegisterModule(HILOG_MODULE_DMS, "DMS") == FALSE ||
|
||||
HiLogRegisterModule(HILOG_MODULE_SEN, "SEN") == FALSE ||
|
||||
HiLogRegisterModule(HILOG_MODULE_SCY, "SCY") == FALSE) {
|
||||
return;
|
||||
}
|
||||
|
||||
HiviewRegisterInitFunc(HIVIEW_CMP_TYPE_LOG, InitLogOutput);
|
||||
HiviewRegisterInitFunc(HIVIEW_CMP_TYPE_LOG_LIMIT, InitLogLimit);
|
||||
HILOG_DEBUG(HILOG_MODULE_HIVIEW, "hilog init success.");
|
||||
}
|
||||
CORE_INIT_PRI(HiLogInit, 0);
|
||||
|
||||
static boolean CheckParameters(uint8 module, uint8 level)
|
||||
{
|
||||
if ((level < g_hiviewConfig.level) || (level < HILOG_COMPILE_LEVEL)
|
||||
|| (module >= HILOG_MODULE_MAX) || (g_logModuleInfo[module].name == NULL)) {
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
boolean HiLogRegisterModule(uint16 id, const char *name)
|
||||
{
|
||||
if ((id >= HILOG_MODULE_MAX) || name == NULL || g_logModuleInfo[id].name != NULL) {
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
uint32 len = (uint32)strnlen(name, LOG_MODULE_NAME_LEN);
|
||||
if (len >= LOG_MODULE_NAME_LEN - 1) {
|
||||
return FALSE;
|
||||
}
|
||||
uint32 i = 0;
|
||||
while (i < len && name[i] != 0) {
|
||||
if (!((name[i] >= 'a' && name[i] <= 'z') || (name[i] >= 'A' && name[i] <= 'Z'))) {
|
||||
return FALSE;
|
||||
}
|
||||
i++;
|
||||
}
|
||||
|
||||
g_logModuleInfo[id].name = name;
|
||||
g_logModuleInfo[id].id = id;
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
const char *HiLogGetModuleName(uint8 id)
|
||||
{
|
||||
if (id >= HILOG_MODULE_MAX) {
|
||||
return "";
|
||||
}
|
||||
const char *name = g_logModuleInfo[id].name;
|
||||
return (name == NULL) ? "" : name;
|
||||
}
|
||||
|
||||
void HiLogPrintf(uint8 module, uint8 level, const char *nums, const char *fmt, ...)
|
||||
{
|
||||
static char newFmt[] = "The number of parameters is invalid.";
|
||||
HiLogContent logContent = { 0 };
|
||||
int32 argsNum = (nums - FUN_ARG_S);
|
||||
if (argsNum < 0 || argsNum > LOG_MULTI_PARA_MAX) {
|
||||
fmt = newFmt;
|
||||
argsNum = 0;
|
||||
}
|
||||
|
||||
if (g_hiviewConfig.logSwitch == HIVIEW_FEATURE_OFF || !CheckParameters(module, level) ||
|
||||
LogIsLimited(module) || !LOG_IS_OUTPUT(module)) {
|
||||
return;
|
||||
}
|
||||
|
||||
HiLogCommon *pCommon = &(logContent.commonContent);
|
||||
pCommon->head = LOG_INFO_HEAD;
|
||||
pCommon->module = module;
|
||||
pCommon->level = level;
|
||||
pCommon->fmt = fmt;
|
||||
pCommon->valueNumber = (uint8)argsNum;
|
||||
pCommon->task = (uint8)HIVIEW_GetTaskId();
|
||||
pCommon->time = (uint32)(HIVIEW_GetCurrentTime() / MS_PER_SECOND);
|
||||
|
||||
uint8 i = 0;
|
||||
va_list args;
|
||||
va_start(args, fmt);
|
||||
while (i < argsNum) {
|
||||
logContent.values[i++] = va_arg(args, uint32);
|
||||
}
|
||||
va_end(args);
|
||||
|
||||
OutputLog((uint8 *)&logContent, sizeof(HiLogCommon) + sizeof(uint32) * argsNum);
|
||||
}
|
||||
/*
|
||||
* Copyright (c) 2020 Huawei Device Co., Ltd.
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#include "string.h"
|
||||
#include "stdarg.h"
|
||||
#include "ohos_types.h"
|
||||
#include "ohos_init.h"
|
||||
#include "hiview_def.h"
|
||||
#include "hiview_util.h"
|
||||
#include "hiview_config.h"
|
||||
#include "hiview_service.h"
|
||||
#include "hiview_log.h"
|
||||
#include "hiview_log_limit.h"
|
||||
#include "hiview_output_log.h"
|
||||
|
||||
#define LOG_IS_OUTPUT(mod) (g_hiviewConfig.logOutputModule & (1 << (mod)))
|
||||
|
||||
static HiLogModuleInfo g_logModuleInfo[HILOG_MODULE_MAX];
|
||||
const char * const FUN_ARG_S = "0123456I";
|
||||
|
||||
static boolean CheckParameters(uint8 module, uint8 level);
|
||||
|
||||
/* The first step does not involve memory allocation. */
|
||||
static void HiLogInit(void)
|
||||
{
|
||||
InitCoreLogOutput();
|
||||
|
||||
/* The module that is not registered cannot print the log. */
|
||||
if (HiLogRegisterModule(HILOG_MODULE_HIVIEW, "HIVIEW") == FALSE ||
|
||||
HiLogRegisterModule(HILOG_MODULE_SAMGR, "SAMGR") == FALSE ||
|
||||
HiLogRegisterModule(HILOG_MODULE_UPDATE, "UPDATE") == FALSE ||
|
||||
HiLogRegisterModule(HILOG_MODULE_ACE, "ACE") == FALSE ||
|
||||
HiLogRegisterModule(HILOG_MODULE_AAFWK, "AAFWK") == FALSE ||
|
||||
HiLogRegisterModule(HILOG_MODULE_APP, "APP") == FALSE ||
|
||||
HiLogRegisterModule(HILOG_MODULE_GRAPHIC, "GRAPHIC") == FALSE ||
|
||||
HiLogRegisterModule(HILOG_MODULE_MEDIA, "MEDIA") == FALSE ||
|
||||
HiLogRegisterModule(HILOG_MODULE_DMS, "DMS") == FALSE ||
|
||||
HiLogRegisterModule(HILOG_MODULE_SEN, "SEN") == FALSE ||
|
||||
HiLogRegisterModule(HILOG_MODULE_SCY, "SCY") == FALSE) {
|
||||
return;
|
||||
}
|
||||
|
||||
HiviewRegisterInitFunc(HIVIEW_CMP_TYPE_LOG, InitLogOutput);
|
||||
HiviewRegisterInitFunc(HIVIEW_CMP_TYPE_LOG_LIMIT, InitLogLimit);
|
||||
HILOG_DEBUG(HILOG_MODULE_HIVIEW, "hilog init success.");
|
||||
}
|
||||
CORE_INIT_PRI(HiLogInit, 0);
|
||||
|
||||
static boolean CheckParameters(uint8 module, uint8 level)
|
||||
{
|
||||
if ((level < g_hiviewConfig.level) || (level < HILOG_COMPILE_LEVEL)
|
||||
|| (module >= HILOG_MODULE_MAX) || (g_logModuleInfo[module].name == NULL)) {
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
boolean HiLogRegisterModule(uint16 id, const char *name)
|
||||
{
|
||||
if ((id >= HILOG_MODULE_MAX) || name == NULL || g_logModuleInfo[id].name != NULL) {
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
uint32 len = (uint32)strnlen(name, LOG_MODULE_NAME_LEN + 1);
|
||||
if (len >= LOG_MODULE_NAME_LEN - 1) {
|
||||
return FALSE;
|
||||
}
|
||||
uint32 i = 0;
|
||||
while (i < len && name[i] != 0) {
|
||||
if (!((name[i] >= 'a' && name[i] <= 'z') || (name[i] >= 'A' && name[i] <= 'Z'))) {
|
||||
return FALSE;
|
||||
}
|
||||
i++;
|
||||
}
|
||||
|
||||
g_logModuleInfo[id].name = name;
|
||||
g_logModuleInfo[id].id = id;
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
const char *HiLogGetModuleName(uint8 id)
|
||||
{
|
||||
if (id >= HILOG_MODULE_MAX) {
|
||||
return "";
|
||||
}
|
||||
const char *name = g_logModuleInfo[id].name;
|
||||
return (name == NULL) ? "" : name;
|
||||
}
|
||||
|
||||
void HiLogPrintf(uint8 module, uint8 level, const char *nums, const char *fmt, ...)
|
||||
{
|
||||
static char newFmt[] = "The number of parameters is invalid.";
|
||||
HiLogContent logContent = { 0 };
|
||||
int32 argsNum = (nums - FUN_ARG_S);
|
||||
if (argsNum < 0 || argsNum > LOG_MULTI_PARA_MAX) {
|
||||
fmt = newFmt;
|
||||
argsNum = 0;
|
||||
}
|
||||
|
||||
if (g_hiviewConfig.logSwitch == HIVIEW_FEATURE_OFF || !CheckParameters(module, level) ||
|
||||
LogIsLimited(module) || !LOG_IS_OUTPUT(module)) {
|
||||
return;
|
||||
}
|
||||
|
||||
HiLogCommon *pCommon = &(logContent.commonContent);
|
||||
pCommon->head = LOG_INFO_HEAD;
|
||||
pCommon->module = module;
|
||||
pCommon->level = level;
|
||||
pCommon->fmt = fmt;
|
||||
pCommon->valueNumber = (uint8)argsNum;
|
||||
pCommon->task = (uint8)HIVIEW_GetTaskId();
|
||||
pCommon->time = (uint32)(HIVIEW_GetCurrentTime() / MS_PER_SECOND);
|
||||
|
||||
uint8 i = 0;
|
||||
va_list args;
|
||||
va_start(args, fmt);
|
||||
while (i < argsNum) {
|
||||
logContent.values[i++] = va_arg(args, uint32);
|
||||
}
|
||||
va_end(args);
|
||||
|
||||
OutputLog((uint8 *)&logContent, sizeof(HiLogCommon) + sizeof(uint32) * argsNum);
|
||||
}
|
||||
@@ -1,104 +1,104 @@
|
||||
/*
|
||||
* Copyright (c) 2020 Huawei Device Co., Ltd.
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#include "hos_types.h"
|
||||
#include "hos_init.h"
|
||||
#include "hiview_def.h"
|
||||
#include "hiview_util.h"
|
||||
#include "hiview_config.h"
|
||||
#include "hiview_log.h"
|
||||
#include "hiview_log_limit.h"
|
||||
|
||||
#define LOG_LIMIT_CHECK_DURATION 60 /* seconds */
|
||||
#define LOG_LIMIT_LEVEL1 6 /* Maximum number of log records in a check period. */
|
||||
#define LOG_LIMIT_LEVEL2 30
|
||||
#define LOG_LIMIT_LEVEL3 60
|
||||
#define LOG_LIMIT_LEVEL4 120
|
||||
#define LOG_LIMIT_DEFAULT LOG_LIMIT_LEVEL2
|
||||
|
||||
static HiLogLimitRule *g_hilogLimitList = NULL;
|
||||
static void SetLimitThreshold(uint8 module, uint8 v);
|
||||
|
||||
void InitLogLimit(void)
|
||||
{
|
||||
if (g_hilogLimitList == NULL) {
|
||||
g_hilogLimitList = (HiLogLimitRule *)HIVIEW_MemAlloc(
|
||||
MEM_POOL_HIVIEW_ID, sizeof(HiLogLimitRule) * HILOG_MODULE_MAX);
|
||||
if (g_hilogLimitList == NULL) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
uint16 i;
|
||||
HiLogLimitRule *pRule = NULL;
|
||||
for (i = 0; i < HILOG_MODULE_MAX; i++) {
|
||||
pRule = g_hilogLimitList + i;
|
||||
pRule->maxNum = LOG_LIMIT_DEFAULT;
|
||||
pRule->logNum = 0;
|
||||
pRule->baseTime = 0;
|
||||
}
|
||||
SetLimitThreshold(HILOG_MODULE_HIVIEW, LOG_LIMIT_LEVEL3);
|
||||
SetLimitThreshold(HILOG_MODULE_APP, LOG_LIMIT_LEVEL2);
|
||||
HILOG_DEBUG(HILOG_MODULE_HIVIEW, "log limit init success.");
|
||||
}
|
||||
|
||||
boolean LogIsLimited(uint8 module)
|
||||
{
|
||||
/* covert ms to sec by dividing 1000, and integer overflow can be accepted */
|
||||
uint16 curTime = (uint16)(HIVIEW_GetCurrentTime() / MS_PER_SECOND);
|
||||
uint8 logNum;
|
||||
uint16 baseTime;
|
||||
HiLogLimitRule *pLimitRule = NULL;
|
||||
|
||||
if (module >= HILOG_MODULE_MAX) {
|
||||
return TRUE;
|
||||
}
|
||||
if (g_hilogLimitList == NULL) {
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
pLimitRule = g_hilogLimitList + module;
|
||||
if (pLimitRule->baseTime == 0) {
|
||||
pLimitRule->baseTime = (uint16)(HIVIEW_GetCurrentTime() / MS_PER_SECOND);
|
||||
}
|
||||
pLimitRule->logNum++;
|
||||
logNum = pLimitRule->logNum;
|
||||
baseTime = pLimitRule->baseTime;
|
||||
if ((curTime < baseTime) || ((curTime - baseTime) >= LOG_LIMIT_CHECK_DURATION)) {
|
||||
pLimitRule->baseTime = curTime;
|
||||
pLimitRule->logNum = 0;
|
||||
if (logNum > pLimitRule->maxNum) {
|
||||
HILOG_WARN(module, "log limit, drop lines %u", logNum - pLimitRule->maxNum);
|
||||
}
|
||||
} else {
|
||||
if (logNum > pLimitRule->maxNum) {
|
||||
return TRUE;
|
||||
}
|
||||
}
|
||||
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
static void SetLimitThreshold(uint8 module, uint8 v)
|
||||
{
|
||||
if (g_hilogLimitList == NULL) {
|
||||
return;
|
||||
}
|
||||
|
||||
HiLogLimitRule *pRule = g_hilogLimitList + module;
|
||||
pRule->maxNum = v;
|
||||
pRule->logNum = 0;
|
||||
pRule->baseTime = 0;
|
||||
/*
|
||||
* Copyright (c) 2020 Huawei Device Co., Ltd.
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#include "ohos_types.h"
|
||||
#include "ohos_init.h"
|
||||
#include "hiview_def.h"
|
||||
#include "hiview_util.h"
|
||||
#include "hiview_config.h"
|
||||
#include "hiview_log.h"
|
||||
#include "hiview_log_limit.h"
|
||||
|
||||
#define LOG_LIMIT_CHECK_DURATION 60 /* seconds */
|
||||
#define LOG_LIMIT_LEVEL1 6 /* Maximum number of log records in a check period. */
|
||||
#define LOG_LIMIT_LEVEL2 30
|
||||
#define LOG_LIMIT_LEVEL3 60
|
||||
#define LOG_LIMIT_LEVEL4 120
|
||||
#define LOG_LIMIT_DEFAULT LOG_LIMIT_LEVEL2
|
||||
|
||||
static HiLogLimitRule *g_hilogLimitList = NULL;
|
||||
static void SetLimitThreshold(uint8 module, uint8 v);
|
||||
|
||||
void InitLogLimit(void)
|
||||
{
|
||||
if (g_hilogLimitList == NULL) {
|
||||
g_hilogLimitList = (HiLogLimitRule *)HIVIEW_MemAlloc(
|
||||
MEM_POOL_HIVIEW_ID, sizeof(HiLogLimitRule) * HILOG_MODULE_MAX);
|
||||
if (g_hilogLimitList == NULL) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
uint16 i;
|
||||
HiLogLimitRule *pRule = NULL;
|
||||
for (i = 0; i < HILOG_MODULE_MAX; i++) {
|
||||
pRule = g_hilogLimitList + i;
|
||||
pRule->maxNum = LOG_LIMIT_DEFAULT;
|
||||
pRule->logNum = 0;
|
||||
pRule->baseTime = 0;
|
||||
}
|
||||
SetLimitThreshold(HILOG_MODULE_HIVIEW, LOG_LIMIT_LEVEL3);
|
||||
SetLimitThreshold(HILOG_MODULE_APP, LOG_LIMIT_LEVEL2);
|
||||
HILOG_DEBUG(HILOG_MODULE_HIVIEW, "log limit init success.");
|
||||
}
|
||||
|
||||
boolean LogIsLimited(uint8 module)
|
||||
{
|
||||
/* covert ms to sec by dividing 1000, and integer overflow can be accepted */
|
||||
uint16 curTime = (uint16)(HIVIEW_GetCurrentTime() / MS_PER_SECOND);
|
||||
uint8 logNum;
|
||||
uint16 baseTime;
|
||||
HiLogLimitRule *pLimitRule = NULL;
|
||||
|
||||
if (module >= HILOG_MODULE_MAX) {
|
||||
return TRUE;
|
||||
}
|
||||
if (g_hilogLimitList == NULL) {
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
pLimitRule = g_hilogLimitList + module;
|
||||
if (pLimitRule->baseTime == 0) {
|
||||
pLimitRule->baseTime = (uint16)(HIVIEW_GetCurrentTime() / MS_PER_SECOND);
|
||||
}
|
||||
pLimitRule->logNum++;
|
||||
logNum = pLimitRule->logNum;
|
||||
baseTime = pLimitRule->baseTime;
|
||||
if ((curTime < baseTime) || ((curTime - baseTime) >= LOG_LIMIT_CHECK_DURATION)) {
|
||||
pLimitRule->baseTime = curTime;
|
||||
pLimitRule->logNum = 0;
|
||||
if (logNum > pLimitRule->maxNum) {
|
||||
HILOG_WARN(module, "log limit, drop lines %u", logNum - pLimitRule->maxNum);
|
||||
}
|
||||
} else {
|
||||
if (logNum > pLimitRule->maxNum) {
|
||||
return TRUE;
|
||||
}
|
||||
}
|
||||
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
static void SetLimitThreshold(uint8 module, uint8 v)
|
||||
{
|
||||
if (g_hilogLimitList == NULL) {
|
||||
return;
|
||||
}
|
||||
|
||||
HiLogLimitRule *pRule = g_hilogLimitList + module;
|
||||
pRule->maxNum = v;
|
||||
pRule->logNum = 0;
|
||||
pRule->baseTime = 0;
|
||||
}
|
||||
@@ -1,43 +1,43 @@
|
||||
/*
|
||||
* Copyright (c) 2020 Huawei Device Co., Ltd.
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#ifndef HOS_LITE_HIVIEW_LOG_LIMIT_H
|
||||
#define HOS_LITE_HIVIEW_LOG_LIMIT_H
|
||||
|
||||
#include "hos_types.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
#if __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
#endif /* End of #ifdef __cplusplus */
|
||||
|
||||
/* The duration of the check is fixed at 60s. */
|
||||
typedef struct {
|
||||
uint8 maxNum; /* the max num limit of log line */
|
||||
uint8 logNum;
|
||||
uint16 baseTime;
|
||||
} HiLogLimitRule;
|
||||
|
||||
void InitLogLimit(void);
|
||||
boolean LogIsLimited(uint8 module);
|
||||
|
||||
#ifdef __cplusplus
|
||||
#if __cplusplus
|
||||
}
|
||||
#endif
|
||||
#endif /* End of #ifdef __cplusplus */
|
||||
|
||||
/*
|
||||
* Copyright (c) 2020 Huawei Device Co., Ltd.
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#ifndef HOS_LITE_HIVIEW_LOG_LIMIT_H
|
||||
#define HOS_LITE_HIVIEW_LOG_LIMIT_H
|
||||
|
||||
#include "ohos_types.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
#if __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
#endif /* End of #ifdef __cplusplus */
|
||||
|
||||
/* The duration of the check is fixed at 60s. */
|
||||
typedef struct {
|
||||
uint8 maxNum; /* the max num limit of log line */
|
||||
uint8 logNum;
|
||||
uint16 baseTime;
|
||||
} HiLogLimitRule;
|
||||
|
||||
void InitLogLimit(void);
|
||||
boolean LogIsLimited(uint8 module);
|
||||
|
||||
#ifdef __cplusplus
|
||||
#if __cplusplus
|
||||
}
|
||||
#endif
|
||||
#endif /* End of #ifdef __cplusplus */
|
||||
|
||||
#endif /* End of #ifndef HOS_LITE_HIVIEW_LOG_LIMIT_H */
|
||||
@@ -1,395 +1,395 @@
|
||||
/*
|
||||
* Copyright (c) 2020 Huawei Device Co., Ltd.
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#include "hiview_output_log.h"
|
||||
#include "hiview_def.h"
|
||||
#include "hiview_util.h"
|
||||
#include "hiview_cache.h"
|
||||
#include "hiview_config.h"
|
||||
#include "hiview_file.h"
|
||||
#include "hiview_log.h"
|
||||
#include "hiview_service.h"
|
||||
#include "message.h"
|
||||
#include "securec.h"
|
||||
#include "hos_types.h"
|
||||
|
||||
#define SINGLE_FMT_MAX_LEN 8
|
||||
#define FMT_CONVERT_TRMINATOR 2
|
||||
|
||||
static char g_logLevelInfo[HILOG_LV_MAX] = {
|
||||
'N', // "NONE"
|
||||
'D', // "DEBUG"
|
||||
'I', // "INFO"
|
||||
'W', // "WARN"
|
||||
'E', // "ERROR"
|
||||
'F' // "FATAL"
|
||||
};
|
||||
|
||||
static uint8 g_logCacheBuffer[LOG_STATIC_CACHE_SIZE];
|
||||
static HiviewCache g_logCache = {
|
||||
.size = 0,
|
||||
.buffer = NULL,
|
||||
};
|
||||
static HiviewFile g_logFile = {
|
||||
.path = HIVIEW_FILE_PATH_LOG,
|
||||
.fhandle = -1,
|
||||
};
|
||||
|
||||
/* Output the log to UART using plaintext. */
|
||||
static void OutputLogRealtime(const Request *req);
|
||||
/* Output the log to FLASH using text. */
|
||||
static void OutputLog2TextFile(const Request *req);
|
||||
/* Output the log to FLASH using binary. */
|
||||
static void OutputLog2BinFile(const Request *req);
|
||||
static int32 LogCommonFmt(char *outStr, int32 outStrlen, const HiLogCommon *commonContentPtr);
|
||||
static int32 LogValuesFmt(char *desStrPtr, int32 desLen, const HiLogContent *logContentPtr);
|
||||
static int32 LogDebugValuesFmt(char *desStrPtr, int32 desLen, const HiLogContent *logContentPtr);
|
||||
|
||||
void InitCoreLogOutput(void)
|
||||
{
|
||||
InitHiviewStaticCache(&g_logCache, LOG_CACHE, g_logCacheBuffer, sizeof(g_logCacheBuffer));
|
||||
HiviewRegisterMsgHandle(HIVIEW_MSG_OUTPUT_LOG_TEXT_FILE, OutputLog2TextFile);
|
||||
HiviewRegisterMsgHandle(HIVIEW_MSG_OUTPUT_LOG_BIN_FILE, OutputLog2BinFile);
|
||||
HiviewRegisterMsgHandle(HIVIEW_MSG_OUTPUT_LOG_FLOW, OutputLogRealtime);
|
||||
}
|
||||
|
||||
void InitLogOutput(void)
|
||||
{
|
||||
if (g_hiviewConfig.outputOption == OUTPUT_OPTION_DEBUG ||
|
||||
g_hiviewConfig.outputOption == OUTPUT_OPTION_FLOW) {
|
||||
return;
|
||||
}
|
||||
HiviewFileType type = HIVIEW_LOG_TEXT_FILE;
|
||||
if (g_hiviewConfig.outputOption == OUTPUT_OPTION_BIN_FILE) {
|
||||
type = HIVIEW_LOG_BIN_FILE;
|
||||
}
|
||||
if (InitHiviewFile(&g_logFile, type,
|
||||
(HIVIEW_LOG_FILE_SIZE / sizeof(HiLogContent)) * sizeof(HiLogContent)) == FALSE) {
|
||||
HILOG_ERROR(HILOG_MODULE_HIVIEW, "Open file[%d] failed.", HIVIEW_LOG_BIN_FILE);
|
||||
}
|
||||
}
|
||||
|
||||
void ClearLogOutput(void)
|
||||
{
|
||||
if (g_logCache.usedSize > 0) {
|
||||
if (g_hiviewConfig.outputOption == OUTPUT_OPTION_TEXT_FILE) {
|
||||
OutputLog2TextFile(NULL);
|
||||
} else if (g_hiviewConfig.outputOption == OUTPUT_OPTION_BIN_FILE) {
|
||||
OutputLog2BinFile(NULL);
|
||||
}
|
||||
}
|
||||
CloseHiviewFile(&g_logFile);
|
||||
}
|
||||
|
||||
void OutputLog(const uint8 *data, uint32 len)
|
||||
{
|
||||
if (data == NULL) {
|
||||
return;
|
||||
}
|
||||
|
||||
/* When the init of kernel is not finished, data is cached in the cache. */
|
||||
if (g_hiviewConfig.hiviewInited == FALSE) {
|
||||
if (WriteToCache(&g_logCache, data, len) != (int32)len) {
|
||||
HILOG_INFO(HILOG_MODULE_HIVIEW, "Write log to cache failed.");
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
if (g_hiviewConfig.outputOption == OUTPUT_OPTION_DEBUG) {
|
||||
char tempOutStr[LOG_FMT_MAX_LEN] = {0};
|
||||
if (LogContentFmt(tempOutStr, sizeof(tempOutStr), data) > 0) {
|
||||
HIVIEW_UartPrint(tempOutStr);
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
if (WriteToCache(&g_logCache, (uint8 *)data, len) == (int32)len) {
|
||||
if (g_logCache.usedSize >= HIVIEW_FILE_BUF_SIZE) {
|
||||
switch (g_hiviewConfig.outputOption) {
|
||||
case OUTPUT_OPTION_TEXT_FILE:
|
||||
HiviewSendMessage(HIVIEW_SERVICE, HIVIEW_MSG_OUTPUT_LOG_TEXT_FILE, 0);
|
||||
break;
|
||||
case OUTPUT_OPTION_BIN_FILE:
|
||||
HiviewSendMessage(HIVIEW_SERVICE, HIVIEW_MSG_OUTPUT_LOG_BIN_FILE, 0);
|
||||
break;
|
||||
case OUTPUT_OPTION_FLOW:
|
||||
HiviewSendMessage(HIVIEW_SERVICE, HIVIEW_MSG_OUTPUT_LOG_FLOW, 0);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static void OutputLogRealtime(const Request *req)
|
||||
{
|
||||
HiLogContent logContent;
|
||||
char tempOutStr[LOG_FMT_MAX_LEN] = {0};
|
||||
int32 len;
|
||||
(void)req;
|
||||
|
||||
while (ReadFromCache(&g_logCache, (uint8 *)&(logContent.commonContent),
|
||||
sizeof(HiLogCommon)) == sizeof(HiLogCommon)) {
|
||||
if (logContent.commonContent.head != LOG_INFO_HEAD) {
|
||||
DiscardCacheData(&g_logCache);
|
||||
HILOG_ERROR(HILOG_MODULE_HIVIEW, "Discard cache[%d] data.", LOG_CACHE);
|
||||
break;
|
||||
}
|
||||
len = logContent.commonContent.valueNumber * sizeof(uint32);
|
||||
if (len > 0 && ReadFromCache(&g_logCache, (uint8 *)&(logContent.values), len) != len) {
|
||||
continue;
|
||||
}
|
||||
len = LogContentFmt(tempOutStr, sizeof(tempOutStr), (uint8 *)&logContent);
|
||||
if (len <= 0) {
|
||||
continue;
|
||||
}
|
||||
HIVIEW_UartPrint(tempOutStr);
|
||||
}
|
||||
}
|
||||
|
||||
static void OutputLog2TextFile(const Request *req)
|
||||
{
|
||||
HiLogContent logContent;
|
||||
char tempOutStr[LOG_FMT_MAX_LEN] = {0};
|
||||
(void)req;
|
||||
|
||||
if (g_logCache.usedSize < sizeof(HiLogCommon)) {
|
||||
return;
|
||||
}
|
||||
|
||||
int32 len;
|
||||
while (ReadFromCache(&g_logCache, (uint8 *)&(logContent.commonContent),
|
||||
sizeof(HiLogCommon)) == sizeof(HiLogCommon)) {
|
||||
if (logContent.commonContent.head != LOG_INFO_HEAD) {
|
||||
DiscardCacheData(&g_logCache);
|
||||
HILOG_ERROR(HILOG_MODULE_HIVIEW, "Discard cache[%d] data.", LOG_CACHE);
|
||||
break;
|
||||
}
|
||||
len = logContent.commonContent.valueNumber * sizeof(uint32);
|
||||
if (len > 0 && ReadFromCache(&g_logCache, (uint8 *)&(logContent.values), len) != len) {
|
||||
continue;
|
||||
}
|
||||
len = LogContentFmt(tempOutStr, sizeof(tempOutStr), (uint8 *)&logContent);
|
||||
if (len > 0 && WriteToFile(&g_logFile, (uint8 *)tempOutStr, len) != len) {
|
||||
g_hiviewConfig.writeFailureCount++;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static void OutputLog2BinFile(const Request *req)
|
||||
{
|
||||
HiLogCommon *pCommonContent = NULL;
|
||||
uint16 len = 0;
|
||||
uint16 valueLen;
|
||||
uint8 *tmpBuffer = NULL;
|
||||
uint16 outputSize = g_logCache.usedSize;
|
||||
(void)req;
|
||||
|
||||
if (outputSize < sizeof(HiLogCommon)) {
|
||||
return;
|
||||
}
|
||||
tmpBuffer = (uint8 *)HIVIEW_MemAlloc(MEM_POOL_HIVIEW_ID, outputSize);
|
||||
if (tmpBuffer == NULL) {
|
||||
return;
|
||||
}
|
||||
while (g_logCache.usedSize >= sizeof(HiLogCommon) && outputSize > (len + sizeof(HiLogCommon))) {
|
||||
if (ReadFromCache(&g_logCache, tmpBuffer + len, sizeof(HiLogCommon)) != sizeof(HiLogCommon)) {
|
||||
continue;
|
||||
}
|
||||
pCommonContent = (HiLogCommon *)(tmpBuffer + len);
|
||||
len += sizeof(HiLogCommon);
|
||||
if (pCommonContent->head != LOG_INFO_HEAD) {
|
||||
DiscardCacheData(&g_logCache);
|
||||
HILOG_ERROR(HILOG_MODULE_HIVIEW, "Discard cache[%d] data.", LOG_CACHE);
|
||||
break;
|
||||
}
|
||||
valueLen = pCommonContent->valueNumber * sizeof(uint32);
|
||||
if (valueLen > 0) {
|
||||
if (ReadFromCache(&g_logCache, tmpBuffer + len, valueLen) != valueLen) {
|
||||
continue;
|
||||
}
|
||||
len += valueLen;
|
||||
}
|
||||
}
|
||||
if (len > 0 && WriteToFile(&g_logFile, tmpBuffer, len) != len) {
|
||||
g_hiviewConfig.writeFailureCount++;
|
||||
HILOG_ERROR(HILOG_MODULE_HIVIEW, "Failed to write log data.");
|
||||
}
|
||||
HIVIEW_MemFree(MEM_POOL_HIVIEW_ID, tmpBuffer);
|
||||
}
|
||||
|
||||
uint32 GetLogFileSize(void)
|
||||
{
|
||||
return GetFileUsedSize(&g_logFile);
|
||||
}
|
||||
|
||||
uint32 ReadLogFile(uint8 *buf, uint32 len)
|
||||
{
|
||||
if (buf == NULL) {
|
||||
return 0;
|
||||
}
|
||||
uint32 usedSize = GetFileUsedSize(&g_logFile);
|
||||
if (usedSize < len) {
|
||||
len = usedSize;
|
||||
}
|
||||
if (ReadFromFile(&g_logFile, buf, len) != (int32)len) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
return len;
|
||||
}
|
||||
|
||||
int32 LogContentFmt(char *outStr, int32 outStrLen, const uint8 *pLogContent)
|
||||
{
|
||||
int32 len;
|
||||
HiLogContent *logContentPtr = (HiLogContent *)pLogContent;
|
||||
|
||||
len = LogCommonFmt(outStr, outStrLen, &(logContentPtr->commonContent));
|
||||
if (len >= 0) {
|
||||
if (g_hiviewConfig.outputOption == OUTPUT_OPTION_DEBUG) {
|
||||
len += LogDebugValuesFmt(outStr + len, outStrLen - len, logContentPtr);
|
||||
} else {
|
||||
len += LogValuesFmt(outStr + len, outStrLen - len, logContentPtr);
|
||||
}
|
||||
}
|
||||
|
||||
if (len < 0) {
|
||||
return len;
|
||||
}
|
||||
|
||||
if (len >= outStrLen - 1) {
|
||||
outStr[outStrLen - TAIL_LINE_BREAK] = '\n';
|
||||
outStr[outStrLen - 1] = '\0';
|
||||
} else {
|
||||
outStr[len++] = '\n';
|
||||
outStr[len++] = '\0';
|
||||
}
|
||||
|
||||
return len;
|
||||
}
|
||||
|
||||
static int32 LogCommonFmt(char *outStr, int32 outStrLen, const HiLogCommon *commonContentPtr)
|
||||
{
|
||||
int32 ret;
|
||||
uint32 time, day, hour, mte, sec;
|
||||
|
||||
time = commonContentPtr->time;
|
||||
day = time / SECONDS_PER_DAY;
|
||||
hour = time % SECONDS_PER_DAY / SECONDS_PER_HOUR;
|
||||
mte = time % SECONDS_PER_HOUR / SECONDS_PER_MINUTE;
|
||||
sec = time % SECONDS_PER_MINUTE;
|
||||
ret = snprintf_s(outStr, outStrLen, outStrLen - 1, "%02d %02d:%02d:%02d 0 %d %c %d/%s: ",
|
||||
day, hour, mte, sec, commonContentPtr->task, g_logLevelInfo[commonContentPtr->level],
|
||||
commonContentPtr->module, HiLogGetModuleName(commonContentPtr->module));
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
static int32 LogValuesFmt(char *desStrPtr, int32 desLen, const HiLogContent *logContentPtr)
|
||||
{
|
||||
int32 i;
|
||||
int32 outLen = 0;
|
||||
int32 len;
|
||||
char fmtStr[SINGLE_FMT_MAX_LEN];
|
||||
uint32 valNum = logContentPtr->commonContent.valueNumber;
|
||||
const char *fmt = logContentPtr->commonContent.fmt;
|
||||
uint32 valueIndex = 0;
|
||||
for (i = 0; fmt[i] != 0 && outLen < desLen;) {
|
||||
if (fmt[i] != '%') {
|
||||
desStrPtr[outLen++] = fmt[i++];
|
||||
continue;
|
||||
}
|
||||
if (fmt[i + 1] == '%') {
|
||||
desStrPtr[outLen++] = fmt[i++];
|
||||
desStrPtr[outLen++] = fmt[i++];
|
||||
continue;
|
||||
}
|
||||
fmtStr[0] = fmt[i++];
|
||||
uint32 t = 1;
|
||||
while (fmt[i] != 0 && t < sizeof(fmtStr) - 1) {
|
||||
/* %s %ms %-ms %m.ns %-m.ns convert to %p */
|
||||
if ((fmt[i] == 's' || fmt[i] == 'S') &&
|
||||
(fmt[i - 1] == '%' || (fmt[i - 1] >= '0' && fmt[i - 1] <= '9'))) {
|
||||
fmtStr[1] = 'p';
|
||||
fmtStr[FMT_CONVERT_TRMINATOR] = 0;
|
||||
i++;
|
||||
break;
|
||||
}
|
||||
if ((fmt[i] >= 'a' && fmt[i] <= 'z') || (fmt[i] >= 'A' && fmt[i] <= 'Z')) {
|
||||
fmtStr[t++] = fmt[i++];
|
||||
fmtStr[t] = 0;
|
||||
break;
|
||||
}
|
||||
fmtStr[t++] = fmt[i++];
|
||||
}
|
||||
if (valueIndex < valNum) {
|
||||
len = snprintf_s(&desStrPtr[outLen], desLen - outLen, desLen - outLen - 1,
|
||||
fmtStr, logContentPtr->values[valueIndex]);
|
||||
if (len < 0) {
|
||||
break;
|
||||
}
|
||||
outLen += len;
|
||||
valueIndex++;
|
||||
}
|
||||
}
|
||||
|
||||
return outLen;
|
||||
}
|
||||
|
||||
static int32 LogDebugValuesFmt(char *desStrPtr, int32 desLen, const HiLogContent *logContentPtr)
|
||||
{
|
||||
int32 ret = 0;
|
||||
switch (logContentPtr->commonContent.valueNumber) {
|
||||
case LOG_MULTI_PARA_0:
|
||||
ret = strncpy_s(desStrPtr, desLen, logContentPtr->commonContent.fmt, desLen - 1);
|
||||
break;
|
||||
case LOG_MULTI_PARA_1:
|
||||
ret = snprintf_s(desStrPtr, desLen, desLen - 1, logContentPtr->commonContent.fmt,
|
||||
logContentPtr->values[0]);
|
||||
break;
|
||||
case LOG_MULTI_PARA_2:
|
||||
ret = snprintf_s(desStrPtr, desLen, desLen - 1, logContentPtr->commonContent.fmt,
|
||||
logContentPtr->values[0], logContentPtr->values[1]);
|
||||
break;
|
||||
case LOG_MULTI_PARA_3:
|
||||
ret = snprintf_s(desStrPtr, desLen, desLen - 1, logContentPtr->commonContent.fmt,
|
||||
logContentPtr->values[0], logContentPtr->values[1], logContentPtr->values[LOG_MULTI_PARA_2]);
|
||||
break;
|
||||
case LOG_MULTI_PARA_4:
|
||||
ret = snprintf_s(desStrPtr, desLen, desLen - 1, logContentPtr->commonContent.fmt,
|
||||
logContentPtr->values[0], logContentPtr->values[1], logContentPtr->values[LOG_MULTI_PARA_2],
|
||||
logContentPtr->values[LOG_MULTI_PARA_3]);
|
||||
break;
|
||||
case LOG_MULTI_PARA_5:
|
||||
ret = snprintf_s(desStrPtr, desLen, desLen - 1, logContentPtr->commonContent.fmt,
|
||||
logContentPtr->values[0], logContentPtr->values[1], logContentPtr->values[LOG_MULTI_PARA_2],
|
||||
logContentPtr->values[LOG_MULTI_PARA_3], logContentPtr->values[LOG_MULTI_PARA_4]);
|
||||
break;
|
||||
case LOG_MULTI_PARA_MAX:
|
||||
ret = snprintf_s(desStrPtr, desLen, desLen - 1, logContentPtr->commonContent.fmt,
|
||||
logContentPtr->values[0], logContentPtr->values[1], logContentPtr->values[LOG_MULTI_PARA_2],
|
||||
logContentPtr->values[LOG_MULTI_PARA_3], logContentPtr->values[LOG_MULTI_PARA_4],
|
||||
logContentPtr->values[LOG_MULTI_PARA_5]);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
if (ret < 0) {
|
||||
ret = 0;
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
/*
|
||||
* Copyright (c) 2020 Huawei Device Co., Ltd.
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#include "hiview_output_log.h"
|
||||
#include "hiview_def.h"
|
||||
#include "hiview_util.h"
|
||||
#include "hiview_cache.h"
|
||||
#include "hiview_config.h"
|
||||
#include "hiview_file.h"
|
||||
#include "hiview_log.h"
|
||||
#include "hiview_service.h"
|
||||
#include "message.h"
|
||||
#include "securec.h"
|
||||
#include "ohos_types.h"
|
||||
|
||||
#define SINGLE_FMT_MAX_LEN 8
|
||||
#define FMT_CONVERT_TRMINATOR 2
|
||||
|
||||
static char g_logLevelInfo[HILOG_LV_MAX] = {
|
||||
'N', // "NONE"
|
||||
'D', // "DEBUG"
|
||||
'I', // "INFO"
|
||||
'W', // "WARN"
|
||||
'E', // "ERROR"
|
||||
'F' // "FATAL"
|
||||
};
|
||||
|
||||
static uint8 g_logCacheBuffer[LOG_STATIC_CACHE_SIZE];
|
||||
static HiviewCache g_logCache = {
|
||||
.size = 0,
|
||||
.buffer = NULL,
|
||||
};
|
||||
static HiviewFile g_logFile = {
|
||||
.path = HIVIEW_FILE_PATH_LOG,
|
||||
.fhandle = -1,
|
||||
};
|
||||
|
||||
/* Output the log to UART using plaintext. */
|
||||
static void OutputLogRealtime(const Request *req);
|
||||
/* Output the log to FLASH using text. */
|
||||
static void OutputLog2TextFile(const Request *req);
|
||||
/* Output the log to FLASH using binary. */
|
||||
static void OutputLog2BinFile(const Request *req);
|
||||
static int32 LogCommonFmt(char *outStr, int32 outStrlen, const HiLogCommon *commonContentPtr);
|
||||
static int32 LogValuesFmt(char *desStrPtr, int32 desLen, const HiLogContent *logContentPtr);
|
||||
static int32 LogDebugValuesFmt(char *desStrPtr, int32 desLen, const HiLogContent *logContentPtr);
|
||||
|
||||
void InitCoreLogOutput(void)
|
||||
{
|
||||
InitHiviewStaticCache(&g_logCache, LOG_CACHE, g_logCacheBuffer, sizeof(g_logCacheBuffer));
|
||||
HiviewRegisterMsgHandle(HIVIEW_MSG_OUTPUT_LOG_TEXT_FILE, OutputLog2TextFile);
|
||||
HiviewRegisterMsgHandle(HIVIEW_MSG_OUTPUT_LOG_BIN_FILE, OutputLog2BinFile);
|
||||
HiviewRegisterMsgHandle(HIVIEW_MSG_OUTPUT_LOG_FLOW, OutputLogRealtime);
|
||||
}
|
||||
|
||||
void InitLogOutput(void)
|
||||
{
|
||||
if (g_hiviewConfig.outputOption == OUTPUT_OPTION_DEBUG ||
|
||||
g_hiviewConfig.outputOption == OUTPUT_OPTION_FLOW) {
|
||||
return;
|
||||
}
|
||||
HiviewFileType type = HIVIEW_LOG_TEXT_FILE;
|
||||
if (g_hiviewConfig.outputOption == OUTPUT_OPTION_BIN_FILE) {
|
||||
type = HIVIEW_LOG_BIN_FILE;
|
||||
}
|
||||
if (InitHiviewFile(&g_logFile, type,
|
||||
(HIVIEW_LOG_FILE_SIZE / sizeof(HiLogContent)) * sizeof(HiLogContent)) == FALSE) {
|
||||
HILOG_ERROR(HILOG_MODULE_HIVIEW, "Open file[%d] failed.", HIVIEW_LOG_BIN_FILE);
|
||||
}
|
||||
}
|
||||
|
||||
void ClearLogOutput(void)
|
||||
{
|
||||
if (g_logCache.usedSize > 0) {
|
||||
if (g_hiviewConfig.outputOption == OUTPUT_OPTION_TEXT_FILE) {
|
||||
OutputLog2TextFile(NULL);
|
||||
} else if (g_hiviewConfig.outputOption == OUTPUT_OPTION_BIN_FILE) {
|
||||
OutputLog2BinFile(NULL);
|
||||
}
|
||||
}
|
||||
CloseHiviewFile(&g_logFile);
|
||||
}
|
||||
|
||||
void OutputLog(const uint8 *data, uint32 len)
|
||||
{
|
||||
if (data == NULL) {
|
||||
return;
|
||||
}
|
||||
|
||||
/* When the init of kernel is not finished, data is cached in the cache. */
|
||||
if (g_hiviewConfig.hiviewInited == FALSE) {
|
||||
if (WriteToCache(&g_logCache, data, len) != (int32)len) {
|
||||
HILOG_INFO(HILOG_MODULE_HIVIEW, "Write log to cache failed.");
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
if (g_hiviewConfig.outputOption == OUTPUT_OPTION_DEBUG) {
|
||||
char tempOutStr[LOG_FMT_MAX_LEN] = {0};
|
||||
if (LogContentFmt(tempOutStr, sizeof(tempOutStr), data) > 0) {
|
||||
HIVIEW_UartPrint(tempOutStr);
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
if (WriteToCache(&g_logCache, (uint8 *)data, len) == (int32)len) {
|
||||
if (g_logCache.usedSize >= HIVIEW_FILE_BUF_SIZE) {
|
||||
switch (g_hiviewConfig.outputOption) {
|
||||
case OUTPUT_OPTION_TEXT_FILE:
|
||||
HiviewSendMessage(HIVIEW_SERVICE, HIVIEW_MSG_OUTPUT_LOG_TEXT_FILE, 0);
|
||||
break;
|
||||
case OUTPUT_OPTION_BIN_FILE:
|
||||
HiviewSendMessage(HIVIEW_SERVICE, HIVIEW_MSG_OUTPUT_LOG_BIN_FILE, 0);
|
||||
break;
|
||||
case OUTPUT_OPTION_FLOW:
|
||||
HiviewSendMessage(HIVIEW_SERVICE, HIVIEW_MSG_OUTPUT_LOG_FLOW, 0);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static void OutputLogRealtime(const Request *req)
|
||||
{
|
||||
HiLogContent logContent;
|
||||
char tempOutStr[LOG_FMT_MAX_LEN] = {0};
|
||||
int32 len;
|
||||
(void)req;
|
||||
|
||||
while (ReadFromCache(&g_logCache, (uint8 *)&(logContent.commonContent),
|
||||
sizeof(HiLogCommon)) == sizeof(HiLogCommon)) {
|
||||
if (logContent.commonContent.head != LOG_INFO_HEAD) {
|
||||
DiscardCacheData(&g_logCache);
|
||||
HILOG_ERROR(HILOG_MODULE_HIVIEW, "Discard cache[%d] data.", LOG_CACHE);
|
||||
break;
|
||||
}
|
||||
len = logContent.commonContent.valueNumber * sizeof(uint32);
|
||||
if (len > 0 && ReadFromCache(&g_logCache, (uint8 *)&(logContent.values), len) != len) {
|
||||
continue;
|
||||
}
|
||||
len = LogContentFmt(tempOutStr, sizeof(tempOutStr), (uint8 *)&logContent);
|
||||
if (len <= 0) {
|
||||
continue;
|
||||
}
|
||||
HIVIEW_UartPrint(tempOutStr);
|
||||
}
|
||||
}
|
||||
|
||||
static void OutputLog2TextFile(const Request *req)
|
||||
{
|
||||
HiLogContent logContent;
|
||||
char tempOutStr[LOG_FMT_MAX_LEN] = {0};
|
||||
(void)req;
|
||||
|
||||
if (g_logCache.usedSize < sizeof(HiLogCommon)) {
|
||||
return;
|
||||
}
|
||||
|
||||
int32 len;
|
||||
while (ReadFromCache(&g_logCache, (uint8 *)&(logContent.commonContent),
|
||||
sizeof(HiLogCommon)) == sizeof(HiLogCommon)) {
|
||||
if (logContent.commonContent.head != LOG_INFO_HEAD) {
|
||||
DiscardCacheData(&g_logCache);
|
||||
HILOG_ERROR(HILOG_MODULE_HIVIEW, "Discard cache[%d] data.", LOG_CACHE);
|
||||
break;
|
||||
}
|
||||
len = logContent.commonContent.valueNumber * sizeof(uint32);
|
||||
if (len > 0 && ReadFromCache(&g_logCache, (uint8 *)&(logContent.values), len) != len) {
|
||||
continue;
|
||||
}
|
||||
len = LogContentFmt(tempOutStr, sizeof(tempOutStr), (uint8 *)&logContent);
|
||||
if (len > 0 && WriteToFile(&g_logFile, (uint8 *)tempOutStr, len) != len) {
|
||||
g_hiviewConfig.writeFailureCount++;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static void OutputLog2BinFile(const Request *req)
|
||||
{
|
||||
HiLogCommon *pCommonContent = NULL;
|
||||
uint16 len = 0;
|
||||
uint16 valueLen;
|
||||
uint8 *tmpBuffer = NULL;
|
||||
uint16 outputSize = g_logCache.usedSize;
|
||||
(void)req;
|
||||
|
||||
if (outputSize < sizeof(HiLogCommon)) {
|
||||
return;
|
||||
}
|
||||
tmpBuffer = (uint8 *)HIVIEW_MemAlloc(MEM_POOL_HIVIEW_ID, outputSize);
|
||||
if (tmpBuffer == NULL) {
|
||||
return;
|
||||
}
|
||||
while (g_logCache.usedSize >= sizeof(HiLogCommon) && outputSize > (len + sizeof(HiLogCommon))) {
|
||||
if (ReadFromCache(&g_logCache, tmpBuffer + len, sizeof(HiLogCommon)) != sizeof(HiLogCommon)) {
|
||||
continue;
|
||||
}
|
||||
pCommonContent = (HiLogCommon *)(tmpBuffer + len);
|
||||
len += sizeof(HiLogCommon);
|
||||
if (pCommonContent->head != LOG_INFO_HEAD) {
|
||||
DiscardCacheData(&g_logCache);
|
||||
HILOG_ERROR(HILOG_MODULE_HIVIEW, "Discard cache[%d] data.", LOG_CACHE);
|
||||
break;
|
||||
}
|
||||
valueLen = pCommonContent->valueNumber * sizeof(uint32);
|
||||
if (valueLen > 0) {
|
||||
if (ReadFromCache(&g_logCache, tmpBuffer + len, valueLen) != valueLen) {
|
||||
continue;
|
||||
}
|
||||
len += valueLen;
|
||||
}
|
||||
}
|
||||
if (len > 0 && WriteToFile(&g_logFile, tmpBuffer, len) != len) {
|
||||
g_hiviewConfig.writeFailureCount++;
|
||||
HILOG_ERROR(HILOG_MODULE_HIVIEW, "Failed to write log data.");
|
||||
}
|
||||
HIVIEW_MemFree(MEM_POOL_HIVIEW_ID, tmpBuffer);
|
||||
}
|
||||
|
||||
uint32 GetLogFileSize(void)
|
||||
{
|
||||
return GetFileUsedSize(&g_logFile);
|
||||
}
|
||||
|
||||
uint32 ReadLogFile(uint8 *buf, uint32 len)
|
||||
{
|
||||
if (buf == NULL) {
|
||||
return 0;
|
||||
}
|
||||
uint32 usedSize = GetFileUsedSize(&g_logFile);
|
||||
if (usedSize < len) {
|
||||
len = usedSize;
|
||||
}
|
||||
if (ReadFromFile(&g_logFile, buf, len) != (int32)len) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
return len;
|
||||
}
|
||||
|
||||
int32 LogContentFmt(char *outStr, int32 outStrLen, const uint8 *pLogContent)
|
||||
{
|
||||
int32 len;
|
||||
HiLogContent *logContentPtr = (HiLogContent *)pLogContent;
|
||||
|
||||
len = LogCommonFmt(outStr, outStrLen, &(logContentPtr->commonContent));
|
||||
if (len >= 0) {
|
||||
if (g_hiviewConfig.outputOption == OUTPUT_OPTION_DEBUG) {
|
||||
len += LogDebugValuesFmt(outStr + len, outStrLen - len, logContentPtr);
|
||||
} else {
|
||||
len += LogValuesFmt(outStr + len, outStrLen - len, logContentPtr);
|
||||
}
|
||||
}
|
||||
|
||||
if (len < 0) {
|
||||
return len;
|
||||
}
|
||||
|
||||
if (len >= outStrLen - 1) {
|
||||
outStr[outStrLen - TAIL_LINE_BREAK] = '\n';
|
||||
outStr[outStrLen - 1] = '\0';
|
||||
} else {
|
||||
outStr[len++] = '\n';
|
||||
outStr[len++] = '\0';
|
||||
}
|
||||
|
||||
return len;
|
||||
}
|
||||
|
||||
static int32 LogCommonFmt(char *outStr, int32 outStrLen, const HiLogCommon *commonContentPtr)
|
||||
{
|
||||
int32 ret;
|
||||
uint32 time, day, hour, mte, sec;
|
||||
|
||||
time = commonContentPtr->time;
|
||||
day = time / SECONDS_PER_DAY;
|
||||
hour = time % SECONDS_PER_DAY / SECONDS_PER_HOUR;
|
||||
mte = time % SECONDS_PER_HOUR / SECONDS_PER_MINUTE;
|
||||
sec = time % SECONDS_PER_MINUTE;
|
||||
ret = snprintf_s(outStr, outStrLen, outStrLen - 1, "%02d %02d:%02d:%02d 0 %d %c %d/%s: ",
|
||||
day, hour, mte, sec, commonContentPtr->task, g_logLevelInfo[commonContentPtr->level],
|
||||
commonContentPtr->module, HiLogGetModuleName(commonContentPtr->module));
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
static int32 LogValuesFmt(char *desStrPtr, int32 desLen, const HiLogContent *logContentPtr)
|
||||
{
|
||||
int32 i;
|
||||
int32 outLen = 0;
|
||||
int32 len;
|
||||
char fmtStr[SINGLE_FMT_MAX_LEN];
|
||||
uint32 valNum = logContentPtr->commonContent.valueNumber;
|
||||
const char *fmt = logContentPtr->commonContent.fmt;
|
||||
uint32 valueIndex = 0;
|
||||
for (i = 0; fmt[i] != 0 && outLen < desLen;) {
|
||||
if (fmt[i] != '%') {
|
||||
desStrPtr[outLen++] = fmt[i++];
|
||||
continue;
|
||||
}
|
||||
if (fmt[i + 1] == '%') {
|
||||
desStrPtr[outLen++] = fmt[i++];
|
||||
desStrPtr[outLen++] = fmt[i++];
|
||||
continue;
|
||||
}
|
||||
fmtStr[0] = fmt[i++];
|
||||
uint32 t = 1;
|
||||
while (fmt[i] != 0 && t < sizeof(fmtStr) - 1) {
|
||||
/* %s %ms %-ms %m.ns %-m.ns convert to %p */
|
||||
if ((fmt[i] == 's' || fmt[i] == 'S') &&
|
||||
(fmt[i - 1] == '%' || (fmt[i - 1] >= '0' && fmt[i - 1] <= '9'))) {
|
||||
fmtStr[1] = 'p';
|
||||
fmtStr[FMT_CONVERT_TRMINATOR] = 0;
|
||||
i++;
|
||||
break;
|
||||
}
|
||||
if ((fmt[i] >= 'a' && fmt[i] <= 'z') || (fmt[i] >= 'A' && fmt[i] <= 'Z')) {
|
||||
fmtStr[t++] = fmt[i++];
|
||||
fmtStr[t] = 0;
|
||||
break;
|
||||
}
|
||||
fmtStr[t++] = fmt[i++];
|
||||
}
|
||||
if (valueIndex < valNum) {
|
||||
len = snprintf_s(&desStrPtr[outLen], desLen - outLen, desLen - outLen - 1,
|
||||
fmtStr, logContentPtr->values[valueIndex]);
|
||||
if (len < 0) {
|
||||
break;
|
||||
}
|
||||
outLen += len;
|
||||
valueIndex++;
|
||||
}
|
||||
}
|
||||
|
||||
return outLen;
|
||||
}
|
||||
|
||||
static int32 LogDebugValuesFmt(char *desStrPtr, int32 desLen, const HiLogContent *logContentPtr)
|
||||
{
|
||||
int32 ret = 0;
|
||||
switch (logContentPtr->commonContent.valueNumber) {
|
||||
case LOG_MULTI_PARA_0:
|
||||
ret = strncpy_s(desStrPtr, desLen, logContentPtr->commonContent.fmt, desLen - 1);
|
||||
break;
|
||||
case LOG_MULTI_PARA_1:
|
||||
ret = snprintf_s(desStrPtr, desLen, desLen - 1, logContentPtr->commonContent.fmt,
|
||||
logContentPtr->values[0]);
|
||||
break;
|
||||
case LOG_MULTI_PARA_2:
|
||||
ret = snprintf_s(desStrPtr, desLen, desLen - 1, logContentPtr->commonContent.fmt,
|
||||
logContentPtr->values[0], logContentPtr->values[1]);
|
||||
break;
|
||||
case LOG_MULTI_PARA_3:
|
||||
ret = snprintf_s(desStrPtr, desLen, desLen - 1, logContentPtr->commonContent.fmt,
|
||||
logContentPtr->values[0], logContentPtr->values[1], logContentPtr->values[LOG_MULTI_PARA_2]);
|
||||
break;
|
||||
case LOG_MULTI_PARA_4:
|
||||
ret = snprintf_s(desStrPtr, desLen, desLen - 1, logContentPtr->commonContent.fmt,
|
||||
logContentPtr->values[0], logContentPtr->values[1], logContentPtr->values[LOG_MULTI_PARA_2],
|
||||
logContentPtr->values[LOG_MULTI_PARA_3]);
|
||||
break;
|
||||
case LOG_MULTI_PARA_5:
|
||||
ret = snprintf_s(desStrPtr, desLen, desLen - 1, logContentPtr->commonContent.fmt,
|
||||
logContentPtr->values[0], logContentPtr->values[1], logContentPtr->values[LOG_MULTI_PARA_2],
|
||||
logContentPtr->values[LOG_MULTI_PARA_3], logContentPtr->values[LOG_MULTI_PARA_4]);
|
||||
break;
|
||||
case LOG_MULTI_PARA_MAX:
|
||||
ret = snprintf_s(desStrPtr, desLen, desLen - 1, logContentPtr->commonContent.fmt,
|
||||
logContentPtr->values[0], logContentPtr->values[1], logContentPtr->values[LOG_MULTI_PARA_2],
|
||||
logContentPtr->values[LOG_MULTI_PARA_3], logContentPtr->values[LOG_MULTI_PARA_4],
|
||||
logContentPtr->values[LOG_MULTI_PARA_5]);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
if (ret < 0) {
|
||||
ret = 0;
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
@@ -1,67 +1,67 @@
|
||||
/*
|
||||
* Copyright (c) 2020 Huawei Device Co., Ltd.
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#ifndef HOS_LITE_HIVIEW_OUTPUT_LOG_H
|
||||
#define HOS_LITE_HIVIEW_OUTPUT_LOG_H
|
||||
|
||||
#include "hos_types.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
#if __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
#endif /* End of #ifdef __cplusplus */
|
||||
|
||||
void InitCoreLogOutput(void);
|
||||
void InitLogOutput(void);
|
||||
void ClearLogOutput(void);
|
||||
|
||||
/**
|
||||
* Output the log to file.
|
||||
* @param data HiLogContent pointer.
|
||||
* @param len log data length.
|
||||
**/
|
||||
void OutputLog(const uint8 *data, uint32 len);
|
||||
|
||||
/**
|
||||
* Get the log file size.
|
||||
* @retval File size.
|
||||
**/
|
||||
uint32 GetLogFileSize(void);
|
||||
|
||||
/**
|
||||
* Read the log data form the log file.
|
||||
* @param buf Read buffer.
|
||||
* @param len Read buffer size.
|
||||
* @retval The length of read data.
|
||||
**/
|
||||
uint32 ReadLogFile(uint8 *buf, uint32 len);
|
||||
|
||||
/**
|
||||
* Formatting log content.
|
||||
* @param outStr Output string buffer.
|
||||
* @param outStrLen Maximum length of the string buffer.
|
||||
* @param pLogContent Pointer to the HiLogContent object.
|
||||
* @retval The actual length of the formatted string.
|
||||
**/
|
||||
int32 LogContentFmt(char *outStr, int32 outStrLen, const uint8 *pLogContent);
|
||||
|
||||
#ifdef __cplusplus
|
||||
#if __cplusplus
|
||||
}
|
||||
#endif
|
||||
#endif /* End of #ifdef __cplusplus */
|
||||
|
||||
#endif /* End of #ifndef HOS_LITE_HIVIEW_OUTPUT_LOG_H */
|
||||
/*
|
||||
* Copyright (c) 2020 Huawei Device Co., Ltd.
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#ifndef HOS_LITE_HIVIEW_OUTPUT_LOG_H
|
||||
#define HOS_LITE_HIVIEW_OUTPUT_LOG_H
|
||||
|
||||
#include "ohos_types.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
#if __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
#endif /* End of #ifdef __cplusplus */
|
||||
|
||||
void InitCoreLogOutput(void);
|
||||
void InitLogOutput(void);
|
||||
void ClearLogOutput(void);
|
||||
|
||||
/**
|
||||
* Output the log to file.
|
||||
* @param data HiLogContent pointer.
|
||||
* @param len log data length.
|
||||
**/
|
||||
void OutputLog(const uint8 *data, uint32 len);
|
||||
|
||||
/**
|
||||
* Get the log file size.
|
||||
* @retval File size.
|
||||
**/
|
||||
uint32 GetLogFileSize(void);
|
||||
|
||||
/**
|
||||
* Read the log data form the log file.
|
||||
* @param buf Read buffer.
|
||||
* @param len Read buffer size.
|
||||
* @retval The length of read data.
|
||||
**/
|
||||
uint32 ReadLogFile(uint8 *buf, uint32 len);
|
||||
|
||||
/**
|
||||
* Formatting log content.
|
||||
* @param outStr Output string buffer.
|
||||
* @param outStrLen Maximum length of the string buffer.
|
||||
* @param pLogContent Pointer to the HiLogContent object.
|
||||
* @retval The actual length of the formatted string.
|
||||
**/
|
||||
int32 LogContentFmt(char *outStr, int32 outStrLen, const uint8 *pLogContent);
|
||||
|
||||
#ifdef __cplusplus
|
||||
#if __cplusplus
|
||||
}
|
||||
#endif
|
||||
#endif /* End of #ifdef __cplusplus */
|
||||
|
||||
#endif /* End of #ifndef HOS_LITE_HIVIEW_OUTPUT_LOG_H */
|
||||
Executable
+43
@@ -0,0 +1,43 @@
|
||||
/*
|
||||
* Copyright (c) 2020 Huawei Device Co., Ltd.
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#ifndef HIVIEWDFX_HILOG_CPP_H
|
||||
#define HIVIEWDFX_HILOG_CPP_H
|
||||
|
||||
#include "hiview_log.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
|
||||
namespace OHOS {
|
||||
namespace HiviewDFX {
|
||||
struct HiLogLabel {
|
||||
LogType type;
|
||||
unsigned int domain;
|
||||
const char *tag;
|
||||
};
|
||||
|
||||
class HiLog final {
|
||||
public:
|
||||
static int Debug(const HiLogLabel &label, const char *fmt, ...) __attribute__((__format__(printf, 2, 3)));
|
||||
static int Info(const HiLogLabel &label, const char *fmt, ...) __attribute__((__format__(printf, 2, 3)));
|
||||
static int Warn(const HiLogLabel &label, const char *fmt, ...) __attribute__((__format__(printf, 2, 3)));
|
||||
static int Error(const HiLogLabel &label, const char *fmt, ...) __attribute__((__format__(printf, 2, 3)));
|
||||
static int Fatal(const HiLogLabel &label, const char *fmt, ...) __attribute__((__format__(printf, 2, 3)));
|
||||
};
|
||||
} // namespace HiviewDFX
|
||||
} // namespace OHOS
|
||||
#endif // __cplusplus
|
||||
|
||||
#endif // HIVIEWDFX_HILOG_CPP_H
|
||||
+330
@@ -0,0 +1,330 @@
|
||||
/*
|
||||
* Copyright (c) 2020 Huawei Device Co., Ltd.
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#ifndef HOS_LITE_HIVIEW_LOG_H
|
||||
#define HOS_LITE_HIVIEW_LOG_H
|
||||
/**
|
||||
* @addtogroup HiLog
|
||||
* @{
|
||||
*
|
||||
* @brief Provides logging functions.
|
||||
*
|
||||
* For example, you can use these functions to output logs of the specified log type, service domain, log tag,
|
||||
* and log level.
|
||||
*
|
||||
* @since 1.1
|
||||
* @version 1.0
|
||||
*/
|
||||
|
||||
/**
|
||||
* @file hilog/log.h
|
||||
*
|
||||
* @brief Defines the logging functions of the HiLog module.
|
||||
*
|
||||
* Before outputting logs, you must define the service domain, and log tag, use the function with
|
||||
* the specified log type and level, and specify the privacy identifier.\n
|
||||
* <ul><li>Service domain: used to identify the subsystem and module of a service. Its value is a hexadecimal
|
||||
* integer ranging from 0x0 to 0xFFFFF. The recommended format is 0xAAABB, where AAA indicates the subsystem
|
||||
* and BB indicates the module.</li> \n
|
||||
* <li>Log tag: a string used to identify the class, file, or service behavior.</li> \n
|
||||
* <li>Log level: <b>DEBUG</b>, <b>INFO</b>, <b>WARN</b>, <b>ERROR</b>, and <b>FATAL</b></li> \n
|
||||
* <li>Parameter format: a printf format string that starts with a % character, including format specifiers
|
||||
* and variable parameters.</li> \n
|
||||
* <li>Privacy identifier: {public} or {private} added between the % character and the format specifier in
|
||||
* each parameter. Note that each parameter has a privacy identifier. If no privacy identifier is added,
|
||||
* the parameter is considered to be <b>private</b>.</li></ul> \n
|
||||
*
|
||||
* Sample code:\n
|
||||
* Defining the service domain and log tag:\n
|
||||
* #define LOG_DOMAIN MY_SUBSYSTEM_MODULE // MY_SUBSYSTEM_MODULE=0x00201, where 002 indicates the subsystem and
|
||||
* 01 indicates the module.\n
|
||||
* #define LOG_TAG "MY_TAG"\n
|
||||
* Outputting logs:\n
|
||||
* HILOG_WARN({@link LOG_APP}, "Failed to visit %{private}s, reason:%{public}d.", url, errno);\n
|
||||
* Output result:\n
|
||||
* 05-06 15:01:06.870 1051 1051 W 00201/MY_TAG: Failed to visit <private>, reason:503.\n
|
||||
*
|
||||
* @since 1.1
|
||||
* @version 1.0
|
||||
*/
|
||||
|
||||
#include <stdarg.h>
|
||||
#include <stdio.h>
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/**
|
||||
* @brief Enumerates logging module types.
|
||||
*
|
||||
* The module type must be globally unique. A maximum of 64 module types can be defined.
|
||||
*
|
||||
* @since 1.0
|
||||
* @version 1.0
|
||||
*/
|
||||
typedef enum {
|
||||
/** DFX */
|
||||
HILOG_MODULE_HIVIEW = 0,
|
||||
/** System Ability Manager */
|
||||
HILOG_MODULE_SAMGR,
|
||||
/** Update */
|
||||
HILOG_MODULE_UPDATE,
|
||||
/** Ability Cross-platform Environment */
|
||||
HILOG_MODULE_ACE,
|
||||
/** Third-party applications */
|
||||
HILOG_MODULE_APP,
|
||||
/** Maximum number of modules */
|
||||
HILOG_MODULE_MAX
|
||||
} HiLogModuleType;
|
||||
|
||||
/**
|
||||
* @brief Defines the service domain for a log file.
|
||||
*
|
||||
* The service domain is used to identify the subsystem and module of a service. Its value is a hexadecimal integer
|
||||
* ranging from 0x0 to 0xFFFFF. If the value is beyond the range, its significant bits are automatically truncated. \n
|
||||
* The recommended format is 0xAAABB, where AAA indicates the subsystem and BB indicates the module. \n
|
||||
*
|
||||
* @since 1.1
|
||||
* @version 1.0
|
||||
*/
|
||||
#ifndef LOG_DOMAIN
|
||||
#define LOG_DOMAIN 0
|
||||
#endif
|
||||
|
||||
/**
|
||||
* @brief Defines a string constant used to identify the class, file, or service behavior.
|
||||
*
|
||||
* @since 1.1
|
||||
* @version 1.0
|
||||
*/
|
||||
#ifndef LOG_TAG
|
||||
#define LOG_TAG NULL
|
||||
#endif
|
||||
|
||||
#define DOMAIN_LENGTH 5
|
||||
#define DOMAIN_FILTER 0x000FFFFF
|
||||
|
||||
/**
|
||||
* @brief Enumerates log types.
|
||||
*
|
||||
* Currently, <b>LOG_APP</b> is available. \n
|
||||
*
|
||||
* @since 1.1
|
||||
* @version 1.0
|
||||
*/
|
||||
typedef enum {
|
||||
LOG_TYPE_MIN = 0,
|
||||
// Log to kmsg, only used by init phase.
|
||||
LOG_INIT = 1,
|
||||
// Used by core service, framework.
|
||||
LOG_CORE = 3,
|
||||
LOG_TYPE_MAX
|
||||
} LogType;
|
||||
|
||||
/**
|
||||
* @brief Enumerates log levels.
|
||||
*
|
||||
* You are advised to select log levels based on their respective usage scenarios:\n
|
||||
* <ul><li><b>DEBUG</b>: used for debugging and disabled from commercial releases</li> \n
|
||||
* <li><b>INFO</b>: used for logging important system running status and steps in key processes</li> \n
|
||||
* <li><b>WARN</b>: used for logging unexpected exceptions that have little impact on user experience and can
|
||||
* automatically recover. Logs at this level are generally output when such exceptions are detected and
|
||||
* captured.</li> \n
|
||||
* <li><b>ERROR</b>: used for logging malfunction that affects user experience and cannot automatically
|
||||
* recover</li>\n
|
||||
* <li><b>FATAL</b>: used for logging major exceptions that have severely affected user experience and should
|
||||
* not occur.</li></ul> \n
|
||||
*
|
||||
* @since 1.1
|
||||
* @version 1.0
|
||||
*/
|
||||
typedef enum {
|
||||
/** Debug level to be used by {@link HILOG_DEBUG} */
|
||||
LOG_DEBUG = 3,
|
||||
/** Informational level to be used by {@link HILOG_INFO} */
|
||||
LOG_INFO = 4,
|
||||
/** Warning level to be used by {@link HILOG_WARN} */
|
||||
LOG_WARN = 5,
|
||||
/** Error level to be used by {@link HILOG_ERROR} */
|
||||
LOG_ERROR = 6,
|
||||
/** Fatal level to be used by {@link HILOG_FATAL} */
|
||||
LOG_FATAL = 7,
|
||||
} LogLevel;
|
||||
|
||||
#define HILOG_LEVEL_MAX (LOG_FATAL + 1)
|
||||
/**
|
||||
* @brief Outputs logs.
|
||||
*
|
||||
* You can use this function to output logs based on the specified log type, log level, service domain, log tag,
|
||||
* and variable parameters determined by the format specifier and privacy identifier in the printf format.
|
||||
*
|
||||
* @param type Indicates the log type. The type for third-party applications is defined by {@link LOG_APP}.
|
||||
* @param level Indicates the log level, which can be <b>LOG_DEBUG</b>, <b>LOG_INFO</b>, <b>LOG_WARN</b>,
|
||||
* <b>LOG_ERROR</b>, and <b>LOG_FATAL</b>.
|
||||
* @param domain Indicates the service domain of logs. Its value is a hexadecimal integer ranging from 0x0 to 0xFFFFF.
|
||||
* The recommended format is 0xAAABB, where AAA indicates the subsystem and BB indicates the module.
|
||||
* @param tag Indicates the log tag, which is a string used to identify the class, file, or service behavior.
|
||||
* @param fmt Indicates the format string, which is an enhancement of a printf format string and supports the privacy
|
||||
* identifier. Specifically, {public} or {private} is added between the % character and the format specifier
|
||||
* in each parameter. \n
|
||||
* @param... Indicates a list of parameters. The number and type of parameters must map onto the format specifiers
|
||||
* in the format string.
|
||||
* @return Returns <b>0</b> or a larger value if the operation is successful; returns a value smaller
|
||||
* than <b>0</b> otherwise.
|
||||
* @since 1.1
|
||||
* @version 1.0
|
||||
*/
|
||||
#if defined(__clang__)
|
||||
int HiLogPrint(LogType type, LogLevel level, unsigned int domain, const char* tag, const char* fmt, ...)
|
||||
__attribute__((format(os_log, 5, 6)));
|
||||
#else
|
||||
int HiLogPrint(LogType type, LogLevel level, unsigned int domain, const char* tag, const char* fmt, ...)
|
||||
__attribute__((format(printf, 5, 6)));
|
||||
#endif
|
||||
/**
|
||||
* @brief Defines the pre-compiled macro for log levels.
|
||||
*
|
||||
* By default, logs at all levels are output in the compilation phase. You can set this pre-compiled macro to a specific
|
||||
* log level so that logs at levels lower than that level wil be shielded.
|
||||
* For example, if you want to shield logs lower than the ERROR level, set this macro to <b>HILOG_LV_ERROR</b>.
|
||||
* In this way, only functions for outputting ERROR- and FATAL-level logs are retained during compilation.
|
||||
* If you set this macro to <b>HILOG_LV_MAX</b>, functions for outputting logs at all levels will be disabled.
|
||||
*
|
||||
* @since 1.0
|
||||
* @version 1.0
|
||||
*/
|
||||
|
||||
int HiLogPrintArgs(LogType bufID, LogLevel prio,
|
||||
unsigned int domain, const char* tag, const char* fmt, va_list ap);
|
||||
|
||||
/**
|
||||
* @brief Outputs debug logs. This is a function-like macro.
|
||||
*
|
||||
* Before calling this function, define the log service domain and log tag. Generally, you need to define them at
|
||||
* the beginning of the source file. \n
|
||||
*
|
||||
* @param type Indicates the log type. The type for third-party applications is defined by {@link LOG_APP}.
|
||||
* @param fmt Indicates the format string, which is an enhancement of a printf format string and supports the
|
||||
* privacy identifier. Specifically, {public} or {private} is added between the % character and the format specifier
|
||||
* in each parameter. \n
|
||||
* @param... Indicates a list of parameters. The number and type of parameters must map onto the format specifiers
|
||||
* in the format string.
|
||||
* @return Returns <b>0</b> or a larger value if the operation is successful; returns a value smaller than <b>0</b>
|
||||
* otherwise.
|
||||
* @see HiLogPrint
|
||||
* @since 1.1
|
||||
* @version 1.0
|
||||
*/
|
||||
#define HILOG_DEBUG(type, ...) ((void)HiLogPrint(LOG_CORE, LOG_DEBUG, LOG_DOMAIN, LOG_TAG, __VA_ARGS__))
|
||||
|
||||
/**
|
||||
* @brief Outputs informational logs. This is a function-like macro.
|
||||
*
|
||||
* Before calling this function, define the log service domain and log tag. Generally, you need to define them
|
||||
* at the beginning of the source file. \n
|
||||
*
|
||||
* @param type Indicates the log type. The type for third-party applications is defined by {@link LOG_APP}.
|
||||
* @param fmt Indicates the format string, which is an enhancement of a printf format string and supports the privacy
|
||||
* identifier. Specifically, {public} or {private} is added between the % character and the format specifier in
|
||||
* each parameter. \n
|
||||
* @param... Indicates a list of parameters. The number and type of parameters must map onto the format specifiers
|
||||
* in the format string.
|
||||
* @return Returns <b>0</b> or a larger value if the operation is successful; returns a value smaller than
|
||||
* <b>0</b> otherwise.
|
||||
* @see HiLogPrint
|
||||
* @since 1.1
|
||||
* @version 1.0
|
||||
*/
|
||||
#define HILOG_INFO(type, ...) ((void)HiLogPrint(LOG_CORE, LOG_INFO, LOG_DOMAIN, LOG_TAG, __VA_ARGS__))
|
||||
|
||||
/**
|
||||
* @brief Outputs warning logs. This is a function-like macro.
|
||||
*
|
||||
* Before calling this function, define the log service domain and log tag. Generally, you need to define them
|
||||
* at the beginning of the source file. \n
|
||||
*
|
||||
* @param type Indicates the log type. The type for third-party applications is defined by {@link LOG_APP}.
|
||||
* @param fmt Indicates the format string, which is an enhancement of a printf format string and supports the
|
||||
* privacy identifier. Specifically, {public} or {private} is added between the % character and the format specifier
|
||||
* in each parameter. \n
|
||||
* @param... Indicates a list of parameters. The number and type of parameters must map onto the format specifiers
|
||||
* in the format string.
|
||||
* @return Returns <b>0</b> or a larger value if the operation is successful; returns a value smaller than
|
||||
* <b>0</b> otherwise.
|
||||
* @see HiLogPrint
|
||||
* @since 1.1
|
||||
* @version 1.0
|
||||
*/
|
||||
#define HILOG_WARN(type, ...) ((void)HiLogPrint(LOG_CORE, LOG_WARN, LOG_DOMAIN, LOG_TAG, __VA_ARGS__))
|
||||
|
||||
/**
|
||||
* @brief Outputs error logs. This is a function-like macro.
|
||||
*
|
||||
* Before calling this function, define the log service domain and log tag. Generally, you need to define
|
||||
* them at the beginning of the source file. \n
|
||||
*
|
||||
* @param type Indicates the log type. The type for third-party applications is defined by {@link LOG_APP}.
|
||||
* @param fmt Indicates the format string, which is an enhancement of a printf format string and supports the privacy
|
||||
* identifier. Specifically, {public} or {private} is added between the % character and the format specifier in each
|
||||
* parameter. \n
|
||||
* @param... Indicates a list of parameters. The number and type of parameters must map onto the format specifiers
|
||||
* in the format string.
|
||||
* @return Returns <b>0</b> or a larger value if the operation is successful; returns a value smaller than
|
||||
* <b>0</b> otherwise.
|
||||
* @see HiLogPrint
|
||||
* @since 1.1
|
||||
* @version 1.0
|
||||
*/
|
||||
#define HILOG_ERROR(type, ...) ((void)HiLogPrint(LOG_CORE, LOG_ERROR, LOG_DOMAIN, LOG_TAG, __VA_ARGS__))
|
||||
|
||||
/**
|
||||
* @brief Outputs fatal logs. This is a function-like macro.
|
||||
*
|
||||
* Before calling this function, define the log service domain and log tag. Generally, you need to define them at
|
||||
* the beginning of the source file. \n
|
||||
*
|
||||
* @param type Indicates the log type. The type for third-party applications is defined by {@link LOG_APP}.
|
||||
* @param fmt Indicates the format string, which is an enhancement of a printf format string and supports the privacy
|
||||
* identifier. Specifically, {public} or {private} is added between the % character and the format specifier in
|
||||
* each parameter. \n
|
||||
* @param... Indicates a list of parameters. The number and type of parameters must map onto the format specifiers
|
||||
* in the format string.
|
||||
* @return Returns <b>0</b> or a larger value if the operation is successful; returns a value smaller than
|
||||
* <b>0</b> otherwise.
|
||||
* @see HiLogPrint
|
||||
* @since 1.1
|
||||
* @version 1.0
|
||||
*/
|
||||
#define HILOG_FATAL(type, ...) ((void)HiLogPrint(LOG_CORE, LOG_FATAL, LOG_DOMAIN, LOG_TAG, __VA_ARGS__))
|
||||
|
||||
#define HILOG_DRIVER "/dev/hilog"
|
||||
#define NANOSEC_PER_MIRCOSEC 1000000
|
||||
struct HiLogEntry {
|
||||
unsigned int len;
|
||||
unsigned int hdrSize;
|
||||
unsigned int pid : 16;
|
||||
unsigned int taskId : 16;
|
||||
unsigned int sec;
|
||||
unsigned int nsec;
|
||||
unsigned int reserved;
|
||||
char msg[0];
|
||||
};
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
/** @} */
|
||||
#endif // HOS_LITE_HIVIEW_LOG_H
|
||||
Executable
+21
@@ -0,0 +1,21 @@
|
||||
/*
|
||||
* Copyright (c) 2020 Huawei Device Co., Ltd.
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#ifndef HOS_LITE_DFX_HILOG_H
|
||||
#define HOS_LITE_DFX_HILOG_H
|
||||
|
||||
#include "hilog_cp.h"
|
||||
|
||||
#endif /* End of #ifndef HOS_LITE_DFX_HILOG_H */
|
||||
Executable
+300
@@ -0,0 +1,300 @@
|
||||
/*
|
||||
* Copyright (c) 2020 Huawei Device Co., Ltd.
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#ifndef HOS_LITE_HIVIEW_LOG_H
|
||||
#define HOS_LITE_HIVIEW_LOG_H
|
||||
/**
|
||||
* @addtogroup HiLog
|
||||
* @{
|
||||
*
|
||||
* @brief Provides logging functions.
|
||||
*
|
||||
* For example, you can use these functions to output logs of the specified log type, service domain, log tag,
|
||||
* and log level.
|
||||
*
|
||||
* @since 1.1
|
||||
* @version 1.0
|
||||
*/
|
||||
|
||||
/**
|
||||
* @file hilog/log.h
|
||||
*
|
||||
* @brief Defines the logging functions of the HiLog module.
|
||||
*
|
||||
* Before outputting logs, you must define the service domain, and log tag, use the function with
|
||||
* the specified log type and level, and specify the privacy identifier.\n
|
||||
* <ul><li>Service domain: used to identify the subsystem and module of a service. Its value is a hexadecimal
|
||||
* integer ranging from 0x0 to 0xFFFFF. The recommended format is 0xAAABB, where AAA indicates the subsystem
|
||||
* and BB indicates the module.</li> \n
|
||||
* <li>Log tag: a string used to identify the class, file, or service behavior.</li> \n
|
||||
* <li>Log level: <b>DEBUG</b>, <b>INFO</b>, <b>WARN</b>, <b>ERROR</b>, and <b>FATAL</b></li> \n
|
||||
* <li>Parameter format: a printf format string that starts with a % character, including format specifiers
|
||||
* and variable parameters.</li> \n
|
||||
* <li>Privacy identifier: {public} or {private} added between the % character and the format specifier in
|
||||
* each parameter. Note that each parameter has a privacy identifier. If no privacy identifier is added,
|
||||
* the parameter is considered to be <b>private</b>.</li></ul> \n
|
||||
*
|
||||
* Sample code:\n
|
||||
* Defining the service domain and log tag:\n
|
||||
* #define LOG_DOMAIN MY_SUBSYSTEM_MODULE // MY_SUBSYSTEM_MODULE=0x00201, where 002 indicates the subsystem and
|
||||
* 01 indicates the module.\n
|
||||
* #define LOG_TAG "MY_TAG"\n
|
||||
* Outputting logs:\n
|
||||
* HILOG_WARN({@link LOG_APP}, "Failed to visit %{private}s, reason:%{public}d.", url, errno);\n
|
||||
* Output result:\n
|
||||
* 05-06 15:01:06.870 1051 1051 W 00201/MY_TAG: Failed to visit <private>, reason:503.\n
|
||||
*
|
||||
* @since 1.1
|
||||
* @version 1.0
|
||||
*/
|
||||
|
||||
#include <stdarg.h>
|
||||
#include <stdio.h>
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/**
|
||||
* @brief Enumerates logging module types.
|
||||
*
|
||||
* The module type must be globally unique. A maximum of 64 module types can be defined.
|
||||
*
|
||||
* @since 1.0
|
||||
* @version 1.0
|
||||
*/
|
||||
typedef enum {
|
||||
/** DFX */
|
||||
HILOG_MODULE_HIVIEW = 0,
|
||||
/** System Ability Manager */
|
||||
HILOG_MODULE_SAMGR,
|
||||
/** Update */
|
||||
HILOG_MODULE_ACE,
|
||||
/** Third-party applications */
|
||||
HILOG_MODULE_APP,
|
||||
/** Maximum number of modules */
|
||||
HILOG_MODULE_MAX
|
||||
} HiLogModuleType;
|
||||
|
||||
/**
|
||||
* @brief Defines the service domain for a log file.
|
||||
*
|
||||
* The service domain is used to identify the subsystem and module of a service. Its value is a hexadecimal integer
|
||||
* ranging from 0x0 to 0xFFFFF. If the value is beyond the range, its significant bits are automatically truncated. \n
|
||||
* The recommended format is 0xAAABB, where AAA indicates the subsystem and BB indicates the module. \n
|
||||
*
|
||||
* @since 1.1
|
||||
* @version 1.0
|
||||
*/
|
||||
#ifndef LOG_DOMAIN
|
||||
#define LOG_DOMAIN 0
|
||||
#endif
|
||||
|
||||
/**
|
||||
* @brief Defines a string constant used to identify the class, file, or service behavior.
|
||||
*
|
||||
* @since 1.1
|
||||
* @version 1.0
|
||||
*/
|
||||
#ifndef LOG_TAG
|
||||
#define LOG_TAG NULL
|
||||
#endif
|
||||
|
||||
#define DOMAIN_LENGTH 5
|
||||
#define DOMAIN_FILTER 0x000FFFFF
|
||||
|
||||
/**
|
||||
* @brief Enumerates log types.
|
||||
*
|
||||
* Currently, <b>LOG_APP</b> is available. \n
|
||||
*
|
||||
* @since 1.1
|
||||
* @version 1.0
|
||||
*/
|
||||
typedef enum {
|
||||
LOG_TYPE_MIN = 0,
|
||||
// Log to kmsg, only used by init phase.
|
||||
LOG_INIT = 1,
|
||||
// Used by core service, framework.
|
||||
LOG_CORE = 3,
|
||||
LOG_TYPE_MAX
|
||||
} LogType;
|
||||
|
||||
/**
|
||||
* @brief Enumerates log levels.
|
||||
*
|
||||
* You are advised to select log levels based on their respective usage scenarios:\n
|
||||
* <ul><li><b>DEBUG</b>: used for debugging and disabled from commercial releases</li> \n
|
||||
* <li><b>INFO</b>: used for logging important system running status and steps in key processes</li> \n
|
||||
* <li><b>WARN</b>: used for logging unexpected exceptions that have little impact on user experience and can
|
||||
* automatically recover. Logs at this level are generally output when such exceptions are detected and
|
||||
* captured.</li> \n
|
||||
* <li><b>ERROR</b>: used for logging malfunction that affects user experience and cannot automatically
|
||||
* recover</li>\n
|
||||
* <li><b>FATAL</b>: used for logging major exceptions that have severely affected user experience and should
|
||||
* not occur.</li></ul> \n
|
||||
*
|
||||
* @since 1.1
|
||||
* @version 1.0
|
||||
*/
|
||||
typedef enum {
|
||||
/** Debug level to be used by {@link HILOG_DEBUG} */
|
||||
LOG_DEBUG = 3,
|
||||
/** Informational level to be used by {@link HILOG_INFO} */
|
||||
LOG_INFO = 4,
|
||||
/** Warning level to be used by {@link HILOG_WARN} */
|
||||
LOG_WARN = 5,
|
||||
/** Error level to be used by {@link HILOG_ERROR} */
|
||||
LOG_ERROR = 6,
|
||||
/** Fatal level to be used by {@link HILOG_FATAL} */
|
||||
LOG_FATAL = 7,
|
||||
} LogLevel;
|
||||
|
||||
#define HILOG_LEVEL_MAX (LOG_FATAL + 1)
|
||||
/**
|
||||
* @brief Outputs logs.
|
||||
*
|
||||
* You can use this function to output logs based on the specified log type, log level, service domain, log tag,
|
||||
* and variable parameters determined by the format specifier and privacy identifier in the printf format.
|
||||
*
|
||||
* @param type Indicates the log type. The type for third-party applications is defined by {@link LOG_APP}.
|
||||
* @param level Indicates the log level, which can be <b>LOG_DEBUG</b>, <b>LOG_INFO</b>, <b>LOG_WARN</b>,
|
||||
* <b>LOG_ERROR</b>, and <b>LOG_FATAL</b>.
|
||||
* @param domain Indicates the service domain of logs. Its value is a hexadecimal integer ranging from 0x0 to 0xFFFFF.
|
||||
* The recommended format is 0xAAABB, where AAA indicates the subsystem and BB indicates the module.
|
||||
* @param tag Indicates the log tag, which is a string used to identify the class, file, or service behavior.
|
||||
* @param fmt Indicates the format string, which is an enhancement of a printf format string and supports the privacy
|
||||
* identifier. Specifically, {public} or {private} is added between the % character and the format specifier
|
||||
* in each parameter. \n
|
||||
* @param... Indicates a list of parameters. The number and type of parameters must map onto the format specifiers
|
||||
* in the format string.
|
||||
* @return Returns <b>0</b> or a larger value if the operation is successful; returns a value smaller
|
||||
* than <b>0</b> otherwise.
|
||||
* @since 1.1
|
||||
* @version 1.0
|
||||
*/
|
||||
#if defined(__clang__)
|
||||
int HiLogPrint(LogType type, LogLevel level, unsigned int domain, const char* tag, const char* fmt, ...)
|
||||
__attribute__((format(os_log, 5, 6)));
|
||||
#else
|
||||
int HiLogPrint(LogType type, LogLevel level, unsigned int domain, const char* tag, const char* fmt, ...)
|
||||
__attribute__((format(printf, 5, 6)));
|
||||
#endif
|
||||
|
||||
/**
|
||||
* @brief Outputs debug logs. This is a function-like macro.
|
||||
*
|
||||
* Before calling this function, define the log service domain and log tag. Generally, you need to define them at
|
||||
* the beginning of the source file. \n
|
||||
*
|
||||
* @param type Indicates the log type. The type for third-party applications is defined by {@link LOG_APP}.
|
||||
* @param fmt Indicates the format string, which is an enhancement of a printf format string and supports the
|
||||
* privacy identifier. Specifically, {public} or {private} is added between the % character and the format specifier
|
||||
* in each parameter. \n
|
||||
* @param... Indicates a list of parameters. The number and type of parameters must map onto the format specifiers
|
||||
* in the format string.
|
||||
* @return Returns <b>0</b> or a larger value if the operation is successful; returns a value smaller than <b>0</b>
|
||||
* otherwise.
|
||||
* @see HiLogPrint
|
||||
* @since 1.1
|
||||
* @version 1.0
|
||||
*/
|
||||
#define HILOG_DEBUG(type, ...) ((void)HiLogPrint(LOG_CORE, LOG_DEBUG, LOG_DOMAIN, LOG_TAG, __VA_ARGS__))
|
||||
|
||||
/**
|
||||
* @brief Outputs informational logs. This is a function-like macro.
|
||||
*
|
||||
* Before calling this function, define the log service domain and log tag. Generally, you need to define them
|
||||
* at the beginning of the source file. \n
|
||||
*
|
||||
* @param type Indicates the log type. The type for third-party applications is defined by {@link LOG_APP}.
|
||||
* @param fmt Indicates the format string, which is an enhancement of a printf format string and supports the privacy
|
||||
* identifier. Specifically, {public} or {private} is added between the % character and the format specifier in
|
||||
* each parameter. \n
|
||||
* @param... Indicates a list of parameters. The number and type of parameters must map onto the format specifiers
|
||||
* in the format string.
|
||||
* @return Returns <b>0</b> or a larger value if the operation is successful; returns a value smaller than
|
||||
* <b>0</b> otherwise.
|
||||
* @see HiLogPrint
|
||||
* @since 1.1
|
||||
* @version 1.0
|
||||
*/
|
||||
#define HILOG_INFO(type, ...) ((void)HiLogPrint(LOG_CORE, LOG_INFO, LOG_DOMAIN, LOG_TAG, __VA_ARGS__))
|
||||
|
||||
/**
|
||||
* @brief Outputs warning logs. This is a function-like macro.
|
||||
*
|
||||
* Before calling this function, define the log service domain and log tag. Generally, you need to define them
|
||||
* at the beginning of the source file. \n
|
||||
*
|
||||
* @param type Indicates the log type. The type for third-party applications is defined by {@link LOG_APP}.
|
||||
* @param fmt Indicates the format string, which is an enhancement of a printf format string and supports the
|
||||
* privacy identifier. Specifically, {public} or {private} is added between the % character and the format specifier
|
||||
* in each parameter. \n
|
||||
* @param... Indicates a list of parameters. The number and type of parameters must map onto the format specifiers
|
||||
* in the format string.
|
||||
* @return Returns <b>0</b> or a larger value if the operation is successful; returns a value smaller than
|
||||
* <b>0</b> otherwise.
|
||||
* @see HiLogPrint
|
||||
* @since 1.1
|
||||
* @version 1.0
|
||||
*/
|
||||
#define HILOG_WARN(type, ...) ((void)HiLogPrint(LOG_CORE, LOG_WARN, LOG_DOMAIN, LOG_TAG, __VA_ARGS__))
|
||||
|
||||
/**
|
||||
* @brief Outputs error logs. This is a function-like macro.
|
||||
*
|
||||
* Before calling this function, define the log service domain and log tag. Generally, you need to define
|
||||
* them at the beginning of the source file. \n
|
||||
*
|
||||
* @param type Indicates the log type. The type for third-party applications is defined by {@link LOG_APP}.
|
||||
* @param fmt Indicates the format string, which is an enhancement of a printf format string and supports the privacy
|
||||
* identifier. Specifically, {public} or {private} is added between the % character and the format specifier in each
|
||||
* parameter. \n
|
||||
* @param... Indicates a list of parameters. The number and type of parameters must map onto the format specifiers
|
||||
* in the format string.
|
||||
* @return Returns <b>0</b> or a larger value if the operation is successful; returns a value smaller than
|
||||
* <b>0</b> otherwise.
|
||||
* @see HiLogPrint
|
||||
* @since 1.1
|
||||
* @version 1.0
|
||||
*/
|
||||
#define HILOG_ERROR(type, ...) ((void)HiLogPrint(LOG_CORE, LOG_ERROR, LOG_DOMAIN, LOG_TAG, __VA_ARGS__))
|
||||
|
||||
/**
|
||||
* @brief Outputs fatal logs. This is a function-like macro.
|
||||
*
|
||||
* Before calling this function, define the log service domain and log tag. Generally, you need to define them at
|
||||
* the beginning of the source file. \n
|
||||
*
|
||||
* @param type Indicates the log type. The type for third-party applications is defined by {@link LOG_APP}.
|
||||
* @param fmt Indicates the format string, which is an enhancement of a printf format string and supports the privacy
|
||||
* identifier. Specifically, {public} or {private} is added between the % character and the format specifier in
|
||||
* each parameter. \n
|
||||
* @param... Indicates a list of parameters. The number and type of parameters must map onto the format specifiers
|
||||
* in the format string.
|
||||
* @return Returns <b>0</b> or a larger value if the operation is successful; returns a value smaller than
|
||||
* <b>0</b> otherwise.
|
||||
* @see HiLogPrint
|
||||
* @since 1.1
|
||||
* @version 1.0
|
||||
*/
|
||||
#define HILOG_FATAL(type, ...) ((void)HiLogPrint(LOG_CORE, LOG_FATAL, LOG_DOMAIN, LOG_TAG, __VA_ARGS__))
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
/** @} */
|
||||
#endif // HOS_LITE_HIVIEW_LOG_H
|
||||
+287
@@ -0,0 +1,287 @@
|
||||
/*
|
||||
* Copyright (c) 2020 Huawei Device Co., Ltd.
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
/**
|
||||
* @addtogroup hilog
|
||||
* @{
|
||||
*
|
||||
* @brief Provides logging functions.
|
||||
*
|
||||
* You can use this module to log code execution and locate code exceptions if any.
|
||||
* This module collects, filters out, buffers, forwards, formats, and performs flow control on logs.
|
||||
*
|
||||
* @since 1.0
|
||||
* @version 1.0
|
||||
*/
|
||||
|
||||
/**
|
||||
* @file hiview_log.h
|
||||
*
|
||||
* @brief Defines functions of the logging module.
|
||||
*
|
||||
* You can use these functions to output logs to locate code exceptions if any.
|
||||
* Ensure that only valid logs are selected for output. If excessive logs are to be output or log levels specified
|
||||
* for output are improper, flow control will be performed on logs and key logs may be filtered out.
|
||||
* To reduce the OHOS resource usage, you need to register the information about modules requiring log output
|
||||
* with the logging system before outputting logs. Logging functions for different levels (for example,
|
||||
* {@link HILOG_LV_DEBUG}) are provided for ease in selecting logs at your desired level.
|
||||
*
|
||||
* @since 1.0
|
||||
* @version 1.0
|
||||
*/
|
||||
|
||||
#ifndef HOS_LITE_HIVIEW_LOG_H
|
||||
#define HOS_LITE_HIVIEW_LOG_H
|
||||
|
||||
#include "ohos_types.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
#if __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
#endif /* End of #ifdef __cplusplus */
|
||||
|
||||
extern const char * const FUN_ARG_S;
|
||||
#define FUN_ARG_0 (&FUN_ARG_S[0])
|
||||
#define FUN_ARG_1 (&FUN_ARG_S[1])
|
||||
#define FUN_ARG_2 (&FUN_ARG_S[2])
|
||||
#define FUN_ARG_3 (&FUN_ARG_S[3])
|
||||
#define FUN_ARG_4 (&FUN_ARG_S[4])
|
||||
#define FUN_ARG_5 (&FUN_ARG_S[5])
|
||||
#define FUN_ARG_6 (&FUN_ARG_S[6])
|
||||
#define FUN_ARG_I (&FUN_ARG_S[7])
|
||||
#define FUN_ARG_NUM(...) ARGS_CHECK(FUN_ARG_NUM_(FUN_ARG_I, ##__VA_ARGS__, FUN_ARG_EX_()))
|
||||
#define FUN_ARG_NUM_(...) FUN_ARG_EX(__VA_ARGS__)
|
||||
#define FUN_ARG_EX(_0, _1, _2, _3, _4, _5, _6, N, ...) N
|
||||
#define FUN_ARG_EX_() FUN_ARG_6, FUN_ARG_5, FUN_ARG_4, FUN_ARG_3, FUN_ARG_2, FUN_ARG_1, FUN_ARG_0
|
||||
#define ARGS_CHECK(N) (TRUE ? N : FUN_ARG_I)
|
||||
|
||||
#define HILOG_LV_INVALID 0
|
||||
#define HILOG_LV_DEBUG 1
|
||||
#define HILOG_LV_INFO 2
|
||||
#define HILOG_LV_WARN 3
|
||||
#define HILOG_LV_ERROR 4
|
||||
#define HILOG_LV_FATAL 5
|
||||
#define HILOG_LV_MAX 6
|
||||
|
||||
/**
|
||||
* @brief Enumerates logging module types.
|
||||
*
|
||||
* The module type must be globally unique. A maximum of 64 module types can be defined.
|
||||
*
|
||||
* @since 1.0
|
||||
* @version 1.0
|
||||
*/
|
||||
typedef enum {
|
||||
/** DFX */
|
||||
HILOG_MODULE_HIVIEW = 0,
|
||||
/** System Ability Manager */
|
||||
HILOG_MODULE_SAMGR,
|
||||
/** Update */
|
||||
HILOG_MODULE_UPDATE,
|
||||
/** Ability Cross-platform Environment */
|
||||
HILOG_MODULE_ACE,
|
||||
/** Third-party applications */
|
||||
HILOG_MODULE_APP,
|
||||
/** Atomic Ability Framework */
|
||||
HILOG_MODULE_AAFWK,
|
||||
/** Graphic */
|
||||
HILOG_MODULE_GRAPHIC,
|
||||
/** Multimedia */
|
||||
HILOG_MODULE_MEDIA,
|
||||
/** Distributed Schedule Service */
|
||||
HILOG_MODULE_DMS,
|
||||
/** Sensors */
|
||||
HILOG_MODULE_SEN,
|
||||
/** Security */
|
||||
HILOG_MODULE_SCY,
|
||||
/** XTS */
|
||||
HILOG_MODULE_XTS,
|
||||
/** Maximum number of modules */
|
||||
HILOG_MODULE_MAX
|
||||
} HiLogModuleType;
|
||||
|
||||
/**
|
||||
* @brief Registers module information with the logging system.
|
||||
*
|
||||
* When a new module is defined, you need to use this function to register the module information with the logging
|
||||
* system. If not registered, the logs of this module will not be output. \n
|
||||
*
|
||||
* @param id Identifies the module to be registered. The module ID, which must be globally unique, is defined in
|
||||
* {@link HiLogModuleType}.
|
||||
* @param name Indicates the module name. The value must be a static string of up to 15 uppercase and lowercase letters.
|
||||
* Variables cannot be passed as module names.
|
||||
* @return Returns <b>TRUE</b> if the registration is successful; returns <b>FALSE</b> otherwise.
|
||||
* @since 1.0
|
||||
* @version 1.0
|
||||
*/
|
||||
boolean HiLogRegisterModule(uint16 id, const char *name);
|
||||
|
||||
/**
|
||||
* @brief Obtains the name of a registered module by module ID.
|
||||
*
|
||||
* @param id Identifies the module. The module ID, which must be globally unique, is defined in {@link HiLogModuleType}.
|
||||
* @return Returns the string pointer to the module name if obtained; returns an empty string if the module ID is
|
||||
* invalid or does not exist.
|
||||
* @since 1.0
|
||||
* @version 1.0
|
||||
*/
|
||||
const char *HiLogGetModuleName(uint8 id);
|
||||
|
||||
/*
|
||||
* Interface for printing basic logs. Use the macro definition interface instead of directly using this interface.
|
||||
* @param module Module ID.
|
||||
* @param level Log Level.
|
||||
* @param nums Parameters automatically generated by macro.
|
||||
* @param fmt Format string.
|
||||
* @attention Do not use this interface directly, you should use the HILOG_XXX interface.
|
||||
*/
|
||||
void HiLogPrintf(uint8 module, uint8 level, const char *nums,
|
||||
const char *fmt, ...) __attribute__((format(printf, 4, 5)));
|
||||
|
||||
/**
|
||||
* @brief Defines the pre-compiled macro for log levels.
|
||||
*
|
||||
* By default, logs at all levels are output in the compilation phase. You can set this pre-compiled macro to a specific
|
||||
* log level so that logs at levels lower than that level wil be shielded.
|
||||
* For example, if you want to shield logs lower than the ERROR level, set this macro to <b>HILOG_LV_ERROR</b>.
|
||||
* In this way, only functions for outputting ERROR- and FATAL-level logs are retained during compilation.
|
||||
* If you set this macro to <b>HILOG_LV_MAX</b>, functions for outputting logs at all levels will be disabled.
|
||||
*
|
||||
* @since 1.0
|
||||
* @version 1.0
|
||||
*/
|
||||
#ifndef HILOG_COMPILE_LEVEL
|
||||
#define HILOG_COMPILE_LEVEL HILOG_LV_DEBUG
|
||||
#endif
|
||||
|
||||
/**
|
||||
* @brief Outputs debug logs.
|
||||
*
|
||||
* @param mod Identifies the module. The module ID, which must be globally unique, is defined in
|
||||
* {@link HiLogModuleType}.
|
||||
* @param fmt Indicates the formatted string of log content.
|
||||
* <ul>
|
||||
* <li>A maximum of six variable parameters are supported. </li>
|
||||
* <li>The format specifier \%s is not supported. If it is used, this function will return unpredictable
|
||||
* results. </li>
|
||||
* <li>Each formatted log record allows for a maximum of 128 characters. If the length of a log record exceeds
|
||||
* 128 characters, the log record cannot be output. </li>
|
||||
* </ul>
|
||||
* @since 1.0
|
||||
* @version 1.0
|
||||
*/
|
||||
#if HILOG_COMPILE_LEVEL <= HILOG_LV_DEBUG
|
||||
#define HILOG_DEBUG(mod, fmt, ...) HiLogPrintf(mod, HILOG_LV_DEBUG, FUN_ARG_NUM(__VA_ARGS__), fmt, ##__VA_ARGS__)
|
||||
#else
|
||||
#define HILOG_DEBUG(mod, fmt, ...)
|
||||
#endif
|
||||
|
||||
/**
|
||||
* @brief Outputs informational logs.
|
||||
*
|
||||
* @param mod Identifies the module. The module ID, which must be globally unique, is defined in
|
||||
* {@link HiLogModuleType}.
|
||||
* @param fmt Indicates the formatted string of log content.
|
||||
* <ul>
|
||||
* <li>A maximum of six variable parameters are supported. </li>
|
||||
* <li>The format specifier \%s is not supported. If it is used, this function will return unpredictable
|
||||
* results. </li>
|
||||
* <li>Each formatted log record allows for a maximum of 128 characters. If the length of a log record exceeds
|
||||
* 128 characters, the log record cannot be output. </li>
|
||||
* </ul>
|
||||
* @since 1.0
|
||||
* @version 1.0
|
||||
*/
|
||||
#if HILOG_COMPILE_LEVEL <= HILOG_LV_INFO
|
||||
#define HILOG_INFO(mod, fmt, ...) HiLogPrintf(mod, HILOG_LV_INFO, FUN_ARG_NUM(__VA_ARGS__), fmt, ##__VA_ARGS__)
|
||||
#else
|
||||
#define HILOG_INFO(mod, fmt, ...)
|
||||
#endif
|
||||
|
||||
/**
|
||||
* @brief Outputs warning logs.
|
||||
*
|
||||
* @param mod Identifies the module. The module ID, which must be globally unique, is defined in
|
||||
* {@link HiLogModuleType}.
|
||||
* @param fmt Indicates the formatted string of log content.
|
||||
* <ul>
|
||||
* <li>A maximum of six variable parameters are supported. </li>
|
||||
* <li>The format specifier \%s is not supported. If it is used, this function will return unpredictable
|
||||
* results. </li>
|
||||
* <li>Each formatted log record allows for a maximum of 128 characters. If the length of a log record exceeds
|
||||
* 128 characters, the log record cannot be output. </li>
|
||||
* </ul>
|
||||
* @since 1.0
|
||||
* @version 1.0
|
||||
*/
|
||||
#if HILOG_COMPILE_LEVEL <= HILOG_LV_WARN
|
||||
#define HILOG_WARN(mod, fmt, ...) HiLogPrintf(mod, HILOG_LV_WARN, FUN_ARG_NUM(__VA_ARGS__), fmt, ##__VA_ARGS__)
|
||||
#else
|
||||
#define HILOG_WARN(mod, fmt, ...)
|
||||
#endif
|
||||
|
||||
/**
|
||||
* @brief Outputs error logs.
|
||||
*
|
||||
* @param mod Identifies the module. The module ID, which must be globally unique, is defined in
|
||||
* {@link HiLogModuleType}.
|
||||
* @param fmt Indicates the formatted string of log content.
|
||||
* <ul>
|
||||
* <li>A maximum of six variable parameters are supported. </li>
|
||||
* <li>The format specifier \%s is not supported. If it is used, this function will return unpredictable
|
||||
* results. </li>
|
||||
* <li>Each formatted log record allows for a maximum of 128 characters. If the length of a log record exceeds
|
||||
* 128 characters, the log record cannot be output. </li>
|
||||
* </ul>
|
||||
* @since 1.0
|
||||
* @version 1.0
|
||||
*/
|
||||
#if HILOG_COMPILE_LEVEL <= HILOG_LV_ERROR
|
||||
#define HILOG_ERROR(mod, fmt, ...) HiLogPrintf(mod, HILOG_LV_ERROR, FUN_ARG_NUM(__VA_ARGS__), fmt, ##__VA_ARGS__)
|
||||
#else
|
||||
#define HILOG_ERROR(mod, fmt, ...)
|
||||
#endif
|
||||
|
||||
/**
|
||||
* @brief Outputs fatal logs.
|
||||
*
|
||||
* @param mod Identifies the module. The module ID, which must be globally unique, is defined in
|
||||
* {@link HiLogModuleType}.
|
||||
* @param fmt Indicates the formatted string of log content.
|
||||
* <ul>
|
||||
* <li>A maximum of six variable parameters are supported. </li>
|
||||
* <li>The format specifier \%s is not supported. If it is used, this function will return unpredictable
|
||||
* results. </li>
|
||||
* <li>Each formatted log record allows for a maximum of 128 characters. If the length of a log record exceeds
|
||||
* 128 characters, the log record cannot be output. </li>
|
||||
* </ul>
|
||||
* @since 1.0
|
||||
* @version 1.0
|
||||
*/
|
||||
#if HILOG_COMPILE_LEVEL <= HILOG_LV_FATAL
|
||||
#define HILOG_FATAL(mod, fmt, ...) HiLogPrintf(mod, HILOG_LV_FATAL, FUN_ARG_NUM(__VA_ARGS__), fmt, ##__VA_ARGS__)
|
||||
#else
|
||||
#define HILOG_FATAL(mod, fmt, ...)
|
||||
#endif
|
||||
|
||||
#ifdef __cplusplus
|
||||
#if __cplusplus
|
||||
}
|
||||
#endif
|
||||
#endif /* End of #ifdef __cplusplus */
|
||||
|
||||
#endif /* End of #ifndef HOS_LITE_HIVIEW_LOG_H */
|
||||
/** @} */
|
||||
Executable
+21
@@ -0,0 +1,21 @@
|
||||
/*
|
||||
* Copyright (c) 2020 Huawei Device Co., Ltd.
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#ifndef HOS_LITE_DFX_HILOG_H
|
||||
#define HOS_LITE_DFX_HILOG_H
|
||||
|
||||
#include "hiview_log.h"
|
||||
|
||||
#endif /* End of #ifndef HOS_LITE_DFX_HILOG_H */
|
||||
@@ -1,3 +0,0 @@
|
||||
详见:https://gitee.com/openharmony/docs/blob/master/readme/DFX子系统README.md
|
||||
|
||||
see: https://gitee.com/openharmony/docs/blob/master/docs-en/readme/dfx.md
|
||||
Executable
+35
@@ -0,0 +1,35 @@
|
||||
# Copyright (c) 2020 Huawei Device Co., Ltd.
|
||||
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||
# you may not use this file except in compliance with the License.
|
||||
# You may obtain a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS,
|
||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
|
||||
import("//build/lite/config/component/lite_component.gni")
|
||||
|
||||
static_library("apphilogcat_static") {
|
||||
sources = [
|
||||
"hiview_applogcat.c",
|
||||
]
|
||||
cflags = [ "-Wall" ]
|
||||
include_dirs = [
|
||||
"//third_party/bounds_checking_function/include",
|
||||
]
|
||||
deps = [
|
||||
"//base/hiviewdfx/hilog_lite/frameworks/featured:hilog_shared"
|
||||
]
|
||||
}
|
||||
|
||||
lite_component("apphilogcat") {
|
||||
target_type = "executable"
|
||||
|
||||
features = [
|
||||
":apphilogcat_static",
|
||||
]
|
||||
}
|
||||
Executable
+165
@@ -0,0 +1,165 @@
|
||||
/*
|
||||
* Copyright (c) 2020 Huawei Device Co., Ltd.
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
#include <fcntl.h>
|
||||
#include <unistd.h>
|
||||
#include <stdlib.h>
|
||||
#include <time.h>
|
||||
#include <string.h>
|
||||
#include <errno.h>
|
||||
#include <dirent.h>
|
||||
#include <sys/types.h>
|
||||
#include <sys/stat.h>
|
||||
#include "log.h"
|
||||
|
||||
|
||||
#define HILOG_LOGBUFFER 2048
|
||||
#define HILOG_MAX_FILELEN 2048
|
||||
#define HILOG_PATH1 "/storage/data/log/hilog1.txt"
|
||||
#define HILOG_PATH2 "/storage/data/log/hilog2.txt"
|
||||
|
||||
static int FileSize(const char *filename)
|
||||
{
|
||||
FILE *fp = fopen(filename, "r");
|
||||
if (!fp) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
int size = 0;
|
||||
int ret = fseek(fp, 0L, SEEK_END);
|
||||
if (ret == 0) {
|
||||
size = ftell(fp);
|
||||
}
|
||||
fclose(fp);
|
||||
|
||||
return size;
|
||||
}
|
||||
|
||||
static FILE *FileClear(FILE **fp, const char *filename)
|
||||
{
|
||||
fclose(*fp);
|
||||
*fp = fopen(filename, "w");
|
||||
if (*fp == NULL) {
|
||||
return NULL;
|
||||
}
|
||||
printf("write file switch %s\n", filename);
|
||||
return *fp;
|
||||
}
|
||||
|
||||
FILE *SelectWriteFile(FILE **fp1, FILE *fp2)
|
||||
{
|
||||
int file1Size = FileSize(HILOG_PATH1);
|
||||
int file2Size = FileSize(HILOG_PATH2);
|
||||
if (file1Size < HILOG_MAX_FILELEN) {
|
||||
return *fp1;
|
||||
} else if (file2Size < HILOG_MAX_FILELEN) {
|
||||
return fp2;
|
||||
} else { // clear file1 write file 1
|
||||
return FileClear(fp1, HILOG_PATH1);
|
||||
}
|
||||
}
|
||||
|
||||
FILE *SwitchWriteFile(FILE **fp1, FILE **fp2, FILE *curFp)
|
||||
{
|
||||
int file1Size = FileSize(HILOG_PATH1);
|
||||
int file2Size = FileSize(HILOG_PATH2);
|
||||
// select file, if file1 is full, record file2, file2 is full, record file1
|
||||
if (file1Size < HILOG_MAX_FILELEN) {
|
||||
return *fp1;
|
||||
} else if (file2Size < HILOG_MAX_FILELEN) {
|
||||
return *fp2;
|
||||
} else if (curFp == *fp2) { // clear file1 write file 1
|
||||
return FileClear(fp1, HILOG_PATH1);
|
||||
} else {
|
||||
return FileClear(fp2, HILOG_PATH2);
|
||||
}
|
||||
}
|
||||
|
||||
int main(int argc, const char **argv)
|
||||
{
|
||||
#define HILOG_PERMMISION 0700
|
||||
#define HILOG_TEST_ARGC 2
|
||||
int fd;
|
||||
int ret;
|
||||
FILE *fpWrite = NULL;
|
||||
if (argc == 1) {
|
||||
#ifdef OHOS_RELEASE
|
||||
return 0;
|
||||
#endif
|
||||
}
|
||||
if (argc == HILOG_TEST_ARGC) {
|
||||
HILOG_ERROR(LOG_CORE, "TEST = %d,%s,%d\n", argc, "hilog test", argc);
|
||||
return 0;
|
||||
}
|
||||
fd = open(HILOG_DRIVER, O_RDONLY);
|
||||
if (fd < 0) {
|
||||
printf("hilog fd failed fd=%d\n", fd);
|
||||
return 0;
|
||||
}
|
||||
|
||||
FILE *fp1 = fopen(HILOG_PATH1, "at");
|
||||
if (fp1 == NULL) {
|
||||
close(fd);
|
||||
printf("open err fp1=%p\n", fp1);
|
||||
return 0;
|
||||
}
|
||||
|
||||
FILE *fp2 = fopen(HILOG_PATH2, "at");
|
||||
if (fp2 == NULL) {
|
||||
fclose(fp1);
|
||||
close(fd);
|
||||
printf("open err fp2=%p\n", fp2);
|
||||
return 0;
|
||||
}
|
||||
// First select
|
||||
fpWrite = SelectWriteFile(&fp1, fp2);
|
||||
if (fpWrite == NULL) {
|
||||
printf("SelectWriteFile open err fp1=%p\n", fp1);
|
||||
return 0;
|
||||
}
|
||||
while (1) {
|
||||
char buf[HILOG_LOGBUFFER] = {0};
|
||||
ret = read(fd, buf, HILOG_LOGBUFFER);
|
||||
if (ret < sizeof(struct HiLogEntry)) {
|
||||
continue;
|
||||
}
|
||||
struct HiLogEntry *head = (struct HiLogEntry *)buf;
|
||||
|
||||
time_t rawtime;
|
||||
struct tm *info = NULL;
|
||||
unsigned int sec = head->sec;
|
||||
rawtime = (time_t)sec;
|
||||
/* Get GMT time */
|
||||
info = gmtime(&rawtime);
|
||||
if (info == NULL) {
|
||||
continue;
|
||||
}
|
||||
buf[HILOG_LOGBUFFER - 1] = '\0';
|
||||
printf("%02d-%02d %02d:%02d:%02d.%03d %d %d %s\n", info->tm_mon + 1, info->tm_mday, info->tm_hour, info->tm_min,
|
||||
info->tm_sec, head->nsec / NANOSEC_PER_MIRCOSEC, head->pid, head->taskId, head->msg);
|
||||
|
||||
ret =
|
||||
fprintf(fpWrite, "%02d-%02d %02d:%02d:%02d.%03d %d %d %s\n", info->tm_mon + 1, info->tm_mday, info->tm_hour,
|
||||
info->tm_min, info->tm_sec, head->nsec / NANOSEC_PER_MIRCOSEC, head->pid, head->taskId, head->msg);
|
||||
// select file, if file1 is full, record file2, file2 is full, record file1
|
||||
fpWrite = SwitchWriteFile(&fp1, &fp2, fpWrite);
|
||||
if (fpWrite == NULL) {
|
||||
printf("[FATAL]File cant't open fp1=%p, fp2=%p\n", fp1, fp2);
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
Executable
+35
@@ -0,0 +1,35 @@
|
||||
# Copyright (c) 2020 Huawei Device Co., Ltd.
|
||||
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||
# you may not use this file except in compliance with the License.
|
||||
# You may obtain a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS,
|
||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
|
||||
import("//build/lite/config/component/lite_component.gni")
|
||||
|
||||
static_library("hilogcat_static") {
|
||||
sources = [
|
||||
"hiview_logcat.c",
|
||||
]
|
||||
cflags = [ "-Wall" ]
|
||||
include_dirs = [
|
||||
"//third_party/bounds_checking_function/include",
|
||||
]
|
||||
deps = [
|
||||
"//base/hiviewdfx/hilog_lite/frameworks/featured:hilog_shared",
|
||||
"//third_party/bounds_checking_function:libsec_shared",
|
||||
]
|
||||
}
|
||||
|
||||
lite_component("hilogcat") {
|
||||
target_type = "executable"
|
||||
features = [
|
||||
":hilogcat_static",
|
||||
]
|
||||
}
|
||||
Executable
+324
@@ -0,0 +1,324 @@
|
||||
/*
|
||||
* Copyright (c) 2020 Huawei Device Co., Ltd.
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdbool.h>
|
||||
#include <string.h>
|
||||
#include <stdlib.h>
|
||||
#include <fcntl.h>
|
||||
#include <unistd.h>
|
||||
#include <time.h>
|
||||
#include "log.h"
|
||||
#include "securec.h"
|
||||
|
||||
|
||||
#define HILOG_DRIVER "/dev/hilog"
|
||||
#define HILOG_LOGBUFFER 1024
|
||||
#undef LOG_DOMAIN
|
||||
#undef LOG_TAG
|
||||
|
||||
#define LOG_DOMAIN 0xD002D00
|
||||
#define LOG_TAG "hilogcat"
|
||||
|
||||
#define CMD_MIN_LEN 2
|
||||
#define CMD_MAX_LEN 32
|
||||
#define CMD_HILOGCAT "hilog"
|
||||
#define CMD_HIEVENT "hievent"
|
||||
#define OPTION_TAG '-'
|
||||
#define OPTION_LIST 'l'
|
||||
#define OPTION_SET 'C'
|
||||
#define OPTION_SIMULATE 's'
|
||||
#define OPTION_HELP 'h'
|
||||
#define OPTION_2_FILE 'f'
|
||||
#define OPTION_START 't'
|
||||
#define OPTION_UART 'R'
|
||||
|
||||
|
||||
#define PARA_LEVEL "level"
|
||||
#define PARA_LEVEL_LEN 5
|
||||
#define PARA_MODULE "mod"
|
||||
#define PARA_MODULE_LEN 3
|
||||
#define OP_ASSIGN '='
|
||||
#define STR_MAX_LEN 128
|
||||
|
||||
typedef struct {
|
||||
const unsigned char outputOption : 4; /* Control log output mode. Cannot be modified during running. */
|
||||
unsigned char hiviewInited : 1; /* Indicates whether the hiview service is inited. */
|
||||
unsigned char level : 3; /* Control log output level. HILOG_LV_XXX */
|
||||
unsigned char logSwitch : 1; /* Indicates whether to enable the log component. */
|
||||
unsigned char eventSwitch : 1; /* Indicates whether to enable the event component. */
|
||||
unsigned char dumpSwitch : 1; /* Indicates whether to enable the dump component. */
|
||||
unsigned char logOutputModule; /* Control log output module. */
|
||||
unsigned short writeFailureCount;
|
||||
} HiviewConfig;
|
||||
|
||||
typedef enum {
|
||||
OUTPUT_OPTION_DEBUG = 0, /* Output to the UART without buffer. Commercial versions are forbidden. */
|
||||
OUTPUT_OPTION_FLOW, /* Output to UART via SAMR */
|
||||
OUTPUT_OPTION_TEXT_FILE,
|
||||
OUTPUT_OPTION_BIN_FILE,
|
||||
OUTPUT_OPTION_MAX
|
||||
} HiviewOutputOption;
|
||||
|
||||
#define HIVIEW_FEATURE_ON 1
|
||||
#define HIVIEW_FEATURE_OFF 0
|
||||
#define HILOG_MODULE_ALL 0xff
|
||||
|
||||
static char g_logLevelInfo[HILOG_LEVEL_MAX] = {
|
||||
'N', // "NONE"
|
||||
'N', // "NONE"
|
||||
'N', // "NONE"
|
||||
'D', // "DEBUG"
|
||||
'I', // "INFO"
|
||||
'W', // "WARN"
|
||||
'E', // "ERROR"
|
||||
'F' // "FATAL"
|
||||
};
|
||||
|
||||
#define HILOG_MODULE_MAX_NUM 50
|
||||
#define DOMIAN_ID_LENTH 6
|
||||
static char g_logModuleInfo[HILOG_MODULE_MAX_NUM][DOMIAN_ID_LENTH] = {
|
||||
"00000",
|
||||
"01100", // "NONE"
|
||||
"01200", // "NONE"
|
||||
"01300", // "NONE"
|
||||
"01400", // "NONE"
|
||||
"01500", // "NONE"
|
||||
"01600", // "NONE"
|
||||
"01700", // "NONE"
|
||||
"01800", // "NONE"
|
||||
"01900", // "NONE"
|
||||
"02500", // "NONE"
|
||||
"02600", // "NONE"
|
||||
"02D00", // "NONE"
|
||||
};
|
||||
|
||||
HiviewConfig g_hiviewConfig = {
|
||||
.outputOption = OUTPUT_OPTION_FLOW,
|
||||
.level = LOG_DEBUG,
|
||||
.logSwitch = HIVIEW_FEATURE_ON,
|
||||
.dumpSwitch = HIVIEW_FEATURE_OFF,
|
||||
.eventSwitch = HIVIEW_FEATURE_OFF,
|
||||
};
|
||||
|
||||
static void HilogHelpProc(void)
|
||||
{
|
||||
printf("hilog [-h] [-l level/mod] [-C level <1>] [-C mod <3>]\n");
|
||||
printf(" -h Help\n");
|
||||
printf(" -l Query the level and module definition information\n");
|
||||
printf(" -l level Query the level definition information\n");
|
||||
printf(" -l mod Query the level definition information\n");
|
||||
printf(" -C Enable all level logs of all modules\n");
|
||||
printf(" -C level <id> Set the lowest log level\n");
|
||||
printf(" -C mod <id> Enable the logs of a specified module and disable other modules\n");
|
||||
printf(" -f <filename> Enable the logs to a specified file\n");
|
||||
}
|
||||
|
||||
static void ListLevelInfo(void)
|
||||
{
|
||||
printf("======Level Information======\n");
|
||||
printf(" 3 - DEBUG\n");
|
||||
printf(" 4 - INFO\n");
|
||||
printf(" 5 - WARN\n");
|
||||
printf(" 6 - ERROR\n");
|
||||
printf(" 7 - FATAL\n");
|
||||
}
|
||||
|
||||
static void ListModuleInfo(void)
|
||||
{
|
||||
int i, ret;
|
||||
char modInfo[STR_MAX_LEN] = { '\0' };
|
||||
printf("======Module Information======\n");
|
||||
for (i = 0; i < HILOG_MODULE_MAX_NUM; i++) {
|
||||
if (g_logModuleInfo[i][0] == 0) {
|
||||
break;
|
||||
}
|
||||
ret = snprintf_s(modInfo, sizeof(modInfo), sizeof(modInfo) - 1, " %d - %s\n", i, g_logModuleInfo[i]);
|
||||
if (ret > 0) {
|
||||
modInfo[ret] = '\0';
|
||||
printf((const char *)modInfo);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static void HilogListProc(const char *cmd)
|
||||
{
|
||||
if (cmd == NULL) {
|
||||
ListLevelInfo();
|
||||
ListModuleInfo();
|
||||
} else if (strncmp(cmd, PARA_LEVEL, PARA_LEVEL_LEN) == 0) {
|
||||
ListLevelInfo();
|
||||
} else if (strncmp(cmd, PARA_MODULE, PARA_MODULE_LEN) == 0) {
|
||||
ListModuleInfo();
|
||||
}
|
||||
}
|
||||
|
||||
static bool SetLogLevel(unsigned char level)
|
||||
{
|
||||
if (level >= LOG_DEBUG && level < HILOG_LEVEL_MAX) {
|
||||
g_hiviewConfig.level = level;
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
static void SetLogOutputModule(unsigned char mod)
|
||||
{
|
||||
g_hiviewConfig.logOutputModule = mod;
|
||||
}
|
||||
|
||||
static void SetOutputModule(const char *cmd)
|
||||
{
|
||||
char *endPtr = NULL;
|
||||
int mod = strtol(cmd, &endPtr, 0);
|
||||
SetLogOutputModule((unsigned char)mod);
|
||||
}
|
||||
|
||||
static void SetOutputLevel(const char *cmd)
|
||||
{
|
||||
char *endPtr = NULL;
|
||||
int level;
|
||||
if (cmd != NULL) {
|
||||
level = strtol(cmd, &endPtr, 0);
|
||||
} else {
|
||||
level = LOG_DEBUG;
|
||||
}
|
||||
if (SetLogLevel((unsigned char)level) == true) {
|
||||
printf("Set the log output level success.\n");
|
||||
return;
|
||||
}
|
||||
printf("Set the log output level failure level=%d.\n", level);
|
||||
}
|
||||
|
||||
|
||||
static void HilogSetProc(const char *option, const char *attr)
|
||||
{
|
||||
if (option == NULL) {
|
||||
SetLogLevel(LOG_DEBUG);
|
||||
SetLogOutputModule(HILOG_MODULE_MAX_NUM);
|
||||
} else if (strncmp(option, PARA_LEVEL, PARA_LEVEL_LEN) == 0) {
|
||||
SetOutputLevel(attr);
|
||||
} else if (strncmp(option, PARA_MODULE, PARA_MODULE_LEN) == 0) {
|
||||
SetOutputModule(attr);
|
||||
}
|
||||
}
|
||||
|
||||
static int HilogCmdProc(int argc, const char **argv)
|
||||
{
|
||||
#define ARG2 1
|
||||
#define ARG3 2
|
||||
#define ARG4 3
|
||||
|
||||
int i = 0;
|
||||
|
||||
if (argv[ARG2][i++] == OPTION_TAG) {
|
||||
switch (argv[ARG2][i++]) {
|
||||
case OPTION_HELP:
|
||||
HilogHelpProc();
|
||||
return 0;
|
||||
case OPTION_LIST:
|
||||
HilogListProc(&argv[ARG3][0]);
|
||||
return 0;
|
||||
case OPTION_SET:
|
||||
HilogSetProc(&argv[ARG3][0], &argv[ARG4][0]);
|
||||
return 1;
|
||||
case OPTION_2_FILE:
|
||||
return 0;
|
||||
default:
|
||||
printf("Invalid command.\n");
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
printf("Invalid command.\n");
|
||||
return 0;
|
||||
}
|
||||
|
||||
static bool FilterLevelLog(unsigned char setLevel, unsigned char logLevel)
|
||||
{
|
||||
int logMinLevel;
|
||||
|
||||
for (logMinLevel = LOG_DEBUG; logMinLevel < HILOG_LEVEL_MAX; logMinLevel++) {
|
||||
if (logLevel == g_logLevelInfo[logMinLevel]) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
// Loglevel >= set level, may print log
|
||||
if (logMinLevel >= setLevel) {
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
static bool FilterModuleLog(unsigned char setModule, const char *logModule)
|
||||
{
|
||||
if (setModule == HILOG_MODULE_MAX_NUM) {
|
||||
return true;
|
||||
}
|
||||
int ret = strncmp(logModule, g_logModuleInfo[setModule], DOMAIN_LENGTH);
|
||||
// If module = setmodule, may print log
|
||||
if (ret == 0) {
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
int main(int argc, const char **argv)
|
||||
{
|
||||
int ret;
|
||||
bool printFlag = true;
|
||||
if (argc > 1) {
|
||||
ret = HilogCmdProc(argc, argv);
|
||||
if (ret == 0) {
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
int fd = open(HILOG_DRIVER, O_RDONLY);
|
||||
if (fd < 0) {
|
||||
HILOG_ERROR(LOG_CORE, "open hilog driver failed\n");
|
||||
return 0;
|
||||
}
|
||||
while (1) {
|
||||
char buf[HILOG_LOGBUFFER] = {0};
|
||||
ret = read(fd, buf, HILOG_LOGBUFFER);
|
||||
if (ret < sizeof(struct HiLogEntry)) {
|
||||
continue;
|
||||
}
|
||||
struct HiLogEntry *head = (struct HiLogEntry *)buf;
|
||||
|
||||
time_t rawtime;
|
||||
struct tm *info = NULL;
|
||||
unsigned int sec = head->sec;
|
||||
rawtime = (time_t)sec;
|
||||
/* Get GMT time */
|
||||
info = gmtime(&rawtime);
|
||||
|
||||
printFlag = FilterLevelLog(g_hiviewConfig.level, *(head->msg));
|
||||
if (!printFlag) {
|
||||
continue;
|
||||
}
|
||||
#define MODULE_OFFSET 2
|
||||
printFlag = FilterModuleLog(g_hiviewConfig.logOutputModule, (head->msg) + MODULE_OFFSET);
|
||||
if (!printFlag) {
|
||||
continue;
|
||||
}
|
||||
if (info == NULL) {
|
||||
continue;
|
||||
}
|
||||
buf[HILOG_LOGBUFFER - 1] = '\0';
|
||||
printf("%02d-%02d %02d:%02d:%02d.%03d %d %d %s\n", info->tm_mon + 1, info->tm_mday, info->tm_hour, info->tm_min,
|
||||
info->tm_sec, head->nsec / NANOSEC_PER_MIRCOSEC, head->pid, head->taskId, head->msg);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
Reference in New Issue
Block a user