annotate commons/core/LoggerFactory.py @ 45:e454402ba9d9

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