Module Log
[hide private]
[frames] | no frames]

Source Code for Module Log

 1  ##################################################################### 
 2  # -*- coding: iso-8859-1 -*-                                        # 
 3  #                                                                   # 
 4  # Frets on Fire                                                     # 
 5  # Copyright (C) 2006 Sami Kyöstilä                                  # 
 6  #                                                                   # 
 7  # This program is free software; you can redistribute it and/or     # 
 8  # modify it under the terms of the GNU General Public License       # 
 9  # as published by the Free Software Foundation; either version 2    # 
10  # of the License, or (at your option) any later version.            # 
11  #                                                                   # 
12  # This program is distributed in the hope that it will be useful,   # 
13  # but WITHOUT ANY WARRANTY; without even the implied warranty of    # 
14  # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the     # 
15  # GNU General Public License for more details.                      # 
16  #                                                                   # 
17  # You should have received a copy of the GNU General Public License # 
18  # along with this program; if not, write to the Free Software       # 
19  # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,        # 
20  # MA  02110-1301, USA.                                              # 
21  ##################################################################### 
22   
23  import sys 
24  import os 
25  import Resource 
26   
27  quiet = True 
28  logFile = open(os.path.join(Resource.getWritableResourcePath(), "fretsonfire.log"), "w") 
29  encoding = "iso-8859-1" 
30   
31  if "-v" in sys.argv: 
32    quiet = False 
33     
34  if os.name == "posix": 
35    labels = { 
36      "warn":   "\033[1;33m(W)\033[0m", 
37      "debug":  "\033[1;34m(D)\033[0m", 
38      "notice": "\033[1;32m(N)\033[0m", 
39      "error":  "\033[1;31m(E)\033[0m", 
40    } 
41  else: 
42    labels = { 
43      "warn":   "(W)", 
44      "debug":  "(D)", 
45      "notice": "(N)", 
46      "error":  "(E)", 
47    } 
48   
49 -def log(cls, msg):
50 msg = unicode(msg).encode(encoding, "ignore") 51 if not quiet: 52 print labels[cls] + " " + msg 53 print >>logFile, labels[cls] + " " + msg
54 55 warn = lambda msg: log("warn", msg) 56 debug = lambda msg: log("debug", msg) 57 notice = lambda msg: log("notice", msg) 58 error = lambda msg: log("error", msg) 59