"bench start" logging output, but on the production server

Hello

When you invoke “bench start” on the CLI of a development server, you get all sorts of feedback and logging as to what is happening.

I want to know how to, and where, to look for similar logging on a production server.
Is there a single log file I need to follow or can I open a terminal session to see the same as on a development server?

Thanks so much

Hi @EugeneP:

Check logs folder

Hope this helps.

Ahoy @avc

Am I right by saying each of these processes on a dev server (started with “bench start”) write to the CLI in different colours, but on a production server each process writes to a separate log file?

So, there is no consolidated output on a prod server, and you have to check each log file separately?

I’ve done some investigation and here is what I’ve learned.

On a production environment, server-side Python code :

import inspect
sFunc = inspect.currentframe().f_code.co_name

#print() writes to the CLI, but only on a dev environment with "bench start"
print(f'***my-log*** : {sFunc}')

#frappe.logger() writes to a log file, subject to the logging level
#    ["ERROR", "WARNING", "WARN", "INFO", "DEBUG"]
#    set with either bench or set_log_level()
#        bench --site "site-name" set-config logging WARN
frappe.utils.logger.set_log_level("DEBUG")
#By default frappe.logger writes to frappe.log
frappe.logger().info(f'***my-log*** : {sFunc} : frappe.logger : {self.name}')
#You can also write to you own log file, eg mylog.log
frappe.logger('mylog').debug(f'***my-log*** : {sFunc} : frappe.logger')

#frappe.log_error() writes to the Error Log doctype and can be read in Desk
frappe.log_error(f'***my-log*** : {sFunc}: frappe.log_error', frappe.get_traceback())

#frappe.errprint() writes to the WUI browser console
frappe.errprint(f'***my-log*** : {sFunc} : frappe.errprint')

#frappe.throw() causes a cascading error condition and writes to the WUI in a pop-up modal
frappe.throw(f'***my-log*** : {sFunc} : frappe.throw')

To find log entries, use the following CLI commands :

sDirB="~/your/frappe/bench/directory"
cd ${sDirB}
grep --recursive "***my-log***" ${sDirB}
find ${sDirB} -type f -mmin -2 -ls
tail --follow ${sDirB}/logs/mylog.log

Are there any other options?
If so, please add to this topic.

Two enterprise setups I came across, both are equally expensive IaaS or self-hosted:

  • Enabled cloudwatch for all pods on AWS EKS and the team was able to use AWS Cloudwatch to search logs and trigger alerts.
  • Separate ELK stack for Kubernetes cluster was setup and logs for a week are searchable there.
1 Like

There are tons of log monitoring tools out there, both commercial and open source. I’ve used a few over the years, and they all tend to work pretty fine. I won’t name any specific one, but googling “log monitoring tool” turns up a lot.

As the code you posted suggests, it’s not a 1-to-1 between what shows up in the console in development and the log files in production. The stuff you see in the console is just whatever werkzeug sends to stdout, and I believe the color coding just distinguishes different dependent processes. Logging, meanwhile, has to be explicitly invoked by frappe (or nginx, etc.)

Is there something in particular you’re looking for but can’t find in the logs?

1 Like

Hi @peterg

Thanks for your contribution

I was just “missing” the same sort of immediate response and feedback you get when on a dev compared to when on a prod environment. But I now realise there is no such consolidated view on prod, except for it you install a log monitoring tool.

1 Like