Skip to content

Commit

Permalink
1.3.2
Browse files Browse the repository at this point in the history
  • Loading branch information
wfxey committed Feb 28, 2025
1 parent 9838678 commit 6830fa0
Show file tree
Hide file tree
Showing 5 changed files with 179 additions and 188 deletions.
162 changes: 88 additions & 74 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,43 +1,42 @@
# **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.
`InsightLogger` is an advanced, customizable logging library designed for Python applications. It enables performance monitoring, detailed error logging, visual log representation, and execution summaries to gain better insights.

## **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.
- **Execution Time Tracking**: Decorate functions to measure and log execution time with live spinning animation.
- **Log Visualization**: Automatically generate bar graphs showing log level frequencies.
- **Environment Summary**: Generate detailed summaries of the runtime environment and execution statistics.
- **Enhanced Formatting**: Add styles like bold, underline, headers, and more to log messages.
- **Flexible Logging**: Supports multiple log levels (INFO, DEBUG, ERROR, etc.) with customizable formats and handles both console and file logs.
- **Rotating Logs**: Automatically manages log file sizes and prevents excessive disk usage through rotating log files.
- **Execution Time Tracking**: Use decorators to measure and log the execution time of functions, including a live spinning animation during function execution.
- **Log Visualization**: Automatically generates bar charts that display the frequency of different log levels.
- **Environmental Insights**: Captures and displays detailed runtime environment information, including system specs and resource usage.
- **Advanced Log Formatting**: Adds visual styles like bold, underline, and headers to log messages for better clarity.

---

## **Installation**

1. Clone the repository:

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

2. Install required dependencies:
2. Install the required dependencies:

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

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

---
- `termcolor` for colored console output.
- `matplotlib` for visualizing logs.
- `tabulate` for neatly formatted tables.
- `psutil` for monitoring system resources.

## **Usage**

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

```python
from insightlog import InsightLogger
Expand All @@ -47,98 +46,113 @@ logger = InsightLogger(name="AppLog")
@logger.log_function_time
def example_function():
time.sleep(2)
time.sleep(2)
# Logging
logger.log_types("INFO", "This is an info log.")
logger.log_types("ERROR", "An error occurred.")
logger.log("INFO", "This is an info log.")
logger.log("ERROR", "An error occurred.")
# Visualize logs and generate a summary
logger.draw_and_save_graph()
summary = logger.generate_log_summary()
logger.logger.info("\nSummary of Logs:\n" + summary)
logger.generate_log_visualization()
summary = logger.generate_execution_summary()
logger.logger.info("\nLog Summary:\n" + summary)
```

### Logging Example

You can log messages with various severity levels such as INFO, ERROR, SUCCESS, WARNING, etc.

```python
logger.log("INFO", "This is an info message.")
logger.log("ERROR", "An error occurred.")
```

### **Decorators**
### Execution Time Tracking

Measure execution time for any function:
Use the `@log_function_time` decorator to measure and log the execution time of functions.

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

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

Supported log levels include:
- `INFO`
- `ERROR`
- `SUCCESS`
- `FAILURE`
- `WARNING`
- `DEBUG`
- `ALERT`
- `TRACE`
- `HIGHLIGHT`
- `CRITICAL`

### **Environment Summary**

`InsightLogger` automatically collects environment information, such as:
- Python version
- Operating system and version
- Machine specifications (CPU, memory, etc.)
- Execution start and end times

---
- INFO
- ERROR
- SUCCESS
- FAILURE
- WARNING
- DEBUG
- ALERT
- TRACE
- CRITICAL

Each log level has its own format for console output.

### Insights and Visualization

After logging, InsightLogger provides valuable insights including:

- **Environmental Info**: Python version, OS version, machine specs (CPU, memory, etc.), and uptime.
- **Log Level Distribution**: A bar chart showing the frequency of each log level.

```python
logger.generate_environment_summary() # Displays environment details
logger.generate_log_visualization() # Generates and saves the log distribution chart
```

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

### Console Output
Console Output:

```
[INFO] This is an info log.
[ERROR] An error occurred.
Function 'example_function' executed in 1500.12 ms.
```
### Summary Table
Environment Summary:
| Environment Info | Details |
|------------------------|-------------------------|
| Python Version | 3.10 |
| Operating System | Windows |
| Memory | 16.00 GB |
| Total Errors | 1 |
| Environment Info | Details |
|------------------|---------------|
| Python Version | 3.10 |
| OS | Windows |
| RAM | 16.00 GB |
| Total Errors | 1 |
### Log Frequency Graph
Log Frequency Chart: (Bar chart displaying the frequency of different log levels)
![Log Frequency](.Insight/2023-12-01/log_frequency.png)
## **Advanced Features**
---
- **Rotating Logs**: Configure log rotation to prevent excessive disk usage.
- **Real-Time Execution Tracker**: Display the real-time execution time of functions with a live spinning animation.
- **Error and Execution Tracking**: Track error counts, execution times, and resource usage (CPU, memory).
## **Contribution**
## **Contributing**
Contributions to InsightLogger are welcome. To contribute:
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.

---
3. Submit a pull request with detailed descriptions of the changes.
## **License**
`InsightLogger` is licensed under the MIT License. See `LICENSE` for details.

---
InsightLogger is licensed under the MIT License. See LICENSE for details.
## **Support**
For issues or feature requests, please [open an issue](https://github.com/VelisCore/InsightLogger/issues).

---
For issues or feature requests, please open an issue.
## **Author**
Developed by **VelisCore**.
Developed by VelisCore.
## **Additional Notes**
- InsightLogger automatically creates a folder named `.insight` to store logs and visualizations.
- The logging system supports both console output and file logs, with rotation based on size.
2 changes: 1 addition & 1 deletion insightlog/__init__.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
from .insight_logger import InsightLogger
from .insight_logger import InsightLog

__all__ = ['InsightLogger']
Loading

0 comments on commit 6830fa0

Please sign in to comment.