Modules or Package for my application


S

Stone

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
 
Ad

Advertisements

G

goon12

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
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top