96 'traceback': str(getattr(e, 'traceback_str', '')),
97 }
98 except SecurityError as e:
99 logging.warning(f'Security error at {context.path}: {e.message}')100 if page:
101 raise
102 status = 403
46 pass
47
48 def handle(self, http_context):
49 logging.warning(f'URL not found: {http_context.path}') 50 http_context.respond_not_found()
51
52 with open(os.path.dirname(__file__)+'/static/images/error.jpeg', "rb") as error_image:
17 pass
18
19 def handle(self, http_context):
20 logging.warning(f'Invalid client certificate : ' 21 f'{http_context.env["SSL_CLIENT_DIGEST"]}'
22 )
23 http_context.respond_unauthenticated()
229 if demote:
230 uid = self.get_provider().get_isolation_uid(username)
231 gid = self.get_provider().get_isolation_gid(username)
232 logging.debug(233 f'Authentication provider "{self.get_provider().name}" maps "{username}" -> {uid:d}'
234 )
235 self.context.worker.demote(uid, gid)
217 return self.context.identity
218
219 def login(self, username, demote=True):
220 logging.info(f'Authenticating session as {username}')221 syslog.syslog(
222 syslog.LOG_NOTICE | syslog.LOG_AUTH,
223 f'{username} has logged in from {self.context.session.client_info["address"]}'
Formatting the message manually before passing it to a logging
call does unnecessary work if logging is disabled. Consider using the logging
module's built-in formatting features to avoid that.
If your logging level is set to "WARNING"
, but the logging call is:
logging.debug("Data: %s", data)
In the above example, there will be no logging as the level debug
is below warning
. The conversion of the data
object to a string will be skipped by the logging module resulting in improved performance.
logging.debug(f"Data: {data}")
In the code shown above, the conversion of the data
object to a string will happen regardless of whether the message is logged or not (which is based on the log level).
import logging
import inspect
logging.basicConfig(level=logging.INFO)
logging.debug(f"Entered function {inspect.stack[0][3]}"))
import logging
import inspect
logging.basicConfig(level=logging.INFO)
logging.debug("Entered function %s", inspect.stack[0][3])