Skip to main content

A simple logger which supports for logging stdout and stderr streams to console, file, and Loggly for Python

Project description

# LogOne

![Logone status](https://img.shields.io/pypi/v/logone.svg)

A simple logger which supports for logging stdout and stderr streams to console, file, and Loggly for Python

## Core Features

+ Simple and easy to use, and also compatible with `logging` package

+ Supports for logging to console, file, and [Loggly](https://www.loggly.com) service in real-time

+ Redirects stdout or stderr stream to the logger as log messages

+ Supports for color and formatting to terminal logging (based on `coloredlogs` package)

+ Works with Python 2 and 3

## Todo

+ [ ] Supports for forwarding logs to Facebook Messenger, Slack, ...

## Installation

`logone` can be installed using [pip](http://www.pip-installer.org):

```
$ [sudo] pip install logone
```

## Example Usage

Here is an example of how easy it is to get started:

```python
#!/usr/bin/python
# -*- coding: utf-8 -*-
import logone

# Indicate `DEBUG` level (or higher) for the root logger
logone.set_level(level=logone.DEBUG)

# Now, we can log anything to the root logger
logone.debug('Quick zephyrs blow, vexing daft Jim')
logone.info('How quickly daft jumping zebras vex')


def main():
# Create a new logger if you do not want to use the root logger
logger = logone.get_logger('example')
logger.set_level(logone.DEBUG)

# Log something to the logger
logger.debug('Debug message')
logger.info('Info message')
logger.warning('Warn message')

# Set up the logger for logging `DEBUG` messages or higher to `example.log` file
# Learn more at: https://docs.python.org/3/library/logging.handlers.html#logging.handlers.TimedRotatingFileHandler
logger.use_file(enabled=True, file_name='logs/example.log', level=logone.DEBUG,
when='d', interval=1, backup_count=10)

# Set up the logger for logging `DEBUG` messages or higher to Loggly service in real-time
logger.use_loggly(enabled=True, level=logone.DEBUG,
loggly_token='YOUR-CUSTOMER-TOKEN', loggly_tag='Python,Example')

# Log something to the logger, file, and Loggly service
logger.error('Error message')
logger.critical('Critical message')

# Redirect stdout stream to the logger as `INFO` messages (for `print` function,...)
logger.redirect_stdout(enabled=True, log_level=logone.INFO)
# Redirect stderr stream to the logger as `ERROR` messages (for unexpected error,...)
logger.redirect_stderr(enabled=True, log_level=logone.ERROR)

# These will be written to stdout stream and then redirected to the logger
print('Jackdaws love my big sphinx of quartz')

value = 20
print('Value = ', value)

# ZeroDivisionError exception will be written to stderr stream and then redirected to the logger
value = 1 / 0
print(value)


if __name__ == '__main__':
main()
```

And here is terminal output:

![Demo](https://raw.githubusercontent.com/dnanhkhoa/logone/master/screenshots/demo.png)

## License

MIT

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

logone-0.1.7.tar.gz (7.3 kB view details)

Uploaded Source

File details

Details for the file logone-0.1.7.tar.gz.

File metadata

  • Download URL: logone-0.1.7.tar.gz
  • Upload date:
  • Size: 7.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No

File hashes

Hashes for logone-0.1.7.tar.gz
Algorithm Hash digest
SHA256 512c8828dfd8dd39e8adadc0e9cbc2836a86c936261c2d36a7efd82e3680675c
MD5 a0b7815c075f970d44644abb2c33e7e4
BLAKE2b-256 397d69f5e5cdaa2b3c1bc146fc61617a6cc004b3a7890850c5df4facf82399d3

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page