Skip to main content

app_error

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: l.info("we're doing fine")
    
            s = AppStatus("unable to find boot sector")
            s.addWarn("backup all data now")
            print(str(s))
            if s.hasErrors(): l.error("We have a problem: ", str(s))  # shows whole status, inc. the warning
                return '''
demo: INFO: demo.py:57: we're doing fine
demo: ERROR: demo.py:61: We have a problem: demo.py:59: unable to find boot sector; WARNINGS: demo.py:60: 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 demo.py in this distribution for usage, starting from most basic and progressing to more advanced for all of the above and more.

===

CHANGELOG:

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

Metadata

Release files for apperror 2.0.1

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for apperror 2.0.1
File Size Uploaded
apperror-2.0.1.tar.gz 11.3 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for apperror 2.0.1
File Interpreter ABI Platform
apperror-2.0.1-py3-none-any.whl Python 3 none any Details

Total release size: 21.6 kB

Release files / apperror-2.0.1.tar.gz

Download URL apperror-2.0.1.tar.gz
Size 11.3 kB
Tags Source
SHA-256 checksum
How to use checksums
f2431299b70dadc8ddf9468b3b3b41267dee3577feae921be697eaac5c9fcfe0
BLAKE2b-256 checksum
How to use checksums
a6f69a2f3f787928f30c057f47094c34b294e3104197c6efc5abf106aca85c32
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.2 CPython/3.10.9

Release files / apperror-2.0.1-py3-none-any.whl

Download URL apperror-2.0.1-py3-none-any.whl
Size 10.3 kB
Tags Python 3
SHA-256 checksum
How to use checksums
e503ec20790ee2c0d601591dd8bfafb3e9a86feb09ff7a01109ee3e7b16b56aa
BLAKE2b-256 checksum
How to use checksums
46c2b3978c4fc94a54fbc10cabbde76067584613aac22a9614c9767c76ab57e0
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.2 CPython/3.10.9

Release history Release notifications | RSS feed

This release

2.0.1 This release

2 release files

2.0.0

2 release files

1.1.1

2 release files

1.1.0

1 release file

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page