Skip to main content

Amos Logger

Project description

Amos logger

For easier use of Log

1. Write logs to different directories

Usage

import logging
from AmosLogger.AmosLogger import AmosLogger

if __name__ == '__main__':
    amos_info_logger = AmosLogger(name='TestLog')
    amos_info_logger.set_logger()
    amos_info_logger.info('Test')

    amos_warn_logger = AmosLogger(name='TestLog')
    amos_warn_logger.set_logger(log_level=logging.WARN)
    amos_warn_logger.warning('Test')

    amos_error_logger = AmosLogger(name='TestLog')
    amos_error_logger.set_logger(log_level=logging.ERROR)
    amos_error_logger.error('Test')
/var/log/TestLog # ls
ERROR  INFO  WARNING

/var/log/TestLog/ERROR # ls
TestLog  TestLog.2023-08-25.log

/var/log/TestLog/ERROR # tailf TestLog
[2023-08-28 09:09:10,127][7335][ERROR]-(main.py:16) - Test
[2023-08-28 09:09:15,128][7389][ERROR]-(main.py:16) - Test
[2023-08-28 09:10:04,423][7770][ERROR]-(main.py:16) - Test
[2023-08-28 09:23:07,312][10550][ERROR]-(main.py:16) - Test

2. Write all logs to the same file

Usage

from AmosLogger.AmosLogger import AmosLogger

if __name__ == '__main__':
    amos_all_in_one_logger = AmosLogger(name='Test_Log')
    amos_log = amos_all_in_one_logger.set_all_in_one_logger()["logger"]
    amos_log.info("Info log")
    amos_log.warning("Warning log")
    amos_log.error("Error log")
/var/log/Test_Log # tailf Test_Log
[2023-08-28 09:23:07,312][10550][INFO]-(main.py:20) - Info log
[2023-08-28 09:23:07,312][10550][WARNING]-(main.py:21) - Warning log
[2023-08-28 09:23:07,312][10550][ERROR]-(main.py:22) - Error log

3. Flask Usage

from flask import Flask, Blueprint
from AmosLogger.AmosLogger import AmosLogger

amos_all_in_one_logger = AmosLogger(name='Flask_APP_Log')
amos_handler = amos_all_in_one_logger.set_all_in_one_logger()["handler"]
app = Flask(__name__)

app.logger.addHandler(amos_handler)

my_blueprint = Blueprint('my_blueprint', __name__)

@my_blueprint.route('/')
def index():
    # 在蓝图中使用日志记录器
    app.logger.info('Index page accessed')
    return 'Hello, World!'

# 将蓝图注册到应用程序中
app.register_blueprint(my_blueprint)

if __name__ == '__main__':
    app.run()

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

AmosLogger-0.0.3.tar.gz (2.7 kB view details)

Uploaded Source

Built Distribution

AmosLogger-0.0.3-py3-none-any.whl (3.4 kB view details)

Uploaded Python 3

File details

Details for the file AmosLogger-0.0.3.tar.gz.

File metadata

  • Download URL: AmosLogger-0.0.3.tar.gz
  • Upload date:
  • Size: 2.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.9.18

File hashes

Hashes for AmosLogger-0.0.3.tar.gz
Algorithm Hash digest
SHA256 6212b639cf26c54e20643f8a3ab4a6bfe1c2f30af45b05e2dfd29e78fd9394b4
MD5 06454fe098ae05743325788cc17510ed
BLAKE2b-256 f5b245d909b6f79c7ba27c674160d87152a414fd1f9b7367cfbff34c5af1ab15

See more details on using hashes here.

File details

Details for the file AmosLogger-0.0.3-py3-none-any.whl.

File metadata

  • Download URL: AmosLogger-0.0.3-py3-none-any.whl
  • Upload date:
  • Size: 3.4 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.9.18

File hashes

Hashes for AmosLogger-0.0.3-py3-none-any.whl
Algorithm Hash digest
SHA256 0723a669533120ba8f15ae3960b1177238d99f259f73ec79c320f4cbcb78ee1d
MD5 be0a8d512a18a8d0722b2495d1b691f1
BLAKE2b-256 684a3d71713d873076a709256d534119b96aef0f067195f8686049589c3be91a

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