Line | |
---|
1 | #!/usr/bin/env python |
---|
2 | |
---|
3 | |
---|
4 | """Create a short probably-unique string for use as a umid= argument in a |
---|
5 | Foolscap log() call, to make it easier to locate the source code that |
---|
6 | generated the message. The main text of the log message is frequently |
---|
7 | unhelpful for this, and python doesn't make it cheap to compile in the |
---|
8 | filename and line number of logging calls. |
---|
9 | |
---|
10 | Given a message-unique-ID like 'aXoWcA', make your logging call look like: |
---|
11 | |
---|
12 | log.msg('OMG badness', level=log.WEIRD, umid='aXoWcA') |
---|
13 | |
---|
14 | Then later, if this message actually occurs, you can grep your source tree |
---|
15 | for aXoWcA to locate the code that caused it. |
---|
16 | |
---|
17 | Just stick to the convention that 'umid=' is reserved for this job. It is a |
---|
18 | good idea to make all the logging statements that could provoke an Incident |
---|
19 | (i.e. those at level=log.WEIRD or higher) have umid= arguments, to make it |
---|
20 | easier to write classifier functions for the incident-gatherer. |
---|
21 | |
---|
22 | """ |
---|
23 | |
---|
24 | ''' |
---|
25 | The following elisp code may be useful: |
---|
26 | |
---|
27 | (defun insert-umid () |
---|
28 | (interactive) |
---|
29 | (insert ", umid=\"") |
---|
30 | (call-process "make_umid" nil t) |
---|
31 | (delete-char -1) |
---|
32 | (insert "\"") |
---|
33 | ) |
---|
34 | (global-set-key (kbd "C-\`") 'insert-umid) |
---|
35 | ''' |
---|
36 | |
---|
37 | # ' # emacs gets confused by the odd number of single-quotes there |
---|
38 | |
---|
39 | import os, base64, sys |
---|
40 | |
---|
41 | def make_id(): |
---|
42 | while True: |
---|
43 | m = os.urandom(4) # this gives 6-character message ids |
---|
44 | m = base64.b64encode(m) |
---|
45 | if "/" in m or "+" in m: |
---|
46 | continue |
---|
47 | m = m.replace("=", "") |
---|
48 | break |
---|
49 | return m |
---|
50 | |
---|
51 | count = 1 |
---|
52 | if len(sys.argv) > 1: |
---|
53 | count = int(sys.argv[1]) |
---|
54 | for i in range(count): |
---|
55 | print(make_id()) |
---|
56 | |
---|
Note: See
TracBrowser
for help on using the repository browser.