Modules or Package for my application

Discussion in 'Python' started by Stone, Nov 27, 2012.

  1. Stone

    Stone Guest

    Dear developers,

    I am creating application (originally written in perl)
    which will take care about replication from one system to the another system over command rsync. It will simulate High-availability solution.

    The application will contains main module called like ha.py
    and another modules will have names Replication.py, Trace.py, Misc.py, Procs.py, Constants.py, Lan.py, Display.py

    My questions are:
    1) When I would like to make a global logging to the one file is it enough to do that like
    TRACE='/var/ha/log/sso_trace.log'
    logger = logging.getLogger('sso')
    hdrl = logging.FileHandler(TRACE)
    formatter = logging.Formatter('%{asctime}s %{levelname}s %{message}s')
    hdrl.setFormatter(formatter)
    logger.addHandler(hdrl)
    logger.setLevel(logging.WARNING)
    and make for them one module or how to solve that?
    How to call that logger from all modules / packages?
    Is it necessary to create alone module?

    2) Is it package necessary or simply modules are enough
    - Replication.py will take care about alone replication
    - Procs.py will take care about some processes
    - Constants.py will take care about definition of global constants
    - Lan.py will take care about LAN definition
    - Dipslay.py will take care about showing screen (GUI or text_based)
    3) How / where to define global variables?

    best regards
    Petr
     
    Stone, Nov 27, 2012
    #1
    1. Advertising

  2. Stone

    goon12 Guest

    On Tuesday, November 27, 2012 3:04:03 AM UTC-5, Stone wrote:
    > Dear developers,
    >
    >
    >
    > I am creating application (originally written in perl)
    >
    > which will take care about replication from one system to the another system over command rsync. It will simulate High-availability solution.
    >
    >
    >
    > The application will contains main module called like ha.py
    >
    > and another modules will have names Replication.py, Trace.py, Misc.py, Procs.py, Constants.py, Lan.py, Display.py
    >
    >
    >
    > My questions are:
    >
    > 1) When I would like to make a global logging to the one file is it enough to do that like
    >
    > TRACE='/var/ha/log/sso_trace.log'
    >
    > logger = logging.getLogger('sso')
    >
    > hdrl = logging.FileHandler(TRACE)
    >
    > formatter = logging.Formatter('%{asctime}s %{levelname}s %{message}s')
    >
    > hdrl.setFormatter(formatter)
    >
    > logger.addHandler(hdrl)
    >
    > logger.setLevel(logging.WARNING)
    >
    > and make for them one module or how to solve that?
    >
    > How to call that logger from all modules / packages?
    >
    > Is it necessary to create alone module?
    >
    >
    >
    > 2) Is it package necessary or simply modules are enough
    >
    > - Replication.py will take care about alone replication
    >
    > - Procs.py will take care about some processes
    >
    > - Constants.py will take care about definition of global constants
    >
    > - Lan.py will take care about LAN definition
    >
    > - Dipslay.py will take care about showing screen (GUI or text_based)
    >
    > 3) How / where to define global variables?
    >
    >
    >
    > best regards
    >
    > Petr


    If you create the logger in your main module and this main module imports the other modules, the logger should be available, to the imported modules, by the name "sso". Now in the other modules, you get the logger using logger = logging.getLogger("sso").

    In the end, I would probably put all these modules in a package and use a logging config file. Define a logger with the same name as your root package and in each module, within the package, just use "logger = logging.getLogger(__name__)"

    http://docs.python.org/2/howto/logging.html#logging-advanced-tutorial
     
    goon12, Nov 28, 2012
    #2
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Parvinder
    Replies:
    6
    Views:
    780
    Thomas G. Marshall
    Feb 27, 2005
  2. Dave
    Replies:
    2
    Views:
    496
  3. George P
    Replies:
    3
    Views:
    709
    Alex Martelli
    Sep 11, 2004
  4. David Pratt
    Replies:
    4
    Views:
    351
    David Pratt
    May 13, 2006
  5. Replies:
    1
    Views:
    15,296
    drobert_bfm
    Nov 27, 2007
Loading...

Share This Page