Return to Snippet

Revision: 66293
at April 12, 2014 01:35 by JordanRowles


Updated Code
# SocketServer_Logging.py
# Version: 1.0
# Use: Internal Application (Work)
# Purpose: To provide logging methods and classes for the logging server.
# Copyright (C)2014 Jordan Rowles
# GNU General Public License Version 3 or Later

import logging as log

def customLogger(name):
	formatter = logging.Formatter(fmt="%(asctime)s - %(levelname)s - %(module)s - %(message)s")
	handler = logging.StreamHandler()
	handler.setFormatter(formatter)
	logger = logging.getLogger(name)
	logger.setLevel(logging.DEBUG)
	logger.addHandler(handler)
	return logger

'''
USE:
* Module1.py *
import LoggingForServer as Log
logger = Log.setup_custom_logger('root')
logger.debug('Module1 Message')
import Module2
* Module2.py *
import LoggingForServer as Log
logger = logging.getLogger('root')
logger.debug('Module2 Message')

* OUTPUT *
2014-04-11 20:08:40,049 - DEBUG - Module1 - Module1Message
2014-04-11 20:08:40,050 - DEBUG - Module2 - Module2Message
'''

Revision: 66292
at April 12, 2014 01:27 by JordanRowles


Initial Code
import logging as log

def customLogger(name):
	formatter = logging.Formatter(fmt="%(asctime)s - %(levelname)s - %(module)s - %(message)s")
	handler = logging.StreamHandler()
	handler.setFormatter(formatter)
	logger = logging.getLogger(name)
	logger.setLevel(logging.DEBUG)
	logger.addHandler(handler)
	return logger

'''
USE:
* Module1.py *
import LoggingForServer as Log
logger = Log.setup_custom_logger('root')
logger.debug('Module1 Message')
import Module2
* Module2.py *
import LoggingForServer as Log
logger = logging.getLogger('root')
logger.debug('Module2 Message')

* OUTPUT *
2014-04-11 20:08:40,049 - DEBUG - Module1 - Module1Message
2014-04-11 20:08:40,050 - DEBUG - Module2 - Module2Message
'''

Initial URL
SocketServer-Logging

Initial Description
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.

Initial Title
SocketServer_Logging.py

Initial Tags
data, server, log

Initial Language
Python