simple introduction to
In version 2.6 of
It hides complexieties in your application initiation. That is the above code would be something like below without using
As you can see
To add
By setting
#python #cement #framework #logging #log #level #foundation
Cement
framework and its usage. Cement
framework is mostly used for creating a command line application using python
.In version 2.6 of
Cement
you can initiate an app using with
:from cement.core.foundation import CementApp
with CementApp('myapp') as app:
app.run()
It hides complexieties in your application initiation. That is the above code would be something like below without using
with
:from cement.core.foundation import CementApp
app = CementApp('myapp')
app.setup()
app.run()
app.close()
As you can see
with
procedure is more clear and straight forward with less code. I know it's silly to have an app like above, but that's just an introduction to the world of Cement
.To add
logger
to your framework you need to set log level in log.logging
as below:from cement.utils.misc import init_defaults
from cement.core.foundation import CementApp
defaults = init_defaults('myapp', 'log.logging')
defaults['log.logging']['level'] = 'DEBUG'
defaults['log.logging']['file'] = 'cementy.log'
defaults['log.logging']['to_console'] = True
with CementApp('myapp', config_defaults=defaults) as app:
app.run()
app.log.debug('This is debug')
init_defaults
is used to setup logging. level
sets the log level to DEBUG
. file
would write log data into cementy.log
file.By setting
to_console
param you can also write the data written to file into console too. So if you run your python application, a file would be created for logging and data will be printed out.#python #cement #framework #logging #log #level #foundation