blob: 8b608a919a83439f666998b258587853150c9428 [file] [log] [blame]
Gilad Arnoldc65330c2012-09-20 15:17:48 -07001# Copyright (c) 2012 The Chromium OS Authors. All rights reserved.
2# Use of this source code is governed by a BSD-style license that can be
3# found in the LICENSE file.
4
5"""Logging via CherryPy."""
6
7import re
8
9import cherrypy
10
11
12class Loggable(object):
13 """Provides a log method, with automatic log tag generation."""
14 _CAMELCASE_RE = re.compile('(?<=.)([A-Z])')
15
16 def _Log(self, message, *args, **kwargs):
17 return LogWithTag(
18 self._CAMELCASE_RE.sub(r'_\1', self.__class__.__name__).upper(),
19 message, *args, **kwargs)
20
21
22def LogWithTag(tag, message, *args, **kwargs):
23 # CherryPy log doesn't seem to take any optional args, so we'll just join
24 # them into a single string, if any are provided.
25 return cherrypy.log(message + ((' ' + ' '.join(args)) if args else ''), tag)