Git Product home page Git Product logo

stutter's Introduction

Stutter

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.

stutter's People

Stargazers

photofroggy avatar

Watchers

photofroggy avatar James Cloos avatar

stutter's Issues

Database Logging

Should be possible to log to databases of different types.

The library needs to be redesigned a little for this to work smoothly.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.