Skip to main content

Make logging and reporting of errors easier, more informative, and more "standard."

Project description


The purpose of this module is to make logging and reporting of errors easier, more informative, and more consistent.

There is one library for python and one for javascript that is not as fully-featured yet.

AppLogger logs messages to include

  • The name of the system generating the message (helpful in pipelines)
  • The file name and line number where the log is written (helpful for quickly finding the relevant code)
  • The log level of the message (useful for quick identification and filtering)
  • The actual message

AppLogger allows you to specify the actual message as a list instead of a string, which makes it efficient enough that you typically don't have to check the log level, and you can just call the log function blindly. Py example:

    l = AppLogger('demo')
    l.debug("This call won't build a big string from my list of numbers, ", [0, 1, 2, 3], " or serialize ",
            my_complex_object, " unless debugging is turned on, so I can feel free to make lots of logging statements!")
    if l.isSetDebug():
        l.debug("I do want to protect logging inside conditional if I need to log with ", slow_function_call())

AppStatus is a container for returning application status, such as warnings, errors, or other info along with the main function result(s). Log into it, just as with AppLogger. These diagnostics can be logged or handled at higher levels in the call stack, providing for the principles of "effective logging" - log only once, and with all context. There are many more things we can do with status, merging status from multiple call chains or de-duplicating log messages, but here is a basic usage:

            s = AppStatus()
            if s.ok:"we're doing fine")
            s = AppStatus("unable to find boot sector")
            s.addWarn("backup all data now")
            if s.hasErrors(): l.error("We have a problem: ", str(s))  # shows whole status, inc. the warning
                return '''
demo: INFO: we're doing fine
demo: ERROR: We have a problem: unable to find boot sector; WARNINGS: backup all data now

It also provides a mechanism for passing computed values up the call stack, either individually, or multiple values at once. Think of it as a ledger to keep track of the things that happened so far in a given call chain. You don't have to make the hard choice of should I return a value, or should I throw an exception to indicate a special condition. You can report everything and let the caller decide, but if they forget to explicitly ignore errors, we'll still throw an exception.

        s = AppStatus()     # we can pretend we got this from a function call that returned an AppStatus
        s.setValue("foo")   # that function might have set a value that we want
        s.addErr("bar")     # but an error might have also been encountered
        v = s.getValue()    # in which case this would throw an exception
        s.clearErrors()     # unless clearErrors() called first
        getErrors()         # getErrors() indicates errors were handled and should not throw on getValue() (unimplemented?)

AppError is the same as AppStatus, but turned into an exception (with stack trace) for those times when you really do want to throw an exception. But, included with the exception you can still have your ledger of computed value(s) and other diagnostics you collected up to the failure point, like warnings and info messages. AppError doesn't inherit from AppStatus because AppStatus doesn't collect a stack trace, but AppError does.

Please see in this distribution for usage, starting from most basic and progressing to more advanced for all of the above and more.



2.0.1: Specify dependency on dumper 2.0.0: Remove support for python 2 1.1.0: Initial version.

Project details

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

apperror-2.0.1.tar.gz (11.3 kB view hashes)

Uploaded source

Built Distribution

apperror-2.0.1-py3-none-any.whl (10.3 kB view hashes)

Uploaded py3

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page