<commit_before># Lggr - easy python logging

Have you ever tried to do anything with the python logging module?

I have. I didn't like it at all. The API was very confusing. Instead of dealing with all of its intricacies, I decided to roll my own.

# How does it work?

Here's an example of adding lggr to an application.

```python
import lggr
logger = lggr.Lggr() # create a logging object

logger.addMethod(lggr.INFO, lggr.Printer()) # log all info() calls to STDOUT
logger.addMethod(lggr.CRITICAL, lggr.FilePrinter("output.log")) # log all critical() calls to an output file
logger.addMethod(None, lggr.ErrorPrinter()) # log all logging calls to STDERR

logger.info("Here is a low level warning. It will be written to STDOUT and STDERR")
logger.warning("This is a warning. It is written to STDERR.")
logger.critical("This message will show up on STDERR and also in the \"output.log\" file")

# did I mention that it does arbitrary string.format()ing? yeah.
logger.info("{noun} is so {adjective}, I'd {verb} its {pl_noun}",
			noun="lggr", adjective="cool", verb="test", pl_noun="functions")

logger.warning("WARNING: {} is a {}. You should know this", lggr.Lggr, type(lggr.Lggr))

logger.clearMethods(lggr.CRITICAL) # remove all methods from a specific level

logger.close() # stop logging
```

`lggr.Printer`, `lggr.ErrorPrinter`, and `lggr.FilePrinter` (as well as `lggr.SocketWriter` and `lggr.Emailer`) are all built-in logging functions that log to STDOUT, STDERR, and a specified file (as well as a host/socket and email addresses), respectively. New logging functions are easy to create because they're coroutines.

```python
@Coroutine
def SocketWriter(host, port, af=socket.AF_INET, st=socket.SOCK_STREAM):
	""" Writes messages to a socket/host. """
	# this is the setup area. This is only run once, when the function is called for the first time
	message = "({0}): {1}"<commit_msg>Adds .disable()/.enable() example<commit_after># Lggr - easy python logging

Have you ever tried to do anything with the python logging module?

I have. I didn't like it at all. The API was very confusing. Instead of dealing with all of its intricacies, I decided to roll my own.

# How does it work?

Here's an example of adding lggr to an application.

```python
import lggr
logger = lggr.Lggr() # create a logging object
logger.disable() # silently stop logging - for when you don't need it, but might in the future
logger.enable() # turn the logging back on

logger.addMethod(lggr.INFO, lggr.Printer()) # log all info() calls to STDOUT
logger.addMethod(lggr.CRITICAL, lggr.FilePrinter("output.log")) # log all critical() calls to an output file
logger.addMethod(None, lggr.ErrorPrinter()) # log all logging calls to STDERR

logger.info("Here is a low level warning. It will be written to STDOUT and STDERR")
logger.warning("This is a warning. It is written to STDERR.")
logger.critical("This message will show up on STDERR and also in the \"output.log\" file")

# did I mention that it does arbitrary string.format()ing? yeah.
logger.info("{noun} is so {adjective}, I'd {verb} its {pl_noun}",
			noun="lggr", adjective="cool", verb="test", pl_noun="functions")

logger.warning("WARNING: {} is a {}. You should know this", lggr.Lggr, type(lggr.Lggr))

logger.clearMethods(lggr.CRITICAL) # remove all methods from a specific level

logger.close() # stop logging
```

`lggr.Printer`, `lggr.ErrorPrinter`, and `lggr.FilePrinter` (as well as `lggr.SocketWriter` and `lggr.Emailer`) are all built-in logging functions that log to STDOUT, STDERR, and a specified file (as well as a host/socket and email addresses), respectively. New logging functions are easy to create because they're coroutines.

```python
@Coroutine
def SocketWriter(host, port, af=socket.AF_INET, st=socket.SOCK_STREAM):
	""" Writes messages to a socket/host. """
	# this is the setup area. This is only run once, when the function is called for the first time
	message = "({0}): {1}"
{'fraction_non_alphanumeric': 0.11094224924012158, 'fraction_numerical': 0.0010131712259371835, 'mean_word_length': 4.698412698412699, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2028153', 'n_tokens_mistral': 1252, 'n_tokens_neox': 1222, 'n_words': 514}