All Projects → keitheis → alog

keitheis / alog

Licence: other
Update: use loguru instead. Simple straight logging your Python code

Programming Languages

python
139335 projects - #7 most used programming language

Projects that are alternatives of or similar to alog

objprint
A library that can print Python objects in human readable format
Stars: ✭ 141 (+271.05%)
Mutual labels:  debug, print
consono
The most correct, informative, appealing and configurable variable inspector for JavaScript
Stars: ✭ 17 (-55.26%)
Mutual labels:  debug, print
pydbg
Python implementation of the Rust `dbg` macro
Stars: ✭ 85 (+123.68%)
Mutual labels:  debug, print
Beeprint
make your debug printing more friendly
Stars: ✭ 348 (+815.79%)
Mutual labels:  debug, print
Godbg
Go implementation of the Rust `dbg` macro
Stars: ✭ 172 (+352.63%)
Mutual labels:  debug, print
Icecream Cpp
🍦 Never use cout/printf to debug again
Stars: ✭ 225 (+492.11%)
Mutual labels:  debug, print
Icecream
🍦 Never use print() to debug again.
Stars: ✭ 5,601 (+14639.47%)
Mutual labels:  debug, print
sendmessage
SendMessage is a little tool to send Windows messages to any window.
Stars: ✭ 93 (+144.74%)
Mutual labels:  helper, debug
Old
每天大红包 · 旧版(不再维护,仅供参考)
Stars: ✭ 1,611 (+4139.47%)
Mutual labels:  helper
Tinyconsole
📱💬🚦 TinyConsole is a micro-console that can help you log and display information inside an iOS application, where having a connection to a development computer is not possible.
Stars: ✭ 1,929 (+4976.32%)
Mutual labels:  helper
Vivify
Vivify is free CSS animation library.
Stars: ✭ 1,651 (+4244.74%)
Mutual labels:  helper
Box
Python dictionaries with advanced dot notation access
Stars: ✭ 1,804 (+4647.37%)
Mutual labels:  helper
Dynamicswebapi
DynamicsWebApi is a Microsoft Dynamics 365 / Microsoft Dataverse (formerly known as Common Data Service) Web API helper library for JavaScript
Stars: ✭ 165 (+334.21%)
Mutual labels:  helper
Idapyhelper
IDAPyHelper is a script for the Interactive Disassembler that helps writing IDAPython scripts and plugins.
Stars: ✭ 128 (+236.84%)
Mutual labels:  helper
Jd Helper
🐑 京东日常小助手, 省时省力, 京东萌宠, 免费水果 [暂停更新]
Stars: ✭ 199 (+423.68%)
Mutual labels:  helper
React Native Keyboard Spacer
Plug and play react-native keyboard spacer view.
Stars: ✭ 1,475 (+3781.58%)
Mutual labels:  helper
Weixin
微信小游戏辅助合集(加减大师、包你懂我、大家来找茬腾讯版、头脑王者、好友画我、悦动音符、我最在行、星途WeGoing、猜画小歌、知乎答题王、腾讯中国象棋、跳一跳、题多多黄金版)
Stars: ✭ 1,216 (+3100%)
Mutual labels:  helper
debugging
Improve your Print Debugging
Stars: ✭ 41 (+7.89%)
Mutual labels:  print
Loco Answers
Open Source Android App for answers in TRIVIA GAMES
Stars: ✭ 180 (+373.68%)
Mutual labels:  helper
Has Parameters
A trait that allows you to pass arguments to Laravel middleware in a more PHP'ish way.
Stars: ✭ 149 (+292.11%)
Mutual labels:  helper

Alog

https://travis-ci.com/keitheis/alog.svg?branch=master http://img.shields.io/pypi/v/alog.svg?style=flat

Your goto Python logging without panic on context swtich.

Warning: No more logger = logging.getLogger(__name__) in your every file.

>>> import alog
>>> alog.info("Hi.")
2016-12-18 20:44:30 INFO  <stdin> Hi.
>>> def test():
...     alog.info("Test 1")
...     alog.error("Test 2")
...
>>> test()
2016-12-18 20:45:19 INFO  <stdin:2> Test 1
2016-12-18 20:45:19 ERROR <stdin:3> Test 2
>>> alog.set_level("ERROR")
>>> test()
2016-12-18 20:45:41 ERROR <stdin:3> Test 2

If you're new to logging, see Why should you use logging instead of print.

Installation

pip install alog

Features

  • Instant logging with expected defaults.

    You can do logging instantly by reading a small piece of README. Alog comes with useful defaults:

    • A default logger.

    • Logging level: logging.INFO

    • Logging format:

      "%(asctime)s %(levelname)-5.5s [parent_module.current_module:%(lineno)s]%(message)s",
      "%Y-%m-%d %H:%M:%S"
      
  • No more __name__ whenever you start to do logging in a module.

    Alog builds the default module names on the fly.

  • Compatible with default Python logging module.

    Alog is built upon default Python logging module. You can configure it by the same way of default Python logging module when it's needed.

Comparing alog with Python default logging module

Comparing alog :

In [1]: import alog

In [2]: alog.info("Hello alog!")
2016-11-23 12:20:34 INFO  <IPython> Hello alog!

with logging module:

In [1]: import logging

In [2]: logging.basicConfig(
   ...:     level=logging.INFO,
   ...:     format="%(asctime)s %(levelname)-5.5s "
   ...:            "[%(name)s:%(lineno)s] %(message)s")

In [3]: # In every file you want to do log, otherwise %(names)s won't work.
In [4]: logger = logging.getLogger(__name__)

In [5]: logger.info("Hello log!")
2016-11-23 12:16:30 INFO  [__main__:1] Hello log!

Tips

import alog

a_complex_json_dict = {...}  # or a_complex_dict
alog.info(alog.pformat(a_complex_dict))

restaurant = Restaurant(...)
alog.info(alog.pdir(restaurant))
# or just skip attributes starts with "__":
alog.info(alog.pdir(restaurant, str_not_startswith="__"))
# instead of
alog.info([attr for attr in dir(restaurant) if attr.startswith("_")])

# Play threads?
alog.turn_logging_thread_name(on=True)
# Processes?
alog.turn_logging_process_id(on=True)
# No datetime wanted?
alog.turn_logging_datetime(on=False)

Why should you use logging instead of print

The main goal of logging is to figure out what was going on and to get the insight. print, by default, does simply pure string output. No timestamp, no module hint, and no level control, comparing to a pretty logging record.

Lets start with aproject/models/user.py :

class User:
    def __init__(self, user_id, username):
        ...
        print(username)
        ...

What you got output of print :

>>> admin = User(1, "admin")
"admin"

Now use alog :

import alog

class User:
    def __init__(self, user_id, username):
        ...
        alog.info(username)
        ...

What you got output of alog.info :

>>> admin = User(1, "admin")
2016-11-23 11:32:58 INFO  [models.user:6] admin

In the output of hundreds of lines, it helps (a lot).

What if you have used print a log? That's as easy:

import alog

print = alog.info

... # A lot of print code no needed to change
Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].