global name logger is not defined thru classes?
Question: I cant get logger as a global name... I tried it inside a normal script, and
later trying to debug inside the python cli, but its out of my reach
apparently...  
(as you will notice, I tried to define logger global everywhere, but also
without that, no success)

Inside the python cli-program:

    
    
    import time
    import datetime
    import subprocess
    import re
    import glob
    import logging
    from daemon import runner
    from lockfile import LockTimeout
    import RPIO
    import picamera
    import atexit
    #From here, it should be global right?
    global logger
    logger = logging.getLogger("DoorcamLog")
    import DoorcamExample
    doorcam=DoorcamExample.Doorcam()
    

Error returned:

    
    
    Traceback (most recent call last):
      File "<stdin>", line 1, in <module>
      File "DoorcamExample.py", line 28, in __init__
        logger.info('Doorcam started capturing')
    NameError: global name 'logger' is not defined
    

DoorcamExample.py:

    
    
    #!/usr/bin/python
    import sys
    import os
    if os.geteuid() != 0:
        # This works perfect on a Raspbian system because there's no rootpassword required
        os.execvp("sudo", ["sudo"] + sys.argv)
        print('to far!') #This should NEVER be reached, there is something wrong...
        sys.exit(1)
    
    import time
    import datetime
    import subprocess
    import re
    import glob
    import logging
    from daemon import runner
    from lockfile import LockTimeout
    import RPIO
    import picamera
    import atexit
    
    
    
    
    class Doorcam:
        global logger
        def __init__(self):
            logger.info('Doorcam started capturing')
            self.pollLightFile='/var/tmp/picam-pollLight'
            atexit.register(self.stopListening)
    
        def socket_callback(self, socket, val):
            vals=val.split()
            if len(vals) == 0 or len(vals) > 4:
                number=1
                notify=True
                trigger='Socket'
                triggernotify='Socket (value %s)'%val
            elif len(vals) == 1:
                number=int(vals[0])
                notify=True
                trigger='Socket'
                triggernotify='Socket (value %s)'%val
            elif len(vals) == 2:
                number=int(vals[1])
                notify=True
                trigger=vals[0]
                triggernotify=vals[0]
            elif len(vals) == 3:
                number=int(vals[1])
                trigger=vals[0]
                triggernotify=vals[0]
                notify=self.boolval(vals[2])
            elif len(vals) == 4:
                number=int(vals[2])
                trigger=vals[0]
                triggernotify=vals[0], [1]
                notify=self.boolval(vals[3])
    
            socket.send('self.upload(self.shot(filename=self.filename, number=number, trigger=trigger), notify=notify,trigger=triggernotify)')
            RPIO.close_tcp_client(socket.fileno())
    
        def startListening(self,channel,port=8080, threaded=True):
            #RPIO.add_interrupt_callback(channel, self.gpio_callback, pull_up_down=RPIO.PUD_DOWN, debounce_timeout_ms=1000)
            RPIO.add_tcp_callback(port, self.socket_callback)
            RPIO.wait_for_interrupts(threaded=threaded)
    
        def stopListening(self):
            logger.info('Stop listening')
            RPIO.stop_waiting_for_interrupts()
    
    
    global logger
    


Answer: "Global" variables are only global within a single module, so your
DoorcamExample.py doesn't have access to logger that you defined in some other
module.

In this case, you don't need a global variable, because the logging module
already maintains a truly global (i.e., visible from all modules) registry of
loggers. So if you do `logging.getLogger("DoorcamLog")` in any of your
modules, you'll get a reference to the same logger.

