| Home | Trees | Indices | Help |
|
|---|
|
|
1 #!/usr/bin/env python
2 # -*- coding: utf-8 -*-
3 """
4 This module contains output and logging utilities.
5 """
6
7 # Copyright (C) 2008 Martin Sandve Alnes and Simula Resarch Laboratory
8 #
9 # This file is part of SyFi.
10 #
11 # SyFi is free software: you can redistribute it and/or modify
12 # it under the terms of the GNU General Public License as published by
13 # the Free Software Foundation, either version 2 of the License, or
14 # (at your option) any later version.
15 #
16 # SyFi is distributed in the hope that it will be useful,
17 # but WITHOUT ANY WARRANTY; without even the implied warranty of
18 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 # GNU General Public License for more details.
20 #
21 # You should have received a copy of the GNU General Public License
22 # along with SyFi. If not, see <http://www.gnu.org/licenses/>.
23 #
24 # First added: 2008-09-03
25 # Last changed: 2008-09-03
26
27 import logging
28
29 # Logging wrappers
30
31 _log = logging.getLogger("sfc")
32 _loghandler = logging.StreamHandler()
33 _log.addHandler(_loghandler)
34 _log.setLevel(logging.WARNING)
35 #_log.setLevel(logging.DEBUG)
36
38 return _loghandler
39
41 return _log
42
44 global _loghandler
45 _log.removeHandler(_loghandler)
46 _loghandler = handler
47 _log.addHandler(_loghandler)
48
50 if isinstance(level, str):
51 level = level.upper()
52 assert level in ("INFO", "WARNING", "ERROR", "DEBUG")
53 level = getattr(logging, level)
54 else:
55 assert isinstance(level, int)
56 _log.setLevel(level)
57
58 # Aliases for calling log consistently:
59
61 _log.debug(*message)
62
64 _log.info(*message)
65
67 _log.warning(*message)
68
73
75 if not condition:
76 _log.error(*message)
77 text = message[0] % message[1:]
78 raise AssertionError(text)
79
80 # Utility functions for file handling:
81
83 "Write text to a file and close it."
84 try:
85 f = open(filename, "w")
86 f.write(text)
87 f.close()
88 except IOError, e:
89 sfc_error("Can't open '%s': %s" % (filename, e))
90
| Home | Trees | Indices | Help |
|
|---|
| Generated by Epydoc 3.0.1 on Thu Jan 31 03:52:26 2013 | http://epydoc.sourceforge.net |