Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Python > Modules or Package for my application

Reply
Thread Tools

Modules or Package for my application

 
 
Stone
Guest
Posts: n/a
 
      11-27-2012
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
 
Reply With Quote
 
 
 
 
goon12
Guest
Posts: n/a
 
      11-28-2012
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/loggi...anced-tutorial
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Disabling modules using Modules/Setup Ben Weintraub Python 0 09-09-2006 12:04 AM
Importing a package and looping through modules in the package Dave Python 2 02-10-2004 08:14 PM
Importing modules from within other modules Tobiah Python 2 09-14-2003 09:18 PM
imputils - import problem modules from sys.modules Remy Cool Python 1 08-27-2003 02:25 PM



Advertisments