Logme - Python Logging for Humans¶
Logme is a Python package that makes logging simple and robust. If you have found logging in Python not so straight forward, download this package and give it a try! :)
V1.3.0 Updates¶
logme.ini
file now supports custom datefmt
and style
! Thanks to @afunTW suggestion! :)
Here is an example of how you can specify these parameters in your logme.ini
configuration:
[my_config]
level = DEBUG
formatter =
fmt: {asctime} - {name} - {levelname} - {message}
datefmt: %Y/%m/%d
style: {
stream =
type: StreamHandler
active: True
level: DEBUG
file =
type: FileHandler
active: True
level: DEBUG
formatter: {name} :: {funcName} :: {levelname} :: {message}
filename: mylogpath/foo.log
Note
Only top level master_formatter supports parameters as shown above, individual handler formatter will not.
Terminal Color Output¶
logme supports color and styling output in the terminal!
The colors and style is customizable in logme.ini
, here is a screenshot of how it looks like in the terminal:
To use color output in logme, make sure your logme package and logme.ini
is up-to-date if you are using a version before 1.2.0.
Check the configuration details here.
In a Nutshell¶
If you have a function you want to log, you can do this in your python file:
import logme
@logme.log
def my_awesome_function(my_arg, logger=None):
logger.info('this is my log message')
"""rest of the function"""
You can do the same with classes too:
import logme
@logme.log
class MyAwesomeClass:
def my_function(self, my_arg):
self.logger.info('this is my log message')
pretty nice right? :)
Version Upgrades¶
For all versioning changes, your logme.ini
file should also be changed for the new features to take place in your project.
logme
package makes the upgrading of versions simple with only two steps:
I. Upgrade to latest version of Logme:¶
Ensure you tag the latest version of logme in your pipfile, then do
$ pipenv install logme
II. Upgrade logme.ini
using the following command:¶
$ logme upgrade
Note
Each newer version is backwards compatible, so if you still have the previous version of logme.ini
without upgrading, you will not be affected.