Author: Not specified Language: text
Description: Not specified Timestamp: 2017-04-30 10:06:14 +0000
View raw paste Reply
  1. #!/usr/bin/env python
  2. # -*- coding: utf-8 -*-
  3.  
  4. # import required modules
  5. import time
  6. import sys
  7.  
  8. # path and name of the log file
  9. logfile = '/var/log/logfile.log'
  10.  
  11. # function to save log messages to specified log file
  12. def log(msg):
  13.  
  14.   # open the specified log file
  15.   file = open(logfile,"a")
  16.  
  17.   # write log message with timestamp to log file
  18.   file.write("%s: %s\n" % (time.strftime("%d.%m.%Y %H:%M:%S"), msg))
  19.  
  20.   # close log file
  21.   file.close
  22.  
  23. # main function
  24. def main():
  25.   # create new log message
  26.   log("Eine neue Nachricht für die Log-Datei")
  27.  
  28.   # quit python script
  29.   sys.exit(0)
  30.  
  31. if __name__ == '__main__':
  32.   main()
  33.  
View raw paste Reply