## ## Copyright (c) 2006 Jason Dillon ## ## Licensed under the Apache License, Version 2.0 (the "License"); ## you may not use this file except in compliance with the License. ## You may obtain a copy of the License at ## ## http://www.apache.org/licenses/LICENSE-2.0 ## ## Unless required by applicable law or agreed to in writing, software ## distributed under the License is distributed on an "AS IS" BASIS, ## WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. ## See the License for the specific language governing permissions and ## limitations under the License. ## ## ## $Id: //guest/jason_dillon/p4spam/main/pylib/perforce/logging.py#2 $ $Date: 2006/04/12 $ ## TRACE = "TRACE" DEBUG = "DEBUG" INFO = "INFO" WARNING = "WARN" ERROR = "ERROR" FATAL = "FATAL" TRACE_ENABLED = False DEBUG_ENABLED = False import types class Logger: def __init__(this, name): if type(name) == types.StringType: this.name = name else: # Assume we have a Python class try: this.name = name.__class__.__name__ except: try: # Asseume we have a Java class this.name = name.getClass().getName() except: # Esle assume its a string this.name = "%s" % name def log(this, level, message): print "%-5s [%s] %s" % (level[0:5], this.name, message) def isTraceEnabled(this): return TRACE_ENABLED def trace(this, message): if this.isTraceEnabled(): this.log(TRACE, message) def isDebugEnabled(this): return DEBUG_ENABLED def debug(this, message): if this.isDebugEnabled(): this.log(DEBUG, message) def info(this, message): this.log(INFO, message) def warning(this, message): this.log(WARNING, message) def warn(this, message): this.warning(message) def error(this, message): this.log(ERROR, message) def fatal(this, message): this.log(FATAL, message)