42
42
"""
43
43
#pylint:disable=redefined-outer-name,consider-using-enumerate,no-self-use
44
44
45
- # imports
45
+ import time
46
46
47
47
__version__ = "0.0.0-auto.0"
48
48
__repo__ = "https://github.com/adafruit/Adafruit_CircuitPython_Logger.git"
49
49
50
- import time
51
50
52
51
LEVELS = [(00 , 'NOTSET' ),
53
52
(10 , 'DEBUG' ),
61
60
62
61
def level_for (value ):
63
62
"""Convert a numberic level to the most appropriate name.
64
- value -- a numeric level
63
+
64
+ :param value: a numeric level
65
+
65
66
"""
66
67
for i in range (len (LEVELS )):
67
68
if value < LEVELS [i ][0 ]:
@@ -73,8 +74,10 @@ class LoggingHandler(object):
73
74
74
75
def format (self , level , msg ):
75
76
"""Generate a timestamped message.
76
- level -- the logging level
77
- msg -- the message to log
77
+
78
+ :param level: the logging level
79
+ :param msg: the message to log
80
+
78
81
"""
79
82
now = time .localtime ()
80
83
time_vals = (now .tm_year , now .tm_mon , now .tm_mday ,
@@ -94,8 +97,10 @@ class PrintHandler(LoggingHandler):
94
97
95
98
def emit (self , level , msg ):
96
99
"""Send a message to teh console.
97
- level -- the logging level
98
- msg -- the message to log
100
+
101
+ :param level: the logging level
102
+ :param msg: the message to log
103
+
99
104
"""
100
105
print (self .format (level , msg ))
101
106
@@ -108,7 +113,9 @@ class Logger(object):
108
113
109
114
def __init__ (self , handler = None ):
110
115
"""Create an instance.
111
- handler -- what to use to output messages. Defaults to a PrintHandler.
116
+
117
+ :param handler: what to use to output messages. Defaults to a PrintHandler.
118
+
112
119
"""
113
120
self ._level = NOTSET
114
121
if handler is None :
@@ -118,54 +125,65 @@ def __init__(self, handler=None):
118
125
119
126
@property
120
127
def level (self ):
121
- """Get the level."""
128
+ """The level."""
122
129
return self ._level
123
130
124
131
@level .setter
125
132
def level (self , value ):
126
- """Set the level."""
127
133
self ._level = value
128
134
129
135
def log (self , level , format_string , * args ):
130
136
"""Log a message.
131
- level -- the priority level at which to log
132
- format_string -- the core mesage string with embedded formatting directives
133
- args -- arguments format_string.format(), can be empty
137
+
138
+ :param level: the priority level at which to log
139
+ :param format_string: the core message string with embedded formatting directives
140
+ :param args: arguments to ``format_string.format()``, can be empty
141
+
134
142
"""
135
143
if self ._level != NOTSET and level >= self ._level :
136
144
self ._handler .emit (level , format_string .format (* args ))
137
145
138
146
def debug (self , format_string , * args ):
139
147
"""Log a debug message.
140
- format_string -- the core mesage string with embedded formatting directives
141
- args -- arguments format_string.format(), can be empty
148
+
149
+ :param format_string: the core message string with embedded formatting directives
150
+ :param args: arguments to ``format_string.format()``, can be empty
151
+
142
152
"""
143
153
self .log (DEBUG , format_string , * args )
144
154
145
155
def info (self , format_string , * args ):
146
156
"""Log a info message.
147
- format_string -- the core mesage string with embedded formatting directives
148
- args -- arguments format_string.format(), can be empty
157
+
158
+ :param format_string: the core message string with embedded formatting directives
159
+ :param args: arguments to ``format_string.format()``, can be empty
160
+
149
161
"""
150
162
self .log (INFO , format_string , * args )
151
163
152
164
def warning (self , format_string , * args ):
153
165
"""Log a warning message.
154
- format_string -- the core mesage string with embedded formatting directives
155
- args -- arguments format_string.format(), can be empty
166
+
167
+ :param format_string: the core message string with embedded formatting directives
168
+ :param args: arguments to ``format_string.format()``, can be empty
169
+
156
170
"""
157
171
self .log (WARNING , format_string , * args )
158
172
159
173
def error (self , format_string , * args ):
160
174
"""Log a error message.
161
- format_string -- the core mesage string with embedded formatting directives
162
- args -- arguments format_string.format(), can be empty
175
+
176
+ :param format_string: the core message string with embedded formatting directives
177
+ :param args: arguments to ``format_string.format()``, can be empty
178
+
163
179
"""
164
180
self .log (ERROR , format_string , * args )
165
181
166
182
def critical (self , format_string , * args ):
167
183
"""Log a critical message.
168
- format_string -- the core mesage string with embedded formatting directives
169
- args -- arguments format_string.format(), can be empty
184
+
185
+ :param format_string: the core message string with embedded formatting directives
186
+ :param args: arguments to ``format_string.format()``, can be empty
187
+
170
188
"""
171
189
self .log (CRITICAL , format_string , * args )
0 commit comments