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. Advertisements

  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. Advertisements

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. Remy Cool
    Replies:
    1
    Views:
    553
    Remy Cool
    Aug 27, 2003
  2. Tobiah
    Replies:
    2
    Views:
    419
    Tobiah
    Sep 14, 2003
  3. Dave
    Replies:
    2
    Views:
    610
  4. Ben Weintraub

    Disabling modules using Modules/Setup

    Ben Weintraub, Sep 9, 2006, in forum: Python
    Replies:
    0
    Views:
    475
    Ben Weintraub
    Sep 9, 2006
  5. Peter Peyman Puk

    Importing v reloading modules modules

    Peter Peyman Puk, Mar 19, 2010, in forum: Python
    Replies:
    0
    Views:
    423
    Peter Peyman Puk
    Mar 19, 2010
  6. Trans
    Replies:
    0
    Views:
    192
    Trans
    Jul 29, 2005
  7. Tim Olsen

    modules including other modules

    Tim Olsen, May 29, 2007, in forum: Ruby
    Replies:
    4
    Views:
    263
    Adriano Mitre
    Jan 20, 2011
  8. Mark Wilden
    Replies:
    5
    Views:
    304
    Rick DeNatale
    May 15, 2008
Loading...