Start implementing logging
This commit is contained in:
		
							
								
								
									
										1
									
								
								TODO
									
									
									
									
									
								
							
							
						
						
									
										1
									
								
								TODO
									
									
									
									
									
								
							| @@ -6,5 +6,4 @@ Limit hits/pages/downloads by rate | ||||
| Automatic tests | ||||
| Add Licence | ||||
| Free memory as soon as possible | ||||
| gzip output files | ||||
| different debug output levels | ||||
							
								
								
									
										17
									
								
								iwla.py
									
									
									
									
									
								
							
							
						
						
									
										17
									
								
								iwla.py
									
									
									
									
									
								
							| @@ -9,6 +9,7 @@ import pickle | ||||
| import gzip | ||||
| import importlib  | ||||
| import argparse | ||||
| import logging | ||||
| from calendar import monthrange | ||||
| from datetime import date | ||||
|  | ||||
| @@ -127,6 +128,12 @@ class IWLA(object): | ||||
|                         (conf.POST_HOOK_DIRECTORY    , conf.post_analysis_hooks), | ||||
|                         (conf.DISPLAY_HOOK_DIRECTORY , conf.display_hooks)] | ||||
|  | ||||
|         self.logger = logging.getLogger('iwla') | ||||
|         self.logger.setFormatter(logging.Formatter('%(name)s %(message)s')) | ||||
|  | ||||
|     def setLoggerLevel(self, level): | ||||
|         self.logger.setLevel(level) | ||||
|  | ||||
|     def getVersion(self): | ||||
|         return IWLA.IWLA_VERSION | ||||
|  | ||||
| @@ -651,6 +658,10 @@ if __name__ == '__main__': | ||||
|     parser.add_argument('-f', '--file', dest='file', | ||||
|                         help='Analyse this log file') | ||||
|  | ||||
|     parser.add_argument('-d', '--log-level', dest='loglevel', | ||||
|                         default=logging.INFO, | ||||
|                         help='Loglevel') | ||||
|  | ||||
|     args = parser.parse_args() | ||||
|  | ||||
|     if args.clean_output: | ||||
| @@ -659,6 +670,12 @@ if __name__ == '__main__': | ||||
|  | ||||
|     iwla = IWLA() | ||||
|  | ||||
|     numeric_level = getattr(logging, args.loglevel.upper(), None) | ||||
|     if not isinstance(numeric_level, int): | ||||
|         raise ValueError('Invalid log level: %s' % (args.loglevel)) | ||||
|  | ||||
|     iwla.setLoggerLevel(numeric_level) | ||||
|      | ||||
|     required_conf = ['analyzed_filename', 'domain_name'] | ||||
|     if not validConfRequirements(required_conf, iwla, 'Main Conf'): | ||||
|         sys.exit(0) | ||||
|   | ||||
		Reference in New Issue
	
	Block a user