ultraprint


Nameultraprint JSON
Version 3.1.0 PyPI version JSON
download
home_pagehttps://github.com/Kawai-Senpai/UltraPrint
SummaryUltraprint is a versatile Python library that enhances your command-line output with colorful text, styled formatting, and easy-to-use logging utilities. Perfect for creating visually appealing console applications.
upload_time2024-11-12 16:55:51
maintainerNone
docs_urlNone
authorRanit Bhowmick
requires_pythonNone
licenseMIT License with attribution requirement
keywords printing console formatting logging colored output styled text
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            # `ultraprint` - A Python Library for Enhanced Terminal Output

Welcome to `ultraprint`! This Python library is designed to enhance terminal output with colorful and styled text, making your console logs more readable and aesthetically pleasing developed by [*Ranit Bhowmick*](https://www.linkedin.com/in/ranitbhowmick/) & [*Sayanti Chatterjee*](https://www.linkedin.com/in/sayantichatterjee/). Whether you're building a command-line application, debugging code, or just want to add some flair to your terminal, `ultraprint` provides a simple and effective solution.

## Table of Contents

1. [Introduction](#introduction)
2. [Installation](#installation)
3. [Basic Usage](#basic-usage)
   - [Color Functions](#color-functions)
   - [Text Style Functions](#text-style-functions)
   - [Background Color Functions](#background-color-functions)
   - [Newline Function](#newline-function)
4. [Advanced Usage: Logging](#advanced-usage-logging)
   - [Logger Class](#logger-class)
   - [Logger Methods](#logger-methods)
5. [Documentation](#documentation)
   - [Color Functions](#color-functions)
   - [Text Style Functions](#text-style-functions)
   - [Background Color Functions](#background-color-functions)
   - [Logger Class](#logger-class)
6. [Examples](#examples)
7. [Contributing](#contributing)

## Introduction

`ultraprint` is a Python library that extends the capabilities of the standard `print` function. It allows you to easily print text in different colors, styles, and backgrounds in the terminal. Additionally, it includes a logger class that can log messages with different severity levels and styles, both in the terminal and to a file.

This library is ideal for developers who want to make their terminal outputs more organized and visually appealing. With `ultraprint`, you can quickly identify important information, warnings, errors, and other message types based on their color and style.

## Installation

To install `ultraprint`, simply use `pip`:

```bash
pip install ultraprint
```

## Basic Usage

### Color Functions

The `ultraprint` library provides functions to print text in various colors:

```python
import ultraprint.common as p

p.red("This is red text")
p.green("This is green text")
p.yellow("This is yellow text")
p.blue("This is blue text")
p.purple("This is purple text")
p.cyan("This is cyan text")
p.lgray("This is light gray text")
p.dgray("This is dark gray text")
```

### Text Style Functions

In addition to colors, you can apply styles like bold, underline, and negative:

```python
p.bold("This is bold text")
p.underline("This is underlined text")
p.negative("This is negative text")
```

### Background Color Functions

You can also change the background color of the text:

```python
p.red_bg("This is red background text")
p.green_bg("This is green background text")
p.yellow_bg("This is yellow background text")
p.blue_bg("This is blue background text")
p.purple_bg("This is purple background text")
p.cyan_bg("This is cyan background text")
p.lgray_bg("This is light gray background text")
p.dgray_bg("This is dark gray background text")
```

### Newline Function

For convenience, you can easily print new lines:

```python
p.n()  # Prints one new line

p.n(3)  # Prints three new lines
```

## Advanced Usage: Logging

### Logger Class

The `ultraprint` library includes an enhanced `logger` class for structured logging with different severity levels, customizable formats, log rotation, and optional extra contextual information (like the file name, function, and line number). Logs can be output both to the console and to a log file, with thread safety ensured for multi-threaded applications.

```python
from ultraprint.logging import logger

# Create a logger object with extra info enabled
log = logger('example_log', include_extra_info=True)

# Log some messages
log.info('This is an info message')
log.error('This is an error message')
log.warning('This is a warning message')
log.success('This is a success message')
log.debug('This is a debug message')
log.critical('This is a critical message')
```

### Logger Methods

The `logger` class provides the following methods:

- `info(msg)`: Logs an informational message (in cyan).
- `error(msg)`: Logs an error message (in red).
- `warning(msg)`: Logs a warning message (in yellow).
- `success(msg)`: Logs a success message (in green).
- `debug(msg)`: Logs a debug message (in dark gray).
- `critical(msg)`: Logs a critical message (with a red background).

Each method writes the log entry to both the console (using colored output) and to a log file named after the logger (e.g., `example_log.log`).

### Extra Information

The `logger` class allows you to include extra context, such as the filename, function name, and line number where the log message was called, using the `include_extra_info=True` flag. This is particularly useful for debugging.

```python
log = logger('detailed_log', include_extra_info=True)
log.info('Logging with extra information')
```

This will output something like:

```
[2024-09-29 12:34:56] [INFO] [detailed_log] Logging with extra information [script.py:my_function:42]
```

### Custom Filename for Logs

You can specify a custom filename for the log file by passing the `filename` argument when creating a logger object. If not provided, the default filename will be the name of the logger followed by `.log`.

```python
log = logger('custom_logger', filename='custom_log_file.log')
log.info('This will be logged in custom_log_file.log')
```

## Documentation

### Color Functions

These functions print the provided text in different colors:

- **red(*args)**: Prints text in red.
- **green(*args)**: Prints text in green.
- **yellow(*args)**: Prints text in yellow.
- **blue(*args)**: Prints text in blue.
- **purple(*args)**: Prints text in purple.
- **cyan(*args)**: Prints text in cyan.
- **lgray(*args)**: Prints text in light gray.
- **dgray(*args)**: Prints text in dark gray.

### Text Style Functions

These functions apply different styles to the text:

- **bold(*args)**: Prints bold text.
- **underline(*args)**: Prints underlined text.
- **negative(*args)**: Prints text with a negative style.

### Background Color Functions

These functions print the provided text with different background colors:

- **red_bg(*args)**: Prints text with a red background.
- **green_bg(*args)**: Prints text with a green background.
- **yellow_bg(*args)**: Prints text with a yellow background.
- **blue_bg(*args)**: Prints text with a blue background.
- **purple_bg(*args)**: Prints text with a purple background.
- **cyan_bg(*args)**: Prints text with a cyan background.
- **lgray_bg(*args)**: Prints text with a light gray background.
- **dgray_bg(*args)**: Prints text with a dark gray background.

### Logger Class

The `logger` class provides structured logging with timestamped entries and colored outputs. Each log method corresponds to a different severity level and prints in a specific color.

#### Logger Methods:

- **info(msg)**: Logs an informational message in cyan.
- **error(msg)**: Logs an error message in red.
- **warning(msg)**: Logs a warning message in yellow.
- **success(msg)**: Logs a success message in green.
- **debug(msg)**: Logs a debug message in dark gray.
- **critical(msg)**: Logs a critical message with a red background.

You can enable extra context (like the file name, function name, and line number) with `include_extra_info=True`.

#### Setting Log Level:

By default, the log level is set to `INFO`, which means that all log messages with a severity level of `INFO` or higher will be displayed. You can change the log level by calling the `set_log_level` method with one of the following options: `INFO`, `SUCCESS`, `WARNING`, `ERROR`, `CRITICAL`.

#### Setting Log File:

By default, logs are written to a file with the same name as the logger followed by `.log`. You can disable writing to a file by setting `write_to_file=False` when creating the logger object or by calling the `set_write_to_file` method. If you want to specify a custom filename, you can pass the `filename` argument when creating the logger object.

#### Custom Log Formats

You can customize the format of your log messages by providing the `log_format` parameter when creating a `logger` object. The default format is `[{time}] [{level}] [{name}] {message}`. You can include the following placeholders in your custom format:

- `{time}`: Timestamp of the log entry.
- `{level}`: Log level (e.g., INFO, ERROR).
- `{name}`: Name of the logger.
- `{message}`: The log message.
- `{extra_info}`: Extra context information if `include_extra_info` is `True`.

**Example:**

```python
log = logger('custom_format_log', log_format='[{time}] [{level}] {message} - {extra_info}', include_extra_info=True)
log.info('This is a custom formatted log message')
```

#### Exception Method

The `logger` class also provides an `exception` method to log exceptions with traceback information. This is useful for debugging purposes.

**Example:**

```python
try:
    1 / 0
except ZeroDivisionError as e:
    log.exception('An exception occurred')
```

This will log the exception message along with the traceback information.

## Examples

### Basic Color and Style Printing

```python
import ultraprint.common as p

p.red("This is red text")
p.bold("This is bold text")
p.red_bg("This is red background text")
```

### Using the Logger with Extra Information

```python
from ultraprint.logging import logger

log = logger('example_log', include_extra_info=True)
log.info('Starting the process...')
log.success('Process completed successfully!')
log.warning('This is a warning')
log.error('An error occurred')
log.critical('Critical failure, system shutting down!')
```

## Contributing

We welcome contributions to `ultraprint`! If you have suggestions, find a bug, or want to add a new feature, please open an issue or submit a pull request on GitHub.

            

Raw data

            {
    "_id": null,
    "home_page": "https://github.com/Kawai-Senpai/UltraPrint",
    "name": "ultraprint",
    "maintainer": null,
    "docs_url": null,
    "requires_python": null,
    "maintainer_email": null,
    "keywords": "Printing, Console, Formatting, Logging, Colored Output, Styled Text",
    "author": "Ranit Bhowmick",
    "author_email": "bhowmickranitking@duck.com",
    "download_url": "https://files.pythonhosted.org/packages/19/7b/2e7ed275c840294812e6ddafa4f52ddef89174da07cfc256716ce7583960/ultraprint-3.1.0.tar.gz",
    "platform": null,
    "description": "# `ultraprint` - A Python Library for Enhanced Terminal Output\r\n\r\nWelcome to `ultraprint`! This Python library is designed to enhance terminal output with colorful and styled text, making your console logs more readable and aesthetically pleasing developed by [*Ranit Bhowmick*](https://www.linkedin.com/in/ranitbhowmick/) & [*Sayanti Chatterjee*](https://www.linkedin.com/in/sayantichatterjee/). Whether you're building a command-line application, debugging code, or just want to add some flair to your terminal, `ultraprint` provides a simple and effective solution.\r\n\r\n## Table of Contents\r\n\r\n1. [Introduction](#introduction)\r\n2. [Installation](#installation)\r\n3. [Basic Usage](#basic-usage)\r\n   - [Color Functions](#color-functions)\r\n   - [Text Style Functions](#text-style-functions)\r\n   - [Background Color Functions](#background-color-functions)\r\n   - [Newline Function](#newline-function)\r\n4. [Advanced Usage: Logging](#advanced-usage-logging)\r\n   - [Logger Class](#logger-class)\r\n   - [Logger Methods](#logger-methods)\r\n5. [Documentation](#documentation)\r\n   - [Color Functions](#color-functions)\r\n   - [Text Style Functions](#text-style-functions)\r\n   - [Background Color Functions](#background-color-functions)\r\n   - [Logger Class](#logger-class)\r\n6. [Examples](#examples)\r\n7. [Contributing](#contributing)\r\n\r\n## Introduction\r\n\r\n`ultraprint` is a Python library that extends the capabilities of the standard `print` function. It allows you to easily print text in different colors, styles, and backgrounds in the terminal. Additionally, it includes a logger class that can log messages with different severity levels and styles, both in the terminal and to a file.\r\n\r\nThis library is ideal for developers who want to make their terminal outputs more organized and visually appealing. With `ultraprint`, you can quickly identify important information, warnings, errors, and other message types based on their color and style.\r\n\r\n## Installation\r\n\r\nTo install `ultraprint`, simply use `pip`:\r\n\r\n```bash\r\npip install ultraprint\r\n```\r\n\r\n## Basic Usage\r\n\r\n### Color Functions\r\n\r\nThe `ultraprint` library provides functions to print text in various colors:\r\n\r\n```python\r\nimport ultraprint.common as p\r\n\r\np.red(\"This is red text\")\r\np.green(\"This is green text\")\r\np.yellow(\"This is yellow text\")\r\np.blue(\"This is blue text\")\r\np.purple(\"This is purple text\")\r\np.cyan(\"This is cyan text\")\r\np.lgray(\"This is light gray text\")\r\np.dgray(\"This is dark gray text\")\r\n```\r\n\r\n### Text Style Functions\r\n\r\nIn addition to colors, you can apply styles like bold, underline, and negative:\r\n\r\n```python\r\np.bold(\"This is bold text\")\r\np.underline(\"This is underlined text\")\r\np.negative(\"This is negative text\")\r\n```\r\n\r\n### Background Color Functions\r\n\r\nYou can also change the background color of the text:\r\n\r\n```python\r\np.red_bg(\"This is red background text\")\r\np.green_bg(\"This is green background text\")\r\np.yellow_bg(\"This is yellow background text\")\r\np.blue_bg(\"This is blue background text\")\r\np.purple_bg(\"This is purple background text\")\r\np.cyan_bg(\"This is cyan background text\")\r\np.lgray_bg(\"This is light gray background text\")\r\np.dgray_bg(\"This is dark gray background text\")\r\n```\r\n\r\n### Newline Function\r\n\r\nFor convenience, you can easily print new lines:\r\n\r\n```python\r\np.n()  # Prints one new line\r\n\r\np.n(3)  # Prints three new lines\r\n```\r\n\r\n## Advanced Usage: Logging\r\n\r\n### Logger Class\r\n\r\nThe `ultraprint` library includes an enhanced `logger` class for structured logging with different severity levels, customizable formats, log rotation, and optional extra contextual information (like the file name, function, and line number). Logs can be output both to the console and to a log file, with thread safety ensured for multi-threaded applications.\r\n\r\n```python\r\nfrom ultraprint.logging import logger\r\n\r\n# Create a logger object with extra info enabled\r\nlog = logger('example_log', include_extra_info=True)\r\n\r\n# Log some messages\r\nlog.info('This is an info message')\r\nlog.error('This is an error message')\r\nlog.warning('This is a warning message')\r\nlog.success('This is a success message')\r\nlog.debug('This is a debug message')\r\nlog.critical('This is a critical message')\r\n```\r\n\r\n### Logger Methods\r\n\r\nThe `logger` class provides the following methods:\r\n\r\n- `info(msg)`: Logs an informational message (in cyan).\r\n- `error(msg)`: Logs an error message (in red).\r\n- `warning(msg)`: Logs a warning message (in yellow).\r\n- `success(msg)`: Logs a success message (in green).\r\n- `debug(msg)`: Logs a debug message (in dark gray).\r\n- `critical(msg)`: Logs a critical message (with a red background).\r\n\r\nEach method writes the log entry to both the console (using colored output) and to a log file named after the logger (e.g., `example_log.log`).\r\n\r\n### Extra Information\r\n\r\nThe `logger` class allows you to include extra context, such as the filename, function name, and line number where the log message was called, using the `include_extra_info=True` flag. This is particularly useful for debugging.\r\n\r\n```python\r\nlog = logger('detailed_log', include_extra_info=True)\r\nlog.info('Logging with extra information')\r\n```\r\n\r\nThis will output something like:\r\n\r\n```\r\n[2024-09-29 12:34:56] [INFO] [detailed_log] Logging with extra information [script.py:my_function:42]\r\n```\r\n\r\n### Custom Filename for Logs\r\n\r\nYou can specify a custom filename for the log file by passing the `filename` argument when creating a logger object. If not provided, the default filename will be the name of the logger followed by `.log`.\r\n\r\n```python\r\nlog = logger('custom_logger', filename='custom_log_file.log')\r\nlog.info('This will be logged in custom_log_file.log')\r\n```\r\n\r\n## Documentation\r\n\r\n### Color Functions\r\n\r\nThese functions print the provided text in different colors:\r\n\r\n- **red(*args)**: Prints text in red.\r\n- **green(*args)**: Prints text in green.\r\n- **yellow(*args)**: Prints text in yellow.\r\n- **blue(*args)**: Prints text in blue.\r\n- **purple(*args)**: Prints text in purple.\r\n- **cyan(*args)**: Prints text in cyan.\r\n- **lgray(*args)**: Prints text in light gray.\r\n- **dgray(*args)**: Prints text in dark gray.\r\n\r\n### Text Style Functions\r\n\r\nThese functions apply different styles to the text:\r\n\r\n- **bold(*args)**: Prints bold text.\r\n- **underline(*args)**: Prints underlined text.\r\n- **negative(*args)**: Prints text with a negative style.\r\n\r\n### Background Color Functions\r\n\r\nThese functions print the provided text with different background colors:\r\n\r\n- **red_bg(*args)**: Prints text with a red background.\r\n- **green_bg(*args)**: Prints text with a green background.\r\n- **yellow_bg(*args)**: Prints text with a yellow background.\r\n- **blue_bg(*args)**: Prints text with a blue background.\r\n- **purple_bg(*args)**: Prints text with a purple background.\r\n- **cyan_bg(*args)**: Prints text with a cyan background.\r\n- **lgray_bg(*args)**: Prints text with a light gray background.\r\n- **dgray_bg(*args)**: Prints text with a dark gray background.\r\n\r\n### Logger Class\r\n\r\nThe `logger` class provides structured logging with timestamped entries and colored outputs. Each log method corresponds to a different severity level and prints in a specific color.\r\n\r\n#### Logger Methods:\r\n\r\n- **info(msg)**: Logs an informational message in cyan.\r\n- **error(msg)**: Logs an error message in red.\r\n- **warning(msg)**: Logs a warning message in yellow.\r\n- **success(msg)**: Logs a success message in green.\r\n- **debug(msg)**: Logs a debug message in dark gray.\r\n- **critical(msg)**: Logs a critical message with a red background.\r\n\r\nYou can enable extra context (like the file name, function name, and line number) with `include_extra_info=True`.\r\n\r\n#### Setting Log Level:\r\n\r\nBy default, the log level is set to `INFO`, which means that all log messages with a severity level of `INFO` or higher will be displayed. You can change the log level by calling the `set_log_level` method with one of the following options: `INFO`, `SUCCESS`, `WARNING`, `ERROR`, `CRITICAL`.\r\n\r\n#### Setting Log File:\r\n\r\nBy default, logs are written to a file with the same name as the logger followed by `.log`. You can disable writing to a file by setting `write_to_file=False` when creating the logger object or by calling the `set_write_to_file` method. If you want to specify a custom filename, you can pass the `filename` argument when creating the logger object.\r\n\r\n#### Custom Log Formats\r\n\r\nYou can customize the format of your log messages by providing the `log_format` parameter when creating a `logger` object. The default format is `[{time}] [{level}] [{name}] {message}`. You can include the following placeholders in your custom format:\r\n\r\n- `{time}`: Timestamp of the log entry.\r\n- `{level}`: Log level (e.g., INFO, ERROR).\r\n- `{name}`: Name of the logger.\r\n- `{message}`: The log message.\r\n- `{extra_info}`: Extra context information if `include_extra_info` is `True`.\r\n\r\n**Example:**\r\n\r\n```python\r\nlog = logger('custom_format_log', log_format='[{time}] [{level}] {message} - {extra_info}', include_extra_info=True)\r\nlog.info('This is a custom formatted log message')\r\n```\r\n\r\n#### Exception Method\r\n\r\nThe `logger` class also provides an `exception` method to log exceptions with traceback information. This is useful for debugging purposes.\r\n\r\n**Example:**\r\n\r\n```python\r\ntry:\r\n    1 / 0\r\nexcept ZeroDivisionError as e:\r\n    log.exception('An exception occurred')\r\n```\r\n\r\nThis will log the exception message along with the traceback information.\r\n\r\n## Examples\r\n\r\n### Basic Color and Style Printing\r\n\r\n```python\r\nimport ultraprint.common as p\r\n\r\np.red(\"This is red text\")\r\np.bold(\"This is bold text\")\r\np.red_bg(\"This is red background text\")\r\n```\r\n\r\n### Using the Logger with Extra Information\r\n\r\n```python\r\nfrom ultraprint.logging import logger\r\n\r\nlog = logger('example_log', include_extra_info=True)\r\nlog.info('Starting the process...')\r\nlog.success('Process completed successfully!')\r\nlog.warning('This is a warning')\r\nlog.error('An error occurred')\r\nlog.critical('Critical failure, system shutting down!')\r\n```\r\n\r\n## Contributing\r\n\r\nWe welcome contributions to `ultraprint`! If you have suggestions, find a bug, or want to add a new feature, please open an issue or submit a pull request on GitHub.\r\n",
    "bugtrack_url": null,
    "license": "MIT License with attribution requirement",
    "summary": "Ultraprint is a versatile Python library that enhances your command-line output with colorful text, styled formatting, and easy-to-use logging utilities. Perfect for creating visually appealing console applications.",
    "version": "3.1.0",
    "project_urls": {
        "Download": "https://github.com/Kawai-Senpai/UltraPrint",
        "Homepage": "https://github.com/Kawai-Senpai/UltraPrint"
    },
    "split_keywords": [
        "printing",
        " console",
        " formatting",
        " logging",
        " colored output",
        " styled text"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "278b75b2de2967a9bef6e76b077f48de35ebff0a3a36b7cb164bd6c8ee6f2d4d",
                "md5": "29e45ddc695f8ec6ea5e910ec57d310b",
                "sha256": "fe149fc9507bbd3844d299dfc3e88b0ac230752c70bdc4ef1f6a79efe92b0450"
            },
            "downloads": -1,
            "filename": "ultraprint-3.1.0-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "29e45ddc695f8ec6ea5e910ec57d310b",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": null,
            "size": 7313,
            "upload_time": "2024-11-12T16:55:49",
            "upload_time_iso_8601": "2024-11-12T16:55:49.444410Z",
            "url": "https://files.pythonhosted.org/packages/27/8b/75b2de2967a9bef6e76b077f48de35ebff0a3a36b7cb164bd6c8ee6f2d4d/ultraprint-3.1.0-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "197b2e7ed275c840294812e6ddafa4f52ddef89174da07cfc256716ce7583960",
                "md5": "a532af013d9827bc48c36ceec815f0c1",
                "sha256": "27f2ce92fb39fc0092271291331bac970624beade8837539cc05da52b9d2790d"
            },
            "downloads": -1,
            "filename": "ultraprint-3.1.0.tar.gz",
            "has_sig": false,
            "md5_digest": "a532af013d9827bc48c36ceec815f0c1",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": null,
            "size": 10774,
            "upload_time": "2024-11-12T16:55:51",
            "upload_time_iso_8601": "2024-11-12T16:55:51.147725Z",
            "url": "https://files.pythonhosted.org/packages/19/7b/2e7ed275c840294812e6ddafa4f52ddef89174da07cfc256716ce7583960/ultraprint-3.1.0.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2024-11-12 16:55:51",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "Kawai-Senpai",
    "github_project": "UltraPrint",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": false,
    "lcname": "ultraprint"
}
        
Elapsed time: 0.37164s