Module Expr Str ImportFrom alias Import alias Import alias Import alias ImportFrom alias FunctionDef arguments args NameParam NameParam defaults kwarg body Expr Call AttributeLoad NameLoad attr Str Str If CompareEq AttributeLoad NameLoad attr Str body Assign NameStore AttributeLoad NameLoad attr orelse Assign NameStore NameLoad Assign NameStore Call NameLoad NameLoad NameLoad Assign NameStore Call AttributeLoad NameLoad attr keyword Str keyword Str Expr Call AttributeLoad NameLoad attr NameLoad Return NameLoad decorator_list FunctionDef arguments args NameParam defaults body Expr Str If Call NameLoad NameLoad Str NameLoad body Assign NameStore Str Expr Call AttributeLoad NameLoad attr NameLoad Return Assign AttributeStore NameLoad attr NameLoad Assign NameStore Call AttributeLoad NameLoad attr Str NameLoad If UnaryOpNot NameLoad body Return Assign NameStore Call AttributeLoad NameLoad attr Str Assign NameStore Call AttributeLoad NameLoad attr Str ImportFrom alias Assign NameStore Call AttributeLoad NameLoad attr Str NameLoad Assign NameStore Call AttributeLoad NameLoad attr Str NameLoad Assign NameStore Call AttributeLoad NameLoad attr Str NameLoad Assign NameStore Call NameLoad NameLoad Call AttributeLoad Call AttributeLoad NameLoad attr Str Str attr If Call NameLoad NameLoad NameLoad body Assign NameStore Call AttributeLoad NameLoad attr Assign NameStore ListComp Call AttributeLoad NameLoad attr NameLoad comprehension NameStore NameLoad For NameStore NameLoad body Expr Call AttributeLoad NameLoad attr NameLoad Assign NameStore Call NameLoad keyword NameLoad Expr Call AttributeLoad NameLoad attr AttributeLoad NameLoad attr For NameStore NameLoad body Expr Call AttributeLoad NameLoad attr NameLoad If CompareNotIn Str NameLoad body Expr Call AttributeLoad NameLoad attr NameLoad If NameLoad body TryExcept body If Call AttributeLoad AttributeLoad NameLoad attr attr body Assign NameStore Call AttributeLoad NameLoad attr If CompareIsNot NameLoad NameLoad body Expr Call AttributeLoad NameLoad attr AttributeLoad NameLoad attr Assign NameStore Call AttributeLoad NameLoad attr keyword Str Expr Call AttributeLoad NameLoad attr NameLoad For NameStore NameLoad body Expr Call AttributeLoad NameLoad attr NameLoad handlers ExceptHandler type NameLoad body Expr Call AttributeLoad NameLoad attr Str If CompareIsNot NameLoad NameLoad body TryExcept body Assign NameStore Dict For NameStore TupleLoad Str Str body If CompareIn NameLoad NameLoad body Assign SubscriptStore NameLoad Index NameLoad SubscriptLoad NameLoad Index NameLoad Assign NameStore Call NameLoad NameLoad NameLoad NameLoad For NameStore NameLoad body Expr Call AttributeLoad NameLoad attr NameLoad handlers ExceptHandler type NameLoad name NameStore body Raise Call NameLoad BinOpMod Str TupleLoad NameLoad NameLoad decorator_list
N/A N/A Provides the default logging configuration interface shipped with
Lino applications for out-of-the-box usage in typical situations.
    
It defines a function :func:`configure` which will be called by Django
when you have your :setting:`LOGGING_CONFIG` set to
``'lino.utils.log.configure'`` (the default value set when you
instantiate a :class:`lino.site.Site`)

In order to disable Lino's system, you can either set
:setting:`LOGGING_CONFIG` to your own value, you configure logging
yourself manually *before* Lino starts. For example by writing at the
begnning of your :xfile:`manage.py` file::

    import logging
    logging.basicConfig(level=logging.INFO)

Or when you want to log things that happen *before* Django calls
:func:`lino.utils.log.configure`, then you must also manually
configure logging.

Examples
--------

A simple common example::

  LOGGING = dict(filename='/var/log/lino/system.log',level='INFO')

Another example using :attr:`lino.core.site.Site.project_dir`::

  ...
  SITE = Site(globals())
  ...
  LOGGING = dict(
      filename=join(SITE.project_dir, 'log', 'system.log'),
      level='DEBUG')


The following example to use date-based log files is **not
recommended** since the filename is computed once per process, causing
a long-running server process to log to an old file even though a
newer file might have been created by another process::

  import datetime
  filename = datetime.date.today().strftime('/var/log/lino/%Y-%m-%d.log')
  LOGGING = dict(filename=filename,level='DEBUG',rotate=False)


Logfile rotation
----------------

Django applications cannot use Python-based **Logfile rotation** since
with Django it is possible to have several processes using the same
:xfile:`settings.py` file.  That would sooner or later cause problems
when they all try to rotate at the same time.

On Linux systems, Lino uses WatchedFileHandler so that system
administrators can install system-wide log rotation with `logrotate`.


Remarks
-------

Yes, we read the `mod_wsgi documentation
<http://code.google.com/p/modwsgi/wiki/ApplicationIssues>`_ saying
"code should ideally not be making assumptions about the environment
it is executing in, eg., whether it is running in an interactive mode,
by asking whether standard output is a tty. In other words, calling
'isatty()' will cause a similar error with mod_wsgi. If such code is a
library module, the code should be providing a way to specifically
flag that it is a non interactive application and not use magic to
determine whether that is the case or not.".  Any comments are
welcome.

See also :srcref:`docs/tickets/15`

 past.builtins basestring N/A os N/A sys N/A logging logging.handlers WatchedFileHandler file_handler N/A N/A filename rotate N/A kw N/A N/A N/A N/A kw setdefault encoding UTF-8 N/A N/A N/A sys platform win32 N/A N/A cl N/A logging FileHandler N/A N/A cl WatchedFileHandler N/A h N/A cl filename kw N/A fmt N/A N/A logging Formatter fmt %(asctime)s %(levelname)s %(module)s : %(message)s datefmt %Y%m-%d %H:%M:%S N/A N/A N/A h setFormatter fmt N/A h N/A configure N/A N/A config N/A N/A N/A When using Lino's default method, the :setting:`LOGGING` setting in
your :xfile:`settings.py` must be a dictionary containing the
parameters you want to set.  Available parameters are:

:param logfile:  the full path of the lino `system.log` file.
                 If absent or `None`, there will be no `system.log` file.
                 
:param level:    the overall verbosity level for both console and logfile.
:param mode:     the opening mode for the logfile
:param encoding: the encoding for the logfile
:param tty:      whether to install a default logger to the terminal

:param logger_names:  A list or tuple of names of loggers to configure.
                      If this is a string, Lino converts it to a list 
                      (expecting it to be a space-separated list of names).
                      Default value is 'lino'.
                 
If there is a logfile, then console messages will never be more
verbose than INFO because too many messages on the screen are
disturbing, and if the level is DEBUG you will better analyze them in
the logfile.

Automatically adds an AdminEmailHandler with level ERROR to all
specified loggers *and* to the 'django' logger (even if 'django' is
not specified in `loggers`).  Because that's rather necessary on a
production server with :setting:`DEBUG` False.

     N/A N/A getattr logging set_up_done False N/A N/A msg Not changing the existing logging configuration. N/A N/A N/A logging info msg N/A N/A N/A logging set_up_done True N/A logger_names N/A N/A config get logger_names None N/A N/A logger_names N/A N/A N/A djangoLogger N/A N/A logging getLogger django N/A linoLogger N/A N/A logging getLogger lino django.utils.log AdminEmailHandler N/A logfile N/A N/A config get filename None N/A rotate N/A N/A config get rotate True N/A tty N/A N/A config get tty True N/A level N/A getattr logging N/A N/A N/A N/A config get level notset upper N/A N/A isinstance logger_names basestring N/A N/A logger_names N/A N/A logger_names split N/A loggers N/A N/A N/A logging getLogger n N/A n logger_names N/A l loggers N/A N/A N/A N/A l setLevel level N/A aeh N/A AdminEmailHandler include_html True N/A N/A N/A aeh setLevel N/A logging ERROR N/A l loggers N/A N/A N/A N/A l addHandler aeh N/A N/A django logger_names N/A N/A N/A N/A djangoLogger addHandler aeh N/A tty N/A N/A N/A N/A N/A N/A N/A sys stdout isatty N/A N/A h N/A N/A logging StreamHandler N/A N/A logfile None N/A N/A N/A N/A h setLevel N/A logging INFO N/A fmt N/A N/A logging Formatter fmt %(levelname)s %(message)s N/A N/A N/A h setFormatter fmt N/A l loggers N/A N/A N/A N/A l addHandler h N/A N/A N/A IOError N/A N/A N/A N/A linoLogger info mod_wsgi mode (no sys.stdout) N/A N/A logfile None N/A N/A N/A N/A kw N/A N/A k N/A mode encoding N/A N/A N/A k config N/A N/A N/A kw N/A k N/A config N/A k N/A h N/A file_handler logfile rotate kw N/A l loggers N/A N/A N/A N/A l addHandler h N/A N/A N/A IOError N/A e N/A N/A N/A Exception N/A Failed to create log file %s : %s N/A logfile e N/A