Nagare

Latest version: v0.5.1

Safety actively analyzes 621907 Python packages for vulnerabilities to keep your Python projects secure.

Scan your dependencies

0.5.0

-----

- Project only hosted on Github now
- Documentation served as github.io pages
- Documentation generated with Sphinx
- Documentations added:

- internationalization
- ``nagare.wsgi.WSGIApp``
- application deployment
- log service

- Running now on Stackless, Pypy (experimental) and CPython (with limitations)
- Request and Response object factories added
- Improved components garbage collector
- Callbacks registered with ``.action()`` and ``.answer()`` can have parameters and keywords
- No more ``lambda`` for the validators
(``lambda v: IntValidator(v).greater_than(10)`` => ``IntValidator().greater_than(10)``)
- Translation *domain* added to the i18n service API
- Custom ``data-*`` HTML5 attributes can be created as ``data_*`` keywords
- The ``<div>`` automatically added in the asynchronous views have the
``nagare-generated`` and ``nagare-async-view`` classes

0.4.1

-----

Bugs fixed
~~~~~~~~~~

- 1516: `nagare-admin create-app` command not working with Stackless Python < 2.7

0.4.0

-----

New features
~~~~~~~~~~~~

- Mercurial migration
- new site, examples and documentation design
- tutorial
- i18n service (messages catalogs, HTTP language negotiation, timezones, dates, currencies, numbers ...)
- multiprocess / thread scopes differences handled by the new :mod:`nagare.local` service
- HTML5 renderer (:class:`nagare.namespaces.xhtml5.Renderer`)
- user impersonnalisation (stackable user objects)
- stackable security rules
- standalone publisher threads pool fully configurable
- dummy sessions manager for completly Restful applications (no state kept on the server)
- fastcgi over unix socket
- the DOCTYPE can be changed
- the content type of an XML response can be changed
- configurable default initial renderer
- relative logger names
- ``nagare-admin shell`` prompt displays the name of the application
- application name can be inserted as ``$name`` in the configuration file

Changes
~~~~~~~

- A renderer can create an asynchronous renderer:
``comp.render(xhtml.AsyncRenderer())`` => ``comp.render(h.AsyncRenderer())``
- New versions of YUI, IPython, SQLAlchemy, lxml and WebOb

Bugs fixed
~~~~~~~~~~

- client disconnection detection added for comet streams
- 51: javascript executed multiple times
- 52: more informations for the ``AnswerWithoutCall`` exception
- 53: a ``component.Task`` must exit on ``answer()`` if a ``on_answer()`` was set
- 54: log service not initialized
- 55: xhtml ``select`` and ``option``: problem with integer
- 66: serializer can't serialize an empty DOM
- 67: serializer can't serialize a fragment (a list of DOM)
- 1298: bad generation of pure ``href`` anchor
- 1442: bad Javascript translation of Python methods
- 1443: error when the default initial renderer is asynchronous
- 1444: ajax error when no HTML is rendered
- 1447: ``IntValidator`` does not catch ``TypeError``
- 1498: tutorial errors
- 1502: incorrect ``memory`` sessions manager
- 1508: error with the latest IPython version
- 1509: ``data_path`` not initialized
- 1510: bad checkbox values in ajax
- 1511: SQLAlchemy engines creation fully configurable

0.3.0

-----

New features
~~~~~~~~~~~~

- refactoring of the sessions managers:

- session objects now keep track of their sessions manager
- no more sessions manager factories
- configurable pickler / unpickler objects
- configuration switch ``states_history`` to set if an objects graphs history must be kept
- new sessions manager (``type=memory``) that keeps the objects graphs in memory, without any pickling
- logging service added:

- one dedicated logger for each published applications is created
- easy configuration and use of this dedicated logger
- all the ``[logging]`` sections of all the published applications are merged before to configure the Python logging system
- preliminary Comet support added (currently only working in a multi-threaded env.)
- last exception raised kept by the ``WSGIApp`` objects and exception hook added
- ``with_request`` parameter added to all the callback registrations and ``Update()`` objects
- translation of Python modules to Javascript added
- configurable name for the security cookie (one of the post Nagare security audit actions)
- configuration of the ``WSGIApp`` objects split accross multiples `set_*`` methods
- ``get_registered_applications()`` added to the publisher objects
- full YUI bundled with Nagare
- New versions:

- Stackless Python 2.6.4 is now the recommanded Python version
- virtualenv updated to 1.4.5
- SQLAlchemy updated to 0.5.8
- Elixir updated to 0.7.1
- Lxml updated to 2.2.4
- YUI updated to 2.8.0r4

Changes
~~~~~~~

- with the YUI connection manager, a large browser response must be reassembled (Firefox only)
- late creation of the SQLAlchemy database engines and metadatas binding
- input fields ot type ``button`` now working in an Ajax submit
- ``Var.var()`` now working in a unicode context
- ``nagare-admin create-rules`` had problems when a static directory didn't exist
- bad boolean expressions parenthesis translation in pyjs fixed
- parsing (X)HTML from URL now working under Windows

Bugs fixed
~~~~~~~~~~

- 47: ``set_publisher()`` called when using "nagare-admin create-db"
- 48: py2js parentheses bug
- 49: ``reset`` configuration ignored by the memcached sessions manager
- 50: [log] inferred caller is wrong

0.2.0

-----

Python Stackless 2.6.2 is now the recommanded Python version.

New features
~~~~~~~~~~~~

- When an AJAX update contains CSS or Javascript urls, they are correctly fetched.
- Multiple AJAX updates object added
- Session lock added (distributed lock when memcached is used)
- A session can now contains SQLAlchemy (and Elixir) entities
- LRU management of the sessions and continuations
- ``nagare-admin create-rules`` administrative command added.
Generation of the Apache / lighttpd / ngnix rewrite rules to serve the statics
contents. See :doc:`nagare-admin`
- ``nagare-admin batch`` administrative command added. To execute Python
statements. See :doc:`nagare-admin`
- Easy WSGI pipe creation
- An application can now be registered under several urls
- The automatic reloader can be configured with a list of files to watch
- API to logout and change the user identity/password added
- automatic generation of a ``link(rel="canonical" ...)`` in the page header
as an alias without the session and continuation parameters
- ``min_compress_len`` parameter added in the memcached configuration
- YUI AJAX modules updated to 2.7.0
- SQLAlchemy updated to 0.5.x

Changes
~~~~~~~

- Complete refactoring of the AJAX communication. The "wire" format is now Javascript.
- ``component.Component.init()`` and ``presentation.init_for()`` API changes.
See :doc:`restful`

Bugs fixed
~~~~~~~~~~

- 19, 23, 26: race condition in the sessions management
- 22: don't clear the registered callbacks when an image is served
- 21: set the security context at the beginning of the request handling
- 13, 14: python to javascript translation updated

0.1.0

-----

Initial release



The log service
===============

It's often useful to log some information during the execution of a Web
application to trace the execution of the requests and to provide useful
information for debugging when something goes wrong. The most common use-case is
to log the exceptions tracebacks to a file on the server that provide the context
where the error occurred so that we can fix the problem without disclosing
sensitive information to the end-users.

Python ships with a `logging`_ module that provides everything we need in a Web
development context. However, it is relatively complex to configure and it's
configuration is a singleton, which is problematic in a multi-applications setup
(that is, when the same ``nagare-admin serve`` process serves more than one
application).

In order to solve these problems, Nagare provides its own :mod:`nagare.log` service
, which is built on top of the `logging`_ module but greatly
simplifies its usage and configuration for common use-cases.


Basic Usages
------------

Using The default logger
~~~~~~~~~~~~~~~~~~~~~~~~

By default, when you serve Web applications with the ``nagare-admin serve``
utility, Nagare creates a dedicated logger, handler and formatter for each
application, and activates them: this is the purpose of the
:class:`nagare.log.configure` and :class:`nagare.log.activate` functions.

You can use the module level functions of the ``log`` module to write messages
to the default logger of the *currently running* application, as shown in the
example below:

.. code-block:: python
:emphasize-lines: 8

from nagare import presentation, log

class Root(object):
pass

presentation.render_for(Root)
def render(self, h, *args):
log.info('Rendering the Root component')
some rendering code...
return h.root

app = Root


Then, each time the default view of the ``Root`` component is rendered, this
line should appear in the console shell (which is the output of the default
logger):

.. code-block:: text

2012-06-14 10:22:38,379 - nagare.application.myapp - INFO - Rendering the root component

As you see, the messages are issued in the ``nagare.application.myapp``
namespace, which is the namespace of the messages coming from the Nagare
application called ``myapp``.

Here is the full listing of the module-level functions of the ``nagare.log``
module:

====================================== =================================================================
Function Effect
====================================== =================================================================
``log.debug(msg, *args, **kw)`` Logs a message with ``DEBUG`` level on the application logger
``log.info(msg, *args, **kw)`` Logs a message with ``INFO`` level on the application logger
``log.warning(msg, *args, **kw)`` Logs a message with ``WARNING`` level on the application logger
``log.error(msg, *args, **kw)`` Logs a message with ``ERROR`` level on the application logger
``log.critical(msg, *args, **kw)`` Logs a message with ``CRITICAL`` level on the application logger
``log.exception(msg, *args, **kw)`` Logs a message with ``ERROR`` level on the application logger,
and also logs the current exception information
``log.log(level, msg, *args, **kw)`` Logs a message with the specified level on the application
logger
====================================== =================================================================

All these functions accept variable arguments and keyword arguments, which are
documented in the ``logging`` module, `here <https://docs.python.org/2/library/logging.htmllogging.Logger.debug>`_.

Overriding the default configuration
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

The ``[[logger]]``, ``[[hander]]`` and ``[[formatter]]`` sub-sections of the
``[logging]`` section in the application configuration file are dedicated to
configure the default application logger.

The default logging setup is equivalent to the following ``[logging]`` section,
where ``<name>`` is replaced by the name of the application (please
refer to the ``logging``'s module `configuration file format`_ for a better
understanding of the configuration of loggers, handlers and formatters):

.. code-block:: ini

[logging]

[[logger]]
qualname=nagare.application.<name>
level=INFO
propagate=1

[[handler]]
class=StreamHandler
args=(sys.stderr,)

[[formatter]]
format=%(asctime)s - %(name)s - %(levelname)s - %(message)s

As you can see, by default, the log messages with a level greater or equal to
``INFO`` are printed to ``sys.stderr`` via a ``StreamHandler``.

It's possible to override this default ``logging`` configuration by adding your
own ``[logging]`` section to the application configuration file. Here, the
logging level of the application is set to ``DEBUG``:

.. code-block:: ini

[logging]
[[logger]]
level=DEBUG

Here, a new handler is defined to log the messages to the file ``/tmp/myapp.log``.
We use a ``RotatingFileHandler`` instead of the classical ``FileHandler`` since
we want the file to be log-rotated in order to prevent it from becoming too large:

.. code-block:: ini

[logging]
[[handler]]
class=handlers.RotatingFileHandler
args="('/tmp/myapp.log', 'a', 10485760, 10, 'UTF-8')"

Using the Nagare IDE
~~~~~~~~~~~~~~~~~~~~

When the Nagare IDE is launched at the same time than your application
(i.e ``nagare-admin serve <name> ide``), a second handler is bound to the default
logger so that all the messages are also sent to the
`IDE log panel <http://www.nagare.org/trac/wiki/NagareIdelogger>`_.

Advanced Usages
---------------

Creating other application loggers
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

As seen above, Nagare makes it easy to log messages in an application. However,
as your application becomes more complex and is broken down in several modules
and packages, it may become hard to track down where you sent a particular message
or to analyze the log file which is now filled with numerous log messages.

In this situation, it's generally useful to organize the log messages into
namespaces, so that we can enable/disable the logging of messages in some
namespaces or send messages with different namespaces to different handlers.

For this purpose, Nagare offers a ``log.get_logger(namespace)`` function that
creates a logger which puts the messages into the specified namespace. To create a
new logger for your application, use a relative name starting with a dot. In this
case, the new namespace is relative to the application namespace, e.g.
``nagare.application.myapp``.

The logger object offers the same functions as the ``log`` module for writing
messages, that is ``logger.debug``, ``logger.info``, ``logger.warning``,
``logger.error``, ``logger.critical``, ``logger.exception`` and ``logger.log``,
with the same parameters.

In this example, we will log all the messages generated in the views to a
specific ``nagare.application.myapp.ui`` namespace:

.. code-block:: python

from nagare import log

presentation.render_for(Root)
def render(self, h, *args):
log.get_logger('.ui').debug('Rendering the Root component')
some rendering code...
return h.root

and you can see, the message is now attached to the ``nagare.application.myapp.myapp.ui``
namespace:

.. code-block:: text

2012-06-14 10:22:38,379 - nagare.application.myapp.ui - INFO - Rendering the root component

Being under the ``nagare.application.myapp`` namespace, this logger propagates
the messages to the default logger. Also this logger inherits the default logger
configuration, which can be overridden:

.. code-block:: ini

[[logging]]
[loggers]
keys=ui Declare the new logger

[[logger_ui]]
qualname=.ui Relative namespace
level=CRITICAL
No specific handler: propagate the messages to the default application logger
handlers=

Here the log level of the logger is set to ``CRITICAL``.

Or a more complex configuration can be created, for example to log the messages
to a specific log file:

.. code-block:: ini

[logging]
[[loggers]]
keys=ui Declare the new logger

[[handlers]]
keys=logfile Declare the new handler

[[formatters]]
keys=simple Declare the new formatter

[[logger_ui]]
qualname=.ui Relative namespace
handlers=logfile
propagate=0 Don't propagate the messages to the default application logger

[[handler_logfile]]
class=handlers.RotatingFileHandler
args="('/tmp/myapp_ui.log', 'a', 10485760, 10, 'UTF-8')" Specific log file
formatter=simple

[[formatter_simple]]
format=%(levelname)s: %(message)s

Creating other loggers
~~~~~~~~~~~~~~~~~~~~~~

Any other general loggers can be created the same way, by just giving a full
absolute namespace.

For example the `SQLAlchemy documentation <http://docs.sqlalchemy.org/en/latest/core/engines.htmlconfiguring-logging>`_
states the name of the SQL query logger is ``sqlalchemy.engine``. So this
logging configuration will display all the generated SQL queries:

.. code-block:: ini

[logging]
[[loggers]]
keys=sa

[[handlers]]
keys=stderr

[[formatters]]
keys=multilines

[[logger_sa]]
qualname=sqlalchemy.engine The absolute SQLAlchemy logger namespace
level=INFO
handlers=stderr

[[handler_stderr]]
class=StreamHandler
args=(sys.stderr,)
formatter=multilines

[[formatter_multilines]]
format={ %(message)s }


.. _`logging`: https://docs.python.org/2/library/logging.html
.. _`Configuration file format`: https://docs.python.org/2/library/logging.config.htmlconfiguration-file-format

Links

Releases

© 2024 Safety CLI Cybersecurity Inc. All Rights Reserved.