In Python Zope, how do I dump the error_log onto the browser?

We are a big org and we use Python Zope. We have naturally two versions: prod and dev. In production I understand due to security reasons we should not show error log to end users, but how do I do that for dev? It is very cumbersome to check the error log manually every time I get an internal server error.

Can I dump the error log directly onto the browser on the respective HTTP request?

Zope v. 4.6.2
Python v. 3.8.0b2 (default, Jul 9 2019, 16:47:40) [GCC 4.8.5]

If you are a big org, I would recommend to install a Sentry server (dumb easy in Kubernetes or any containerized environment) and log the errors to Sentry.

In Zope or Plone there is collective.sentry add-on to support logging errors this way. I use this since some years and it helps to keep track of all sorts of errors, even those one does not notice normally. Often a customer call b/c of a problem and I can tell them like "I know, I got this error already reported, we are on fixing it".

Additionally it saves that much time, the installation effort is back in just s few months.

1 Like

Thanks @jensens
installing further services or software is very cumbersome and bureaucratic, I don't want to go that way.

Could you kindly tell me how do I install that addon collective.sentry?

I was not the one who installed Zope, so I am bit lost on the backend, I develop the python code from the UI admin portal.

João Pimentel Ferreira via Plone Community wrote at 2022-3-10 15:27 +0000:

We are a big org and we use Python Zope. We have naturally two versions: prod and dev. In production I understand due to security reasons we should not show error log to end users, but how do I do that for dev? It is very cumbersome to check the error log manually every time I get an internal server error.

Can I dump the error log directly onto the browser on the respective HTTP request?

You can configure error_log to log tracebacks to the logfile.
Then you will find traceback in the logfile.

You could also customize error handling.
The basic mechanism is via so called error views (an adapter
for (exception, request)). If not such view is registered for the
current error, standard_error_message is tried.
You could generate a link to the error log entry (Jens told you
how) for users with sufficient privileges.
Note, however, that some exceptions happen before authentication;
in those cases, error handling happens for "anonymous".

Alternatively you could run Zope in the foreground in a terminal in the dev environment. It should print the traceback directly onto that terminal.

@dieter and @icemac thank you for your replies

Maybe I was not clear enough: I don't want to dump the whole log file onto the browser, I just want the traceback error which is in log file, triggered by the corresponding HTTP request.

For example, when I make a HTTP request on the browser, instead of getting from the browser "Internal server error", I want to have on the browser the traceback error caused by such HTTP request.

That would help debugging, because I don't need to go to the error_log every time I get an internal server error, and I would get the traceback for that specific http request error directly on the browser.

João Pimentel Ferreira via Plone Community wrote at 2022-3-11 08:55 +0000:

...
For example, when I make a HTTP request on the browser, instead of getting from the browser "Internal server error", I want to have on the browser the traceback error caused by such HTTP request.

As I (already) wrote:
customize Zope's error handling (defining either your own
error view[s] or standard_error_message) and do there whatever you want (I would prefer a link to the error log entry - Jens told you how in your Products.SiteErrorLog` thread).

1 Like

customize Zope's error handling (defining either your own error view[s] or `standard_error_message)

Can you clarify where in the Zope code the error view can be customised? or where to adjust standard_error_message.

Also, in Zope 2, this was the default behavior, I mean, the traceback for a error was returned to the browser. What exactly changed?

zfm via Plone Community wrote at 2022-3-24 08:58 +0000:

...
Can you clarify where in the Zope code the error view can be customised? or where to adjust standard_error_message.

A view in general is an adapter for a pair object, request.
Usually, a template is associated with a view which "presents"
the adapted object for the request.
You (usually) register views in "ZCML" via "browser:page".
For details, search the net (e.g. in the Plone documentation).

An error view is a view where the object is an exception.

When I remember right, standard_error_message is no longer
installed in the Zope root object.
If this is the case, you must create an object
with this name (a template or Python script).
If it is still installed, you must modify/replace the object.

Also, in Zope 2, this was the default behavior, I mean, the traceback for a error was returned to the browser. What exactly changed?

Zope 4 no longer does everything itself -- but delegates to
other frameworks. This allows to simplify things and reduces
the maintenance burden.

In particular, Zope 4 is a "WSGI application". This means that
it runs (as application component) in a WSGI server framework which provides
standard solutions for many web application related tasks -
among them error handling.

For most users the default error handling is sufficient.
For users with special requirements (such as you),
there are very flexible ways to customize the error handling
(--> error views and standard_error_message).

I am not sure whether the newer (Zope component architecture
related) features (such as views, events, adapters, utilities)
are already documented in the (fairly old) Zope documentation.
But you will surely find related information in the Plone
documentation (--> "https://docs.plone.org/").