Logging objects for Python apps.
Project description
Stutter is my own idea for a simple logging lib. Objects in the package handle timestamps and logging to files automatically. Logging to files can be buffered, and even threaded, according to your application’s needs.
Note that it may be possible to use the BufferedReader object with twisted to eliminate the need for threading. I may create such an object in future.
Brief example
Use objects from this package if you want to log messages. I intend to use this in a bot, and possibly a client, for the deviantART chat network. Logging can be done as follows:
from stutter import logging logger = logging.BaseLogger() logger.message('Sup homie?') logger.message('Everything is saved to files in `./log` by default') logger.message('You can change this somehow... I'll explain later.') logger.debug('This message won't be printed on-screen, but will be saved.')
Buffered logging
File IO can be expensive sometimes, so you can use the BufferedLogger object to determine when messages should be saved to files. When a BufferedLogger is used to display log messages on screen, the messages are displayed instantly, but they not saved to any files until .push() is used:
import time from stutter import logging logger = logging.BufferedLogger() logger.message('Some boring message...') time.sleep(5) # You can use the time you have to confirm that no logs have been written # yet, if you like. These are really trivial examples... logger.warning('Writing logs!') logger.push()
Note that .push() will only save up to 5 messages at a time. You can change this by telling push how many messages to save using the limit parameter. For example, to save up to 10 messages, you would call .push(limit=10). To push all stored messages to log files, call .push(limit=0).
Threaded logging
If you want to automate calls to push without having to really think about it too much, you can use the ThreadedLogger object. A brief and naive example:
from stutter import logging logger = logging.ThreadedLogger() # Start pushing in a thread. logger.start() logger.message('Your mother smells of elderberries.') # Stop the threading stuff. logger.stop() # Wait until the thread has actually stopped. logger.join() # Make sure all log messages have been saved. # This is not done by stopping the thread! logger.push(0)
Documentation
I will write documentation when I can be arsed.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distributions
File details
Details for the file stutter-1.1.zip
.
File metadata
- Download URL: stutter-1.1.zip
- Upload date:
- Size: 10.9 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | ab53c51b108da054bae61090a3009f068544e64de02224a71ee834b8366908fe |
|
MD5 | 52ede8460ec05d387e63b278e6e20a03 |
|
BLAKE2b-256 | 4e84026586e02add20607080830f3d64f99c773731f559bdf4bcd79a0801a467 |
File details
Details for the file stutter-1.1.tar.gz
.
File metadata
- Download URL: stutter-1.1.tar.gz
- Upload date:
- Size: 6.4 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 87105fbbe89df1f692ca3ac6a3b293eb7c9561bf0f29056a91a154cde7601d5c |
|
MD5 | 87850cb4380fe6396bec7d1111d97e46 |
|
BLAKE2b-256 | 9d8596de24015f13cb71350b5ba08b06cd37d299408cf2e353c676d6c081dbf7 |