Advertisement
codemonkey

Untitled

Sep 23rd, 2011
220
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.62 KB | None | 0 0
  1. import os, datetime
  2.  
  3. def log(path, data):
  4.  
  5.     # Input path should be a folder
  6.     if(os.path.isfile(path)):
  7.         raise Exception("Input path leeds to a file. Expected a directory")
  8.    
  9.     # Make folder if it doesn't exist
  10.     if(not os.path.exists(path)):
  11.         # Create the path
  12.         os.makedirs(path)
  13.    
  14.     # Make filename
  15.     time = datetime.datetime.now().strftime("%Y-%m-%d-%H-%M-%S-%f")
  16.     filepath = os.path.join(path, time + ".log")
  17.    
  18.     # Write
  19.     file = open(filepath, "w")
  20.     file.write(data.__str__() + "\n")
  21.     file.close()
  22.    
  23.     return True
  24.  
  25. # Testing
  26. if(__name__ == "__main__"):
  27.     log("/temp/logger", ["support", "for", "arrays"].__str__())
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement