""" Logging facilities for RPKI libraries. $Id$ Copyright (C) 2009--2011 Internet Systems Consortium ("ISC") Permission to use, copy, modify, and distribute this software for any purpose with or without fee is hereby granted, provided that the above copyright notice and this permission notice appear in all copies. THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL ISC BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. Portions copyright (C) 2007--2008 American Registry for Internet Numbers ("ARIN") Permission to use, copy, modify, and distribute this software for any purpose with or without fee is hereby granted, provided that the above copyright notice and this permission notice appear in all copies. THE SOFTWARE IS PROVIDED "AS IS" AND ARIN DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL ARIN BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. """ import syslog, sys, os, time import traceback as tb ## @var enable_trace # Whether call tracing is enabled. enable_trace = False ## @var use_syslog # Whether to use syslog use_syslog = True ## @var show_python_ids # Whether __repr__() methods should show Python id numbers show_python_ids = False ## @var enable_tracebacks # Whether tracebacks are enabled globally. Individual classes and # modules may choose to override this. enable_tracebacks = False tag = "" pid = 0 def init(ident = "rpki", flags = syslog.LOG_PID, facility = syslog.LOG_DAEMON): """ Initialize logging system. """ if use_syslog: return syslog.openlog(ident, flags, facility) else: global tag, pid tag = ident pid = os.getpid() def set_trace(enable): """ Enable or disable call tracing. """ global enable_trace enable_trace = enable class logger(object): """ Closure for logging. """ def __init__(self, priority): self.priority = priority def __call__(self, message): if use_syslog: return syslog.syslog(self.priority, message) else: sys.stderr.write("%s %s[%d]: %s\n" % (time.strftime("%F %T"), tag, pid, message)) error = logger(syslog.LOG_ERR) warn = logger(syslog.LOG_WARNING) note = logger(syslog.LOG_NOTICE) info = logger(syslog.LOG_INFO) debug = logger(syslog.LOG_DEBUG) def trace(): """ Execution trace -- where are we now, and whence came we here? """ if enable_trace: bt = tb.extract_stack(limit = 3) return debug("[%s() at %s:%d from %s:%d]" % (bt[1][2], bt[1][0], bt[1][1], bt[0][0], bt[0][1])) def traceback(do_it = None): """ Consolidated backtrace facility with a bit of extra info. Argument specifies whether or not to log the traceback (some modules and classes have their own controls for this, this lets us provide a unified interface). If no argument is specified, we use the global default value rpki.log.enable_tracebacks. """ if do_it is None: do_it = enable_tracebacks if do_it: assert sys.exc_info() != (None, None, None), "rpki.log.traceback() called without valid trace on stack, this is a programming error" bt = tb.extract_stack(limit = 3) error("Exception caught in %s() at %s:%d called from %s:%d" % (bt[1][2], bt[1][0], bt[1][1], bt[0][0], bt[0][1])) bt = tb.format_exc() assert bt is not None, "Apparently I'm still not using the right test for null backtrace" for line in bt.splitlines(): warn(line) def log_repr(obj, *tokens): """ Constructor for __repr__() strings, handles suppression of Python IDs as needed, includes self_handle when available. """ words = ["%s.%s" % (obj.__class__.__module__, obj.__class__.__name__)] try: words.append("{%s}" % obj.self.self_handle) except: pass words.extend(str(token) for token in tokens if token is not None and token != "") if show_python_ids: words.append(" at %#x" % id(obj)) return "<" + " ".join(words) + ">" 9b30f04cc67ba351725ef4051881'>fc8fb08d
b603ea6e











7cd69b77
1ed26c98
41c51dee

9be98caf

41c51dee

4cf293b5
6d7cbc19
41c51dee

a1cbec00
6d7cbc19
41c51dee


ad8c775e
41c51dee

4d803d82
41c51dee





4d803d82
6d7cbc19
41c51dee

4dd311b3
89e42691
b8334309

0bfc429a
b8334309
935f1206

dfab8147

935f1206





2add9234
935f1206







c4be735c
935f1206
dfab8147

935f1206




c4be735c









935f1206


















4dd311b3
41c51dee


89e42691
4dd311b3
89e42691
4dd311b3




ba42f709
4dd311b3
41c51dee



4dd311b3


14bd2769
4dd311b3

3031f6ec
4dd311b3











41c51dee


4dd311b3










41c51dee


4dd311b3














41c51dee


4dd311b3
94bad6e5
4dd311b3

42b211b6
4dd311b3
41c51dee


4dd311b3




fc8fb08d
4dd311b3
6d7cbc19
4dd311b3
41c51dee


4dd311b3
1754b742
57c3a43e
4dd311b3



1754b742
4d911076

4dd311b3
41c51dee


4dd311b3




41c51dee



4dd311b3


744ec2cb


4dd311b3
41c51dee


4dd311b3






41c51dee


4dd311b3




41c51dee



4dd311b3



744ec2cb


aaecbfca
41c51dee


aaecbfca


4dd311b3
744ec2cb












4dd311b3
41c51dee


4dd311b3
aaecbfca
4dd311b3
744ec2cb







21ba16be

4dd311b3



cd006f96
41c51dee


4dd311b3


41c51dee
fc8fb08d
cd006f96
41c51dee




cd006f96
744ec2cb
cd006f96
4dd311b3
666582cc
4dd311b3


a780a780
41c51dee
a780a780
4dd311b3
cd006f96
4dd311b3

41c51dee


4dd311b3




41c51dee















cd006f96
4dd311b3




4dd311b3






fc8fb08d
4dd311b3


41c51dee





4dd311b3









41c51dee




4dd311b3






41c51dee



4dd311b3

ad8c775e
4dd311b3


41c51dee



4dd311b3

ad8c775e
4dd311b3



41c51dee


4dd311b3



41c51dee




d2001e8d
57c3a43e

e43c0c61
1157f4bd
d2001e8d
aaecbfca
94bad6e5
4dd311b3

41c51dee


4dd311b3
94bad6e5
4dd311b3

41c51dee

d2001e8d
41c51dee
931eb70e
d2001e8d
fe215500
4dd311b3

41c51dee
db7c04d1
41c51dee
4dd311b3
41c51dee

4dd311b3

41c51dee

ad8c775e

94bad6e5
4dd311b3
21ba16be
4dd311b3
744ec2cb
4dd311b3

41c51dee




4dd311b3


a780a780


4dd311b3



119bfdbb
4dd311b3
41c51dee
94bad6e5
41c51dee



744ec2cb
42b211b6
4dd311b3









4d911076

cd006f96
96559dfb
b3a4636d
1157f4bd
bdd3b437
4dd311b3
d0c51c60
4dd311b3

41c51dee


4dd311b3

744ec2cb
41c51dee


744ec2cb
4dd311b3

41c51dee





931eb70e
90a2370c

4dd311b3












41c51dee
db7c04d1
41c51dee
4dd311b3
aaecbfca
4dd311b3
744ec2cb






94bad6e5
4dd311b3

3a449c7e
c4be735c
6de6c7c8
3a449c7e
dfab8147
fb9d4d2d
dfab8147



6de6c7c8
3a449c7e
72e42a65

1157f4bd
e54ad58d
744ec2cb

4dd311b3

41c51dee

94bad6e5
41c51dee
3a449c7e
c4be735c

94bad6e5
cd006f96
3a449c7e
72e42a65

3a449c7e
4dd311b3

41c51dee


e54ad58d
e43c0c61
e54ad58d
1157f4bd
4dd311b3

41c51dee
db7c04d1
41c51dee
4dd311b3
41c51dee

4dd311b3

41c51dee

ad8c775e

db7c04d1



94bad6e5
744ec2cb
cd006f96
4dd311b3
39e00194

db7c04d1
4dd311b3
3a449c7e

41c51dee


39e00194
db7c04d1
935f1206
39e00194
db7c04d1
935f1206
39e00194
db7c04d1


39e00194
935f1206




28cf2519

935f1206
39e00194

39e00194
3a449c7e
f2461442
bf0d6be3
2add9234
f2461442
bf0d6be3

b417bbfc
cd006f96
125c61b4
72e42a65
3a449c7e
4dd311b3
cd006f96
41c51dee
94bad6e5
41c51dee
caaed227
94bad6e5
bf0d6be3
94bad6e5
cd006f96
3b6dc091
41c51dee


3b6dc091


4dd311b3
41c51dee





4dd311b3


41c51dee


3b6dc091
4dd311b3
3b6dc091


cd006f96
4dd311b3

41c51dee








3b6dc091

42b211b6
4dd311b3
3b6dc091





94bad6e5
3b6dc091

4dd311b3
3b6dc091
4dd311b3


3b6dc091
cd006f96
4dd311b3
57c3a43e
84dd133c







d2001e8d
3b6dc091
4dd311b3
41c51dee





4dd311b3
3dff6336
4dd311b3

f461f6f3
94bad6e5
d2001e8d

4dd311b3
4110a31d
41c51dee
666582cc

41c51dee
94bad6e5

666582cc
4110a31d
94bad6e5
4d803d82

c4be735c
4d803d82
d2001e8d

4110a31d
3a449c7e
41c51dee



91c5f8e9
744ec2cb
3a449c7e
d2001e8d
3a449c7e
4dd311b3
41c51dee




4dd311b3
aaecbfca
4dd311b3
744ec2cb
e252a23c
744ec2cb
94bad6e5
4dd311b3

744ec2cb
4dd311b3


41c51dee


4dd311b3
4dd311b3
3b6dc091

41c51dee







1952ab78

94bad6e5
41c51dee
1952ab78








d2001e8d
3b6dc091

41c51dee


3b6dc091


41c51dee








3b6dc091

c4be735c
41c51dee





4dd311b3
d2001e8d






444389ab

94bad6e5
444389ab
94bad6e5
444389ab
cd006f96
83524080



3b6dc091

83524080






aaecbfca
45456b2e
83524080

72e42a65
83524080

72e42a65


83524080

72e42a65
3b6dc091
4dd311b3
119bfdbb
6e27428a
3b6dc091

41c51dee

d86ab23f
119bfdbb
94bad6e5
a780a780
94bad6e5
9a7e24ee
eba8fc67
6075022d
5dd67f0e

94bad6e5
1ca7907a





5dd67f0e
4cf293b5
f4d51343
aac95769
45456b2e








b8334309
45456b2e
4cf293b5
744ec2cb
d86ab23f
94bad6e5
d86ab23f
7ee38794
9a7e24ee


4cf293b5
dba89077
96dce206
9a7e24ee
94bad6e5
a780a780
94bad6e5
45456b2e
7ee38794
8ec96ec4


e54ad58d


935f1206
6de6c7c8
e54ad58d












94bad6e5
e54ad58d
4dd311b3

da14517d

94bad6e5
da14517d












aedaacf9
da14517d




444389ab
41c51dee


95d3eb56


ab90c10d
95d3eb56







da14517d
444389ab


da14517d

444389ab
da14517d
94bad6e5
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070