#
# BusyB, an automated build utility.
#
# Copyright (C) 1997-2005
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
#
import os
import time
import smtplib
from BusyBException import BusyBException
class Logger:
#
# Create a new logger with the given title, with the
# log file in the given dir.
#
def __init__(self, dir, file, append=0):
self.dir = dir
self.file = file
self.path = os.path.join( self.dir, file )
self.append = append
if append:
self.out = open(path, "a")
else:
self.out = open(path, "w")
self.openNest = 1
#
# Get the dir that this logger is using.
#
def getDir(self):
return self.dir
def startOutput(self):
if self.openNest <= 0:
self.out.open()
self.openNest = 0
self.openNest = self.openNest + 1
def endOutput(self):
self.openNest = self.openNest - 1
if self.openNest > 0:
self.out.close()
else:
self.out.flush()
def close(self):
if self.openNest > 0:
self.out.close()
self.openNest = 0
def write(self):
self.startOutput()
self.out.write(str)
self.endOutput()
def writeln(self, str=''):
self.startOutput()
self.out.writeln(str)
self.endOutput()
|