Posted By


JordanRowles on 04/12/14

Tagged


Statistics


Viewed 1072 times
Favorited by 0 user(s)

SocketServer_Logging.py


/ Published in: Python
Save to your folder(s)

These logging functions will be improved and added into the SocketServer_Server.py to log information from programs on machines on the same network, but not directly connected to each other.


Copy this code and paste it in your HTML
  1. # SocketServer_Logging.py
  2. # Version: 1.0
  3. # Use: Internal Application (Work)
  4. # Purpose: To provide logging methods and classes for the logging server.
  5. # Copyright (C)2014 Jordan Rowles
  6. # GNU General Public License Version 3 or Later
  7.  
  8. import logging as log
  9.  
  10. def customLogger(name):
  11. formatter = logging.Formatter(fmt="%(asctime)s - %(levelname)s - %(module)s - %(message)s")
  12. handler = logging.StreamHandler()
  13. handler.setFormatter(formatter)
  14. logger = logging.getLogger(name)
  15. logger.setLevel(logging.DEBUG)
  16. logger.addHandler(handler)
  17. return logger
  18.  
  19. '''
  20. USE:
  21. * Module1.py *
  22. import LoggingForServer as Log
  23. logger = Log.setup_custom_logger('root')
  24. logger.debug('Module1 Message')
  25. import Module2
  26. * Module2.py *
  27. import LoggingForServer as Log
  28. logger = logging.getLogger('root')
  29. logger.debug('Module2 Message')
  30.  
  31. * OUTPUT *
  32. 2014-04-11 20:08:40,049 - DEBUG - Module1 - Module1Message
  33. 2014-04-11 20:08:40,050 - DEBUG - Module2 - Module2Message
  34. '''

URL: SocketServer-Logging

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.