MCPcopy
hub / github.com/samuelclay/NewsBlur / user

Function user

utils/log.py:29–68  ·  view source on GitHub ↗
(u, msg, request=None, warn_color=True)

Source from the content-addressed store, hash-verified

27
28
29def user(u, msg, request=None, warn_color=True):
30 msg = smart_str(msg)
31 if not u:
32 return debug(msg)
33
34 platform = "------"
35 time_elapsed = ""
36 if isinstance(u, WSGIRequest) or request:
37 if not request:
38 request = u
39 u = getattr(request, "user", None)
40 platform = extract_user_agent(request)
41
42 if hasattr(request, "start_time"):
43 seconds = time.time() - request.start_time
44 color = "~FB"
45 if warn_color:
46 if seconds >= 5:
47 color = "~FR"
48 elif seconds > 1:
49 color = "~FY"
50 queue_str = ""
51 if hasattr(request, "_server_timing_start"):
52 queue_seconds = request.start_time - request._server_timing_start
53 if queue_seconds > 0.1:
54 queue_str = "~FR+%.2fq~SB" % queue_seconds
55 time_elapsed = "[%s%.4ss%s~SB] " % (
56 color,
57 seconds,
58 queue_str,
59 )
60 if not u:
61 info(" ---> [~FB~SN%-6s~SB] %s[anonymous] %s" % (platform, time_elapsed, msg))
62 return
63 is_premium = u.is_authenticated and u.profile.is_premium
64 premium = "*" if is_premium else ""
65 if is_premium and u.profile.is_archive:
66 premium = "^"
67 username = cipher(str(u)) if settings.CIPHER_USERNAMES else str(u)
68 info(" ---> [~FB~SN%-6s~SB] %s[%s%s] %s" % (platform, time_elapsed, username, premium, msg))
69
70
71def cipher(msg):

Callers

nothing calls this directly

Calls 4

extract_user_agentFunction · 0.85
cipherFunction · 0.85
debugFunction · 0.70
infoFunction · 0.70

Tested by

no test coverage detected