~rvb/maas/parent-child-relationship

« back to all changes in this revision

Viewing changes to src/provisioningserver/logger/utils.py

  • Committer: MaaS Lander
  • Author(s): Gavin Panella
  • Date: 2015-01-13 20:47:12 UTC
  • mfrom: (3373.4.45 celery-in-dns-removal)
  • Revision ID: maas_lander-20150113204712-h7axs50qohgoc0k8
[r=allenap,jtv][bug=][author=allenap] Remove all remaining Celery dependencies.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# Copyright 2014 Canonical Ltd.  This software is licensed under the
2
 
# GNU Affero General Public License version 3 (see the file LICENSE).
3
 
 
4
 
"""Utilities for logging."""
5
 
 
6
 
from __future__ import (
7
 
    absolute_import,
8
 
    print_function,
9
 
    unicode_literals,
10
 
    )
11
 
 
12
 
str = None
13
 
 
14
 
__metaclass__ = type
15
 
__all__ = [
16
 
    "log_call",
17
 
]
18
 
 
19
 
from functools import wraps
20
 
import logging
21
 
 
22
 
from provisioningserver.logger.log import get_maas_logger
23
 
 
24
 
 
25
 
maaslog = get_maas_logger("calls")
26
 
 
27
 
 
28
 
def log_call(level=logging.INFO):
29
 
    """Log to the maaslog that something happened with a task.
30
 
 
31
 
    :param event: The event that we want to log.
32
 
    :param task_name: The name of the task.
33
 
    :**kwargs: A dict of args passed to the task.
34
 
    """
35
 
    def _decorator(func):
36
 
        @wraps(func)
37
 
        def wrapper(*args, **kwargs):
38
 
            arg_string = "%s %s" % (args, kwargs)
39
 
            maaslog.log(
40
 
                level, "Starting task '%s' with args: %s" %
41
 
                (func.__name__, arg_string))
42
 
            func(*args, **kwargs)
43
 
            maaslog.log(
44
 
                level, "Finished task '%s' with args: %s" %
45
 
                (func.__name__, arg_string))
46
 
        return wrapper
47
 
    return _decorator