Skip to content

Commit

Permalink
1.2.2
Browse files Browse the repository at this point in the history
  • Loading branch information
wfxey committed Dec 26, 2024
1 parent f106b4b commit 93c2843
Show file tree
Hide file tree
Showing 4 changed files with 65 additions and 39 deletions.
50 changes: 31 additions & 19 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@

# InsightLogger
# **InsightLogger**

`InsightLogger` is an advanced, customizable logging library designed for Python applications. It helps developers track application performance, log detailed error messages, visualize data through charts, and create summaries of application execution.

## Features
## **Features**

- **Flexible Logging**: Supports multiple log levels (INFO, DEBUG, ERROR, etc.) with customizable formatting.
- **Rotating Logs**: Automatically manages log file size to prevent excessive disk usage.
Expand All @@ -14,28 +13,31 @@

---

## Installation
## **Installation**

1. Clone the repository:

```bash
git clone https://github.com/VelisCore/InsightLogger.git
```

2. Install required dependencies:

```bash
pip install -r requirements.txt
```

Dependencies include:
- `termcolor`
- `matplotlib`
- `tabulate`
- `psutil`
Dependencies include:
- `termcolor`
- `matplotlib`
- `tabulate`
- `psutil`

---

## Usage
## **Usage**

### Getting Started
### **Getting Started**

```python
from insight_logger import InsightLogger
Expand All @@ -57,15 +59,17 @@ summary = logger.generate_log_summary()
logger.logger.info("\nSummary of Logs:\n" + summary)
```

### Decorators
### **Decorators**

Measure execution time for any function:

```python
@logger.log_function_time
def sample_function():
time.sleep(1.5)
```

### Log Levels
### **Log Levels**

Supported log levels include:
- `INFO`
Expand All @@ -79,7 +83,8 @@ Supported log levels include:
- `HIGHLIGHT`
- `CRITICAL`

### Environment Summary
### **Environment Summary**

`InsightLogger` automatically collects environment information, such as:
- Python version
- Operating system and version
Expand All @@ -88,16 +93,18 @@ Supported log levels include:

---

## Example Output
## **Example Output**

### Console Output

```
[INFO] This is an info log.
[ERROR] An error occurred.
Function 'example_function' executed in 1500.12 ms.
```

### Summary Table

| Environment Info | Details |
|------------------------|-------------------------|
| Python Version | 3.10 |
Expand All @@ -106,27 +113,32 @@ Function 'example_function' executed in 1500.12 ms.
| Total Errors | 1 |

### Log Frequency Graph

![Log Frequency](.Insight/2023-12-01/log_frequency.png)

---

## Contribution
## **Contribution**

We welcome contributions to `InsightLogger`. To contribute:
1. Fork the repository.
2. Create a new branch for your feature or bug fix.
3. Submit a pull request with detailed descriptions of changes.

---

## License
## **License**

`InsightLogger` is licensed under the MIT License. See `LICENSE` for details.

---

## Support
## **Support**

For issues or feature requests, please [open an issue](https://github.com/VelisCore/InsightLogger/issues).

---

## Author
## **Author**

Developed by **VelisCore**.
4 changes: 3 additions & 1 deletion insightlog/__init__.py
Original file line number Diff line number Diff line change
@@ -1 +1,3 @@
from .main import InsightLogger as setup
from .insight_logger import InsightLogger

__all__ = ['InsightLogger']
43 changes: 27 additions & 16 deletions insightlog/main.py → insightlog/insight_logger.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import logging
import datetime
import os
import random
import time
import platform
import psutil
Expand All @@ -12,9 +11,11 @@
from logging.handlers import RotatingFileHandler
from tabulate import tabulate
import itertools
import sys
import io

def ensure_insight_folder():
insight_dir = os.path.join(os.getcwd(), '.Insight')
insight_dir = os.path.join(os.getcwd(), '.insight')
if not os.path.exists(insight_dir):
os.makedirs(insight_dir)
return insight_dir
Expand All @@ -30,6 +31,7 @@ def start_logging(name, save_log="enabled", log_dir=".Insight", log_filename=Non
logger = logging.getLogger(name)
if not logger.hasHandlers():
logger.setLevel(log_level)

if save_log == "enabled":
if not os.path.isdir(log_dir):
os.makedirs(log_dir)
Expand All @@ -41,11 +43,13 @@ def start_logging(name, save_log="enabled", log_dir=".Insight", log_filename=Non
file_formatter = logging.Formatter('%(asctime)s - %(levelname)s - %(message)s')
file_handler.setFormatter(file_formatter)
logger.addHandler(file_handler)

console_handler = logging.StreamHandler()
console_handler.setLevel(log_level)
console_formatter = logging.Formatter('%(asctime)s - %(levelname)s - %(message)s')
console_handler.setFormatter(console_formatter)
logger.addHandler(console_handler)

return logger

class InsightLogger:
Expand Down Expand Up @@ -80,21 +84,22 @@ def spin():
return result
return wrapper


def format_message(self, level, text, bold=False, background=None, border=False, header=False, underline=False, urgent=False):
color = {
"INFO": "\033[92m",
"SUCCESS": "\033[92m",
"FAILURE": "\033[1;31m",
"WARNING": "\033[93m",
"DEBUG": "\033[94m",
"ALERT": "\033[93m",
"TRACE": "\033[96m",
"HIGHLIGHT": "\033[1;33m",
"BORDERED": "\033[1;34m",
"HEADER": "\033[1;37m",
"ERROR": "\033[91m",
"INFO": "\033[92m",
"SUCCESS": "\033[92m",
"FAILURE": "\033[1;31m",
"WARNING": "\033[93m",
"DEBUG": "\033[94m",
"ALERT": "\033[93m",
"TRACE": "\033[96m",
"HIGHLIGHT": "\033[1;33m",
"BORDERED": "\033[1;34m",
"HEADER": "\033[1;37m",
"ERROR": "\033[91m",
"CRITICAL": "\033[1;41m",
}.get(level, "\033[0m")
}.get(level, "\033[0m")

reset = "\033[0m"
bold_style = "\033[1m" if bold else ""
Expand Down Expand Up @@ -162,11 +167,12 @@ def generate_log_summary(self):
table_rows = [(key, value) for key, value in environment_info.items()]
table_footer = ["Total Errors", sum(self.error_count.values())]

summary_table = tabulate(table_rows + [table_footer], headers=table_header, tablefmt="fancy_grid", numalign="right")
summary_table = tabulate(table_rows + [table_footer], headers=table_header, tablefmt="grid", numalign="right")

return summary_table

if __name__ == "__main__":

def main():
try:
insight_logger = InsightLogger(name="InsightLog")

Expand All @@ -176,6 +182,7 @@ def example_function():

example_function()

# Example logs
insight_logger.log_types("INFO", "This is an info log.")
insight_logger.log_types("ERROR", "This is an error log.")
insight_logger.log_types("SUCCESS", "This is a success log.")
Expand All @@ -194,3 +201,7 @@ def example_function():

except Exception as e:
insight_logger.logger.error(f"Error initializing InsightLogger: {e}")


if __name__ == "__main__":
main()
7 changes: 4 additions & 3 deletions setup.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
from setuptools import setup, find_packages

# Read the long description from README.md
with open("README.md", "r", encoding="utf-8") as fh:
long_description = fh.read()

setup(
name='InsightLogger',
version='1.2.1',
version='1.2.2',
packages=find_packages(),
license='MIT',
description='A customizable logging utility with enhanced features for developers.',
Expand All @@ -14,7 +15,7 @@
long_description=long_description,
long_description_content_type="text/markdown",
url='https://github.com/VelisCore/InsightLogger',
download_url='https://github.com/VelisCore/InsightLogger/archive/refs/tags/v1.2.1tar.gz',
download_url='https://github.com/VelisCore/InsightLogger/archive/refs/tags/v1.2.2.tar.gz',
keywords=[
'logging', 'log', 'logger', 'developer tools', 'performance monitoring', 'visualization'
],
Expand Down Expand Up @@ -43,4 +44,4 @@
'Documentation': 'https://github.com/VelisCore/InsightLogger/wiki',
'Source Code': 'https://github.com/VelisCore/InsightLogger',
},
)
)

0 comments on commit 93c2843

Please sign in to comment.