Skip to content

Commit 02b3107

Browse files
authored
Update nginx.py
- consider the parent logger - __name__ instead of "root"
1 parent 20a8484 commit 02b3107

File tree

1 file changed

+17
-16
lines changed

1 file changed

+17
-16
lines changed

nginx.py

Lines changed: 17 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,8 @@
1212
INDENT = ' '
1313
DEBUG=False
1414

15-
logging.basicConfig(level=logging.DEBUG if DEBUG else logging.INFO)
15+
log = logging.getLogger(__name__)
16+
log.setLevel(logging.DEBUG if DEBUG else logging.INFO)
1617

1718
class Error(Exception):
1819
pass
@@ -421,31 +422,31 @@ def loads(data, conf=True):
421422
while True:
422423
m = re.compile(r'^\s*events\s*{').search(data[index:])
423424
if m:
424-
logging.debug("Open (Events)")
425+
log.debug("Open (Events)")
425426
e = Events()
426427
lopen.insert(0, e)
427428
index += m.end()
428429
continue
429430

430431
m = re.compile(r'^\s*http\s*{').search(data[index:])
431432
if m:
432-
logging.debug("Open (Http)")
433+
log.debug("Open (Http)")
433434
h = Http()
434435
lopen.insert(0, h)
435436
index += m.end()
436437
continue
437438

438439
m = re.compile(r'^\s*stream\s*{').search(data[index:])
439440
if m:
440-
logging.debug("Open (Stream)")
441+
log.debug("Open (Stream)")
441442
s = Stream()
442443
lopen.insert(0, s)
443444
index += m.end()
444445
continue
445446

446447
m = re.compile(r'^\s*server\s*{').search(data[index:])
447448
if m:
448-
logging.debug("Open (Server)")
449+
log.debug("Open (Server)")
449450
s = Server()
450451
lopen.insert(0, s)
451452
index += m.end()
@@ -454,63 +455,63 @@ def loads(data, conf=True):
454455
n = re.compile(r'(?!\B"[^"]*);(?![^"]*"\B)')
455456
m = re.compile(r'^\s*location\s+(.*?".*?".*?|.*?)\s*{').search(data[index:])
456457
if m and not n.search(m.group()):
457-
logging.debug("Open (Location) {0}".format(m.group(1)))
458+
log.debug("Open (Location) {0}".format(m.group(1)))
458459
l = Location(m.group(1))
459460
lopen.insert(0, l)
460461
index += m.end()
461462
continue
462463

463464
m = re.compile(r'^\s*if\s+(.*?".*?".*?|.*?)\s*{').search(data[index:])
464465
if m and not n.search(m.group()):
465-
logging.debug("Open (If) {0}".format(m.group(1)))
466+
log.debug("Open (If) {0}".format(m.group(1)))
466467
ifs = If(m.group(1))
467468
lopen.insert(0, ifs)
468469
index += m.end()
469470
continue
470471

471472
m = re.compile(r'^\s*upstream\s+(.*?)\s*{').search(data[index:])
472473
if m and not n.search(m.group()):
473-
logging.debug("Open (Upstream) {0}".format(m.group(1)))
474+
log.debug("Open (Upstream) {0}".format(m.group(1)))
474475
u = Upstream(m.group(1))
475476
lopen.insert(0, u)
476477
index += m.end()
477478
continue
478479

479480
m = re.compile(r'^\s*geo\s+(.*?".*?".*?|.*?)\s*{').search(data[index:])
480481
if m and not n.search(m.group()):
481-
logging.debug("Open (Geo) {0}".format(m.group(1)))
482+
log.debug("Open (Geo) {0}".format(m.group(1)))
482483
g = Geo(m.group(1))
483484
lopen.insert(0, g)
484485
index += m.end()
485486
continue
486487

487488
m = re.compile(r'^\s*map\s+(.*?".*?".*?|.*?)\s*{').search(data[index:])
488489
if m and not n.search(m.group()):
489-
logging.debug("Open (Map) {0}".format(m.group(1)))
490+
log.debug("Open (Map) {0}".format(m.group(1)))
490491
g = Map(m.group(1))
491492
lopen.insert(0, g)
492493
index += m.end()
493494
continue
494495

495496
m = re.compile(r'^\s*limit_except\s+(.*?".*?".*?|.*?)\s*{').search(data[index:])
496497
if m and not n.search(m.group()):
497-
logging.debug("Open (LimitExcept) {0}".format(m.group(1)))
498+
log.debug("Open (LimitExcept) {0}".format(m.group(1)))
498499
l = LimitExcept(m.group(1))
499500
lopen.insert(0, l)
500501
index += m.end()
501502
continue
502503

503504
m = re.compile(r'^\s*types\s*{').search(data[index:])
504505
if m:
505-
logging.debug("Open (Types)")
506+
log.debug("Open (Types)")
506507
l = Types()
507508
lopen.insert(0, l)
508509
index += m.end()
509510
continue
510511

511512
m = re.compile(r'^(\s*)#[ \r\t\f]*(.*?)\n').search(data[index:])
512513
if m:
513-
logging.debug("Comment ({0})".format(m.group(2)))
514+
log.debug("Comment ({0})".format(m.group(2)))
514515
c = Comment(m.group(2), inline='\n' not in m.group(1))
515516
if lopen and isinstance(lopen[0], Container):
516517
lopen[0].add(c)
@@ -522,7 +523,7 @@ def loads(data, conf=True):
522523
m = re.compile(r'^\s*}').search(data[index:])
523524
if m:
524525
if isinstance(lopen[0], Container):
525-
logging.debug("Close ({0})".format(lopen[0].__class__.__name__))
526+
log.debug("Close ({0})".format(lopen[0].__class__.__name__))
526527
c = lopen[0]
527528
lopen.pop(0)
528529
if lopen and isinstance(lopen[0], Container):
@@ -544,7 +545,7 @@ def loads(data, conf=True):
544545
s = r'^\s*({})\s*((?:{})+);'.format(s1, s1)
545546
m = re.compile(s).search(data[index:])
546547
if m:
547-
logging.debug("Key {0} {1}".format(m.group(1), m.group(2)))
548+
log.debug("Key {0} {1}".format(m.group(1), m.group(2)))
548549
k = Key(m.group(1), m.group(2))
549550
if lopen and isinstance(lopen[0], (Container, Server)):
550551
lopen[0].add(k)
@@ -555,7 +556,7 @@ def loads(data, conf=True):
555556

556557
m = re.compile(r'^\s*(\S+);').search(data[index:])
557558
if m:
558-
logging.debug("Key {0}".format(m.group(1)))
559+
log.debug("Key {0}".format(m.group(1)))
559560
k = Key(m.group(1), '')
560561
if lopen and isinstance(lopen[0], (Container, Server)):
561562
lopen[0].add(k)

0 commit comments

Comments
 (0)