Metadata-Version: 2.1
Name: mtnlog
Version: 1.0.2
Summary: A simple performance logger for Python
Author-email: Wongkraiwich Chuenchomphu <wongkraiwich@inedible.dev>
Project-URL: Homepage, https://github.com/kentakoong/mtnlog
Project-URL: Issues, https://github.com/kentakoong/mtnlog/issues
Classifier: Programming Language :: Python :: 3
Classifier: License :: OSI Approved :: MIT License
Classifier: Operating System :: OS Independent
Requires-Python: >=3.8
Description-Content-Type: text/markdown
License-File: LICENSE.md
Requires-Dist: nvitop
Requires-Dist: pandas

# mtnlog - A simple multinode performance logger for Python

## Introduction

mtnlog is a simple multinode performance logger for Python. It is designed to be used in a similar way to Python's built-in logging module, but with a focus on performance logging. It provides a simple API for logging performance data, including start and end times, and allows for easy integration with other logging systems.

## Installation

You can install mtnlog using pip:

```bash
pip install mtnlog
```

## Usage

To use mtnlog, you have two features: `JSONLogger` and `PerformanceLogger`.

### JSONLogger

The `JSONLogger` class is a simple logger that writes performance data to a JSON file. You can create a new `JSONLogger` instance by passing a file path to the constructor:

```python
from mtnlog import JSONLogger

logger = JSONLogger(log_dir='logs') # logs is the directory where the log file will be saved
```

You can then use the `log` method to log performance data:

```python
logger.log('<your_dict>', filename='log') # your_dict is a dictionary with the data you want to log / filename is the name of the file
```

`your_dict` is a dictionary with the data you want to log.
`filename` is the name of the file where the data will be saved

### PerformanceLogger

The `PerformanceLogger` class is a logger for system performance data. It logs the the time taken to execute the block, as well as the CPU, memory, and GPU usage. You can create a new `PerformanceLogger` instance by passing a file path to the constructor:

```python
from mtnlog import PerformanceLogger

collector = PerformanceLogger(log_dir="<your_log_dir>", log_node="<current_node>")
```

`your_log_dir` is the directory where the log file will be saved.
`current_node` is the number of the node you are logging.

You can then use the `change_tag` method to change the tag of the log:

```python
collector.change_tag("<new_tag>")
```

`new_tag` is the new tag you want to use.

To stop logging, you can use the `stop` method:

```python
collector.stop()
```

## Example

Here is an example of how to use mtnlog:

```python
from mtnlog import JSONLogger, PerformanceLogger

# Create a JSONLogger instance

logger = JSONLogger(log_dir='logs')

# Log some data

logger.log({'message': 'Hello, world!'}, filename='log')

# Create a PerformanceLogger instance

collector = PerformanceLogger(log_dir='logs', log_node="0")

# Change the tag

collector.change_tag('new_tag')

# Stop logging

collector.stop()

```
