Delete unused downloads page asset.
[chromium-blink-merge.git] / ppapi / generators / idl_log.py
blobf5b103e751c4a08ce1575d782155c4ba10ac6e74
1 # Copyright (c) 2012 The Chromium 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.
5 """ Error and information logging for IDL """
7 import sys
10 class IDLLog(object):
11 """Captures and routes logging output.
13 Caputres logging output and/or sends out via a file handle, typically
14 stdout or stderr.
15 """
16 def __init__(self, name, out):
17 if name:
18 self._name = '%s : ' % name
19 else:
20 self._name = ''
22 self._out = out
23 self._capture = False
24 self._console = True
25 self._log = []
27 def Log(self, msg):
28 if self._console:
29 line = "%s\n" % (msg)
30 self._out.write(line)
31 if self._capture:
32 self._log.append(msg)
34 def LogLine(self, filename, lineno, pos, msg):
35 if self._console:
36 line = "%s(%d) : %s%s\n" % (filename, lineno, self._name, msg)
37 self._out.write(line)
38 if self._capture:
39 self._log.append(msg)
41 def SetConsole(self, enable):
42 self._console = enable
44 def SetCapture(self, enable):
45 self._capture = enable
47 def DrainLog(self):
48 out = self._log
49 self._log = []
50 return out
52 ErrOut = IDLLog('Error', sys.stderr)
53 WarnOut = IDLLog('Warning', sys.stdout)
54 InfoOut = IDLLog('', sys.stdout)