# -*- coding: utf-8 -*-


"""

self.myLogger       = aController.myLogger
self.myController.log( "closing com", "print"  )



"""


import sys
#from time import sleep


class Logger( object ):
     """
     Log info to both the console and a 
     log file.
     File name currently hardcoded into the application.
     """
    
     def __init__(self,  aController ): 
     
     
          self.myController   = aController
          
          
          self.myLogFileName  = self.myController.myParameters.myLogFile     #      "term.log"
          self.myLogFile      = None           # populate in open 
          self.defaultOut     = "print"        # not implemented
          self.fileopen       = False
          
          
          #print "create Logger"
          
     def log( self, adata, logto ):
         
         """
         *todo use ato   lotto directs output but ignored for now 
         """
         if self.fileopen:
             self.myLogFile.write( adata + "\r\n" )

         print adata 
         sys.stdout.flush()    # try not to let logged info linger
         return 
         
       
     def open(self, ):
         """
         open log file for use
         currently no error checking 
         """
         self.myLogFile = open( self.myLogFileName, "a" )
         self.fileopen  = True
         return 
 

     def close(self, ):
         """
         close the log file
         """
         
         self.myLogFile.close()
         self.fileopen = False
         return 
          
          
          