comparison TEisotools-1.0/commons/core/LoggerFactory.py @ 6:20ec0d14798e draft

Uploaded
author urgi-team
date Wed, 20 Jul 2016 05:00:24 -0400
parents
children
comparison
equal deleted inserted replaced
5:4093a2fb58be 6:20ec0d14798e
1 # Copyright INRA (Institut National de la Recherche Agronomique)
2 # http://www.inra.fr
3 # http://urgi.versailles.inra.fr
4 #
5 # This software is governed by the CeCILL license under French law and
6 # abiding by the rules of distribution of free software. You can use,
7 # modify and/ or redistribute the software under the terms of the CeCILL
8 # license as circulated by CEA, CNRS and INRIA at the following URL
9 # "http://www.cecill.info".
10 #
11 # As a counterpart to the access to the source code and rights to copy,
12 # modify and redistribute granted by the license, users are provided only
13 # with a limited warranty and the software's author, the holder of the
14 # economic rights, and the successive licensors have only limited
15 # liability.
16 #
17 # In this respect, the user's attention is drawn to the risks associated
18 # with loading, using, modifying and/or developing or reproducing the
19 # software by the user in light of its specific status of free software,
20 # that may mean that it is complicated to manipulate, and that also
21 # therefore means that it is reserved for developers and experienced
22 # professionals having in-depth computer knowledge. Users are therefore
23 # encouraged to load and test the software's suitability as regards their
24 # requirements in conditions enabling the security of their systems and/or
25 # data to be ensured and, more generally, to use and operate it in the
26 # same conditions as regards security.
27 #
28 # The fact that you are presently reading this means that you have had
29 # knowledge of the CeCILL license and that you accept its terms.
30
31
32 ## @mainpage Documentation of the REPET API
33 #
34 # Welcome to the API documentation!
35 # This API is a set of packages and classes for pipeline(s) development.
36 #
37 # @par The "logger" package
38 #
39 # Logging is managed via LoggerFactory. This class creates instances of logging.logging python class. It's strongly encouraged to use this factory each time you need to log something.
40 #
41 # @par The "checker" package
42 #
43 # This package is a set of classes designed to facilitate development of different kind of checks: filesystem checks, environment checks, configuration file checks ...
44 #
45 # Classes should subclass checker::IChecker or if a logger is needed: checker::AbstractChecker.
46 #
47 # Methods should raise checker::CheckerException.
48 #
49 # Use checker::ConfigChecker and checker::ConfigException for configuration files checks.
50 #
51 # checker::CheckerUtils is a set of small static methods shared by other classes of checker package.
52 #
53 # @par The "coord" package
54 #
55 # This package is a set of classes dedicated to coordinates manipulations.
56 #
57 # A coord::Range instance records a region on a given sequence (start, end and sequence name).
58 #
59 # A coord::Map instance is a coord::Range instance and record a named region on a given sequence (start, end, sequence name and name).
60 #
61 # A coord::Set instance is a coord::Map instance and record a named region on a given sequence with an identifier (start, end, sequence name, name and id).
62 #
63 # A coord::Align instance handle a match between two sequences, query and subject (pair of coordinates with E-value, score and identity).
64 #
65 # A coord::Path instance is a coord::Align instance and handle a match between two sequences, query and subject (pair of coordinates with E-value, score and identity) with an identifier.
66 #
67 # A coord::Match instance is a coord::Path instance and handle a chain of match(es) between two sequences, query and subject, with an identifier and the length of the input sequences.
68 #
69 # coord::Align, coord::Map, coord::Path and coord::Set come with utils classes: coord::AlignUtils, coord::MapUtils, coord::PathUtils and coord::SetUtils.
70 #
71 # @par The "seq" package
72 #
73 # This package a set of classes dedicated to sequences manipulations.
74 #
75 # A seq::Bioseq instance records a sequence with its header. seq::Bioseq comes with an utils class: seq::BioseqUtils.
76 #
77 # A seq::BioseqDB instance handle a collection of a Bioseq (header-sequence).
78 #
79 # A seq::AlignedBioseqDB instance is a multiple sequence alignment representation.
80 #
81 # A seq::FastaUtils is a set of static methods for fasta file manipulation.
82 #
83 # @par The "sql" package
84 #
85 # This package is dedicated to persistance of coord package objects.
86 # All classes come with dedicated interfaces. Use these interfaces for class manipulation.
87 # Class names patterns are ITable*Adaptator and Table*Adaptator.
88 #
89 # sql::ITablePathAdaptator, sql::TablePathAdaptator /
90 # sql::ITableSetAdaptator, sql::TableSetAdaptator /
91 # sql::ITableSeqAdaptator, sql::TableSeqAdaptator /
92 # sql::ITableMapAdaptator, sql::TableMapAdaptator /
93 # sql::ITableMatchAdaptator, sql::TableMatchAdaptator.
94 #
95
96 import logging
97 import sys
98
99 DEFAULT_LEVEL = 1
100 DEFAULT_FORMAT = "%(asctime)s - %(module)s - %(levelname)s - %(message)s"
101 DATE_FORMAT = "%Y-%m-%d %H:%M:%S"
102
103 ## Use this class to create a instance of logging class.
104 #
105 class LoggerFactory(object):
106
107 def createLogger(name, verbosity = DEFAULT_LEVEL, format = DEFAULT_FORMAT, out = sys.stdout):
108 log = logging.getLogger(name)
109
110 hasStreamHandler = False
111 for handler in log.handlers:
112 if handler.__class__ == logging.StreamHandler:
113 hasStreamHandler = True
114 break
115 if not hasStreamHandler:
116 formatter = logging.Formatter(format, DATE_FORMAT)
117 handler = logging.StreamHandler(out)
118 handler.setFormatter(formatter)
119 log.addHandler(handler)
120
121 LoggerFactory.setLevel(log, verbosity)
122 return log
123
124 createLogger = staticmethod(createLogger)
125
126 def setLevel(log, verbosity):
127 log.disabled = False
128 if verbosity >= 4:
129 log.setLevel(logging.DEBUG)
130 elif verbosity == 3:
131 log.setLevel(logging.INFO)
132 elif verbosity == 2:
133 log.setLevel(logging.WARNING)
134 elif verbosity == 1:
135 log.setLevel(logging.ERROR)
136 elif verbosity == 0:
137 log.disabled = True
138
139 setLevel = staticmethod(setLevel)