A simple asynchronous logging module.


Keywords
Moca, asynchronous log logging, async, logging, sanic, uvloop
License
OpenSSL
Install
pip install moca-log==0.2.4

Documentation

MocaLog --- A simple asynchronous logging module

MocaLog is a asynchronous logging module that use aiomysql, aiofiles, aiosqlite. MocaLog is designed for asynchronous web frameworks, such as Sanic.

life is short - you need Python!

Documents

System requirements

  • Python >= 3.7
  • aiofiles
  • aiomysql
  • aiosqlite
  • pymysql==0.9.2
  • uvloop(optional)

If uvloop module is available MocaLog will try use uvloop.
uvloop don't support windows systems.

Installation

pip3 install moca_log

Example

from moca_log import *
from asyncio import get_event_loop

# At first you need to create a driver.
file_driver = FileDriver('./tmp.log')
# or
mysql_driver = MySQLDriver(host='127.0.0.1', port=3306, user='root', password='mochimochi', db='moca_system')
# or 
sqlite_driver = SQLiteDriver('./log.db')

# Next step is create the instance of MocaLog.
moca_log = MocaLog(file_driver, LogLevel.INFO)  #  only save the logs that is same to INFO or higher than INFO.

# MocaLog needs to run on an asynchronous event loop.
loop = get_event_loop()

# Save the logs
loop.run_until_complete(moca_log.save('This is a test message.', moca_log.ERROR))
# or
loop.run_until_complete(moca_log.save('This is a test message.', LogLevel.ERROR))
# output
# [ERROR] (2020-03-31 23:21:08.956751) <MocaLog.py|insert_log|103|50641|4480896448> This is a test message.
# [log level] (current time) <file name | caller name | line number | process ID | thread ID > log message.

# Get logs
logs: List[str] = loop.run_until_complete(moca_log.read_logs())

# Add handler
def error_event(message, *args, **kwargs):
    print('Some error occurred!!')
    print(message)
moca_log.add_handler(moca_log.ERROR, error_event)
# when you save the log wiht ERROR level, the error_event will be called.

LICENSE (MIT)

MIT License

Copyright 2020.1.17 <el.ideal-ideas: https://www.el-ideal-ideas.com>

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

Links