# llvm-diagnostics
Python module for creating diagnostics using the LLVM diagnostics specification
# Installation
```sh
% pip install llvm-diagnostics
```
# Usage
## Parsing a log file containing LLVM Diagnostics messages
Parsing a logging file can be done as follows:
```python
from llvm_diagnostics.parser import diagnostics_messages_from_file
for error in list(diagnostics_messages_from_file("test/resources/test.out")):
print(f"Diagnostics Message found:")
print(f" File: {error.file_path}")
print(f" Level: {error.level}")
print(f" Message: {error.message}")
```
Which will result in output similar to:
```sh
Diagnostics Message found:
File: /code/supermarket-buyer-supplier/src/offers/convert_customer_receipt.cpp
Level: DiagnosticsLevel.WARNING
Message: 'fruit_section' is deprecated: 2021.Q2 Deprecated Use application::supermarket_app::receipt_engine::receipt::FruitInformation::fruit_section_labels [-Wdeprecated-declarations]
```
## Reporting on Diagnostics messages
You can use `llvm-diagnostics` to create your own Diagnostics messages.
### Reporting a message in LLVM Diagnostics format
```python
import llvm_diagnostics as logger
message = logger.Warning(
file_path='fake_file.py',
line_number=logger.Range(start=10),
column_number=logger.Range(start=15, range=3),
line="mPercentage = 105",
expectations="100",
message='Value exceeds maximum, automatically capped to 100',
).report()
```
This will result in the following message on `stderr`:
![example](resources/llvm_output_example.png)
### Reporting a message in GitHub format
```python
import llvm_diagnostics as logger
logger.config(logger.formatters.GitHub())
message = logger.Warning(
file_path='fake_file.py',
line_number=logger.Range(start=10),
column_number=logger.Range(start=15, range=3),
line="mPercentage = 105",
expectations="100",
message='Value exceeds maximum, automatically capped to 100',
).report()
```
This will result in the following message on `stderr`:
```sh
::warning file=fake_file.py,line=10,col=15,endColumn=18::Value exceeds maximum, automatically capped to 100
```
Raw data
{
"_id": null,
"home_page": "https://github.com/tomtom-international/llvm-diagnostics",
"name": "llvm-diagnostics",
"maintainer": "",
"docs_url": null,
"requires_python": ">=3.7",
"maintainer_email": "",
"keywords": "diagnostics logger logging llvm",
"author": "Kevin de Jong",
"author_email": "KevinDeJong@tomtom.com",
"download_url": "https://files.pythonhosted.org/packages/10/17/ecb54db99380a8f0c332bf286a586c202925043ab4b1667ca9dee9ffac6b/llvm-diagnostics-3.0.1.tar.gz",
"platform": null,
"description": "# llvm-diagnostics\n\nPython module for creating diagnostics using the LLVM diagnostics specification\n\n# Installation\n\n```sh\n% pip install llvm-diagnostics\n```\n\n# Usage\n\n## Parsing a log file containing LLVM Diagnostics messages\n\nParsing a logging file can be done as follows:\n\n```python\nfrom llvm_diagnostics.parser import diagnostics_messages_from_file\n\nfor error in list(diagnostics_messages_from_file(\"test/resources/test.out\")):\n print(f\"Diagnostics Message found:\")\n print(f\" File: {error.file_path}\")\n print(f\" Level: {error.level}\")\n print(f\" Message: {error.message}\")\n```\n\nWhich will result in output similar to:\n\n```sh\nDiagnostics Message found:\n File: /code/supermarket-buyer-supplier/src/offers/convert_customer_receipt.cpp\n Level: DiagnosticsLevel.WARNING\n Message: 'fruit_section' is deprecated: 2021.Q2 Deprecated Use application::supermarket_app::receipt_engine::receipt::FruitInformation::fruit_section_labels [-Wdeprecated-declarations]\n```\n\n## Reporting on Diagnostics messages\n\nYou can use `llvm-diagnostics` to create your own Diagnostics messages.\n\n### Reporting a message in LLVM Diagnostics format\n\n```python\nimport llvm_diagnostics as logger\n\nmessage = logger.Warning(\n file_path='fake_file.py',\n line_number=logger.Range(start=10),\n column_number=logger.Range(start=15, range=3),\n line=\"mPercentage = 105\",\n expectations=\"100\",\n message='Value exceeds maximum, automatically capped to 100',\n).report()\n```\nThis will result in the following message on `stderr`:\n\n![example](resources/llvm_output_example.png)\n\n### Reporting a message in GitHub format\n\n```python\nimport llvm_diagnostics as logger\n\nlogger.config(logger.formatters.GitHub())\n\nmessage = logger.Warning(\n file_path='fake_file.py',\n line_number=logger.Range(start=10),\n column_number=logger.Range(start=15, range=3),\n line=\"mPercentage = 105\",\n expectations=\"100\",\n message='Value exceeds maximum, automatically capped to 100',\n).report()\n```\n\nThis will result in the following message on `stderr`:\n\n```sh\n::warning file=fake_file.py,line=10,col=15,endColumn=18::Value exceeds maximum, automatically capped to 100\n```\n\n\n",
"bugtrack_url": null,
"license": "Apache License 2.0",
"summary": "Python module for creating diagnostics using the LLVM diagnostics specification",
"version": "3.0.1",
"project_urls": {
"Download": "https://github.com/tomtom-international/llvm-diagnostics",
"Homepage": "https://github.com/tomtom-international/llvm-diagnostics"
},
"split_keywords": [
"diagnostics",
"logger",
"logging",
"llvm"
],
"urls": [
{
"comment_text": "",
"digests": {
"blake2b_256": "fb8f35f24961ecd06a81edface2212e7c32ea580c640943fd8a27e7a9b58f6b7",
"md5": "fb191bbc5f7a7784ae04d5a96185cafa",
"sha256": "51aac4c0a29dc4bcd21c15bd7e2c050f2e5d59ef95ae0e8a1e0174b7964a386c"
},
"downloads": -1,
"filename": "llvm_diagnostics-3.0.1-py3-none-any.whl",
"has_sig": false,
"md5_digest": "fb191bbc5f7a7784ae04d5a96185cafa",
"packagetype": "bdist_wheel",
"python_version": "py3",
"requires_python": ">=3.7",
"size": 11283,
"upload_time": "2023-10-03T12:48:39",
"upload_time_iso_8601": "2023-10-03T12:48:39.818345Z",
"url": "https://files.pythonhosted.org/packages/fb/8f/35f24961ecd06a81edface2212e7c32ea580c640943fd8a27e7a9b58f6b7/llvm_diagnostics-3.0.1-py3-none-any.whl",
"yanked": false,
"yanked_reason": null
},
{
"comment_text": "",
"digests": {
"blake2b_256": "1017ecb54db99380a8f0c332bf286a586c202925043ab4b1667ca9dee9ffac6b",
"md5": "e46774ee9d4f182cc7dd0b2900da7b6d",
"sha256": "67470811bbab34bf75d6ef298d6a6f35b1133c710e8fc15c793eb6755d07215f"
},
"downloads": -1,
"filename": "llvm-diagnostics-3.0.1.tar.gz",
"has_sig": false,
"md5_digest": "e46774ee9d4f182cc7dd0b2900da7b6d",
"packagetype": "sdist",
"python_version": "source",
"requires_python": ">=3.7",
"size": 35632,
"upload_time": "2023-10-03T12:48:41",
"upload_time_iso_8601": "2023-10-03T12:48:41.344090Z",
"url": "https://files.pythonhosted.org/packages/10/17/ecb54db99380a8f0c332bf286a586c202925043ab4b1667ca9dee9ffac6b/llvm-diagnostics-3.0.1.tar.gz",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2023-10-03 12:48:41",
"github": true,
"gitlab": false,
"bitbucket": false,
"codeberg": false,
"github_user": "tomtom-international",
"github_project": "llvm-diagnostics",
"travis_ci": false,
"coveralls": true,
"github_actions": true,
"lcname": "llvm-diagnostics"
}