Skip to main content

Easy logging to console or rotating file or socket for Python 3.

Project description

## ylog

[![License](https://img.shields.io/badge/License-MIT-red.svg)]()
[![OS](https://img.shields.io/badge/OS-MacOS%2C%20Linux-brightgreen.svg)]()
[![Python](https://img.shields.io/badge/Python-3.6.5-blue.svg)]()
[![Pypi](https://img.shields.io/pypi/wheel/Django.svg)]()
[![version](https://img.shields.io/badge/Version-0.0.2-yellow.svg)]()

Simple and effective logging for Python 3, easy logging to console or rotating file or socket

### Install

```bash
pip install ylog
```

### Example Usage

```bash
# Default Stream or File Handler Format Is:
'[%(asctime)s %(name)s %(module)s:%(lineno)d %(levelname)s] %(message)s'

# Default Socket Handler Format Is:
'[%(asctime)s %(ip)s:%(name)s %(module)s:%(lineno)d %(levelname)s] %(message)s'

# Default Date Format Is:
'%Y-%m-%d %H:%M:%S'
```

#### 1. Stream Logger

```bash
import ylog

logger = ylog.getConsoleLogger('loggerName')

logger.info('Hello')

# show
[2018-06-07 12:50:35 ylog <stdin>:1 INFO] The StreamHandler is working
```

#### 2. File Logger

Rotating log files by date and size:

- If the file size is reached (default 100M) but the split date is not reached, then the existing log file (for example, app.log) is backed up as app.log.x( x from 1 to n).

- If the split date is reached, rename all log files (including app.log.x) with a timestamp. For example, app.log-1979-02-19-13:33:16.1

```bash
import ylog

logger = ylog.getFileLogger('./demo.log')

logger.info('The fileHandler is working, no logger name')

# show
[2018-06-07 12:56:29 ylog <stdin>:1 INFO] The fileHandler is working, no logger name

# ---------------------- #

logger2 = ylog.getFileLogger('./demo.log', loggerName='demoLogger', size=200, date='y')

logger2.info('Files will be split after reaching 200M and 1 year')

# show
[2018-06-07 13:00:24 demoLogger <stdin>:1 INFO] Files will be split after reaching 200M and 1 year
```

#### 3. Socket Logger

> ylog SocketHandler is mainly used with `pylogserver`. When pylogserver is available, logs are sent to pylogserver in real time. When pylogserver is not available, logs are cached locally and automatically sent when communication is restored.

_Visit [pylogserver](https://github.com/yingsf/pylogserver) for more details on pylogserver_

When loggerName contains `||`, pylogserver will use the characters before `||` as the directory name, and the characters after `||` as the log file name. The following is the location of the log file on the pylogserver server.

```bash
import ylog

# './buff' is the local log cache directory
logger = ylog.getSocketLogger('ylog||test', '127.0.0.1', 7000, './buff')

logger.info('Send log to pylogserver')

$ tree
.
└── ylog
└── test.log

$ cat test.log

[2018-06-07 13:16:04 61.180.150.242:test <stdin>:1 INFO] Send log to pylogserver
```


Project details


Download files

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

Files for ylog, version 0.0.3
Filename, size File type Python version Upload date Hashes
Filename, size ylog-0.0.3-py3-none-any.whl (8.2 kB) File type Wheel Python version 3.6 Upload date Hashes View
Filename, size ylog-0.0.3.tar.gz (9.7 kB) File type Source Python version None Upload date Hashes View

Supported by

Pingdom Pingdom Monitoring Google Google Object Storage and Download Analytics Sentry Sentry Error logging AWS AWS Cloud computing DataDog DataDog Monitoring Fastly Fastly CDN DigiCert DigiCert EV certificate StatusPage StatusPage Status page