2016-03-24 06:19:45 +00:00
|
|
|
# sanelogging
|
|
|
|
|
2016-03-24 06:38:42 +00:00
|
|
|
## Sane Defaults for Python Logging
|
2016-03-24 06:19:45 +00:00
|
|
|
|
|
|
|
The python stdlib `logging` module is useful, flexible, and configurable.
|
|
|
|
|
2016-03-24 06:41:24 +00:00
|
|
|
However, the maintainers have (quite reasonably) determined that python is
|
|
|
|
an application runtime and not an application. The default configuration
|
2016-03-24 06:38:42 +00:00
|
|
|
for the `logging` is thus not very useful, and this commonly results in
|
|
|
|
boilerplate in your own programs.
|
2016-03-24 06:19:45 +00:00
|
|
|
|
|
|
|
This is an opinionated module for the 90% case where you just want sane
|
2016-03-24 06:38:42 +00:00
|
|
|
defaults without that boilerplate. (In effect, moving it into PyPI.)
|
2016-03-24 06:19:45 +00:00
|
|
|
|
2016-03-24 06:38:42 +00:00
|
|
|
# It Also Does Some Other Stuff
|
2016-03-24 06:19:45 +00:00
|
|
|
|
2016-03-24 06:38:42 +00:00
|
|
|
* There are some convenience methods added, such as `panic` and `die` (c.f.
|
|
|
|
golang and perl).
|
2016-03-24 06:19:45 +00:00
|
|
|
|
2016-03-24 06:38:42 +00:00
|
|
|
* `notice` is aliased to `info`, for those who forget that python
|
|
|
|
doesn't have a notice level (i.e. me).
|
2016-03-24 06:19:45 +00:00
|
|
|
|
2016-03-24 06:48:29 +00:00
|
|
|
* If you set the environment variable `LOG_TO_SYSLOG` to something,
|
|
|
|
it will print out your log messages on paper and mail them to you.
|
2016-03-24 06:38:42 +00:00
|
|
|
|
|
|
|
* If stdout is a tty, log messages will be color-coded using the `colorlog`
|
|
|
|
module.
|
2016-03-24 06:19:45 +00:00
|
|
|
|
|
|
|
# Usage
|
|
|
|
|
2016-03-24 06:33:35 +00:00
|
|
|
```python
|
|
|
|
|
2016-03-24 06:19:45 +00:00
|
|
|
from sanelogging import log
|
|
|
|
|
|
|
|
log.info("starting up!")
|
|
|
|
|
|
|
|
log.error("something went wrong.")
|
|
|
|
|
2016-03-24 06:33:35 +00:00
|
|
|
log.die("bailing out") # exits
|
2016-03-24 06:47:15 +00:00
|
|
|
|
2016-03-24 06:48:29 +00:00
|
|
|
print "no soup for you." # never reached
|
2016-03-24 06:47:15 +00:00
|
|
|
|
2016-03-24 06:19:45 +00:00
|
|
|
```
|
|
|
|
|
2018-01-16 20:04:04 +00:00
|
|
|
![example output](https://raw.githubusercontent.com/sneak/sanelogging/master/example/example.png)
|
2016-03-24 06:39:34 +00:00
|
|
|
|
2016-03-24 06:19:45 +00:00
|
|
|
Author
|
|
|
|
======
|
|
|
|
|
2016-03-24 06:46:00 +00:00
|
|
|
Jeffrey Paul <sneak@sneak.berlin>
|
2016-03-24 06:33:35 +00:00
|
|
|
|
|
|
|
https://sneak.berlin
|
2016-03-24 06:19:45 +00:00
|
|
|
|
2016-03-24 06:33:35 +00:00
|
|
|
[@sneakdotberlin](https://twitter.com/sneakdotberlin)
|
2016-03-24 06:19:45 +00:00
|
|
|
|
2016-03-24 06:33:35 +00:00
|
|
|
`5539 AD00 DE4C 42F3 AFE1 1575 0524 43F4 DF2A 55C2`
|
2016-03-24 06:19:45 +00:00
|
|
|
|
|
|
|
License
|
|
|
|
=======
|
|
|
|
|
|
|
|
This code is released into the public domain.
|