Skip to content

Commit ecc450d

Browse files
committed
Move FileHandler to extensions.py
1 parent 49b1224 commit ecc450d

File tree

2 files changed

+32
-32
lines changed

2 files changed

+32
-32
lines changed

adafruit_logging/__init__.py

Lines changed: 0 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -91,38 +91,6 @@ def emit(self, level, msg):
9191
print(self.format(level, msg))
9292

9393

94-
class FileHandler(LoggingHandler):
95-
"""File handler for working with log files off of the microcontroller (like
96-
an SD card)
97-
98-
:param filepath: The filepath to the log file
99-
:param mode: Whether to write ('w') or append ('a'); default is to append
100-
"""
101-
102-
def __init__(self, filepath: str, mode: str = "a"):
103-
self.logfile = open(filepath, mode, encoding="utf-8")
104-
105-
def close(self):
106-
"""Closes the file"""
107-
self.logfile.close()
108-
109-
def format(self, level: int, msg: str):
110-
"""Generate a string to log
111-
112-
:param level: The level of the message
113-
:param msg: The message to format
114-
"""
115-
return super().format(level, msg) + "\r\n"
116-
117-
def emit(self, level: int, msg: str):
118-
"""Generate the message and write it to the UART.
119-
120-
:param level: The level of the message
121-
:param msg: The message to log
122-
"""
123-
self.logfile.write(self.format(level, msg))
124-
125-
12694
# The level module-global variables get created when loaded
12795
# pylint:disable=undefined-variable
12896

adafruit_logging/extensions.py

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
from . import LoggingHandler
2+
3+
class FileHandler(LoggingHandler):
4+
"""File handler for working with log files off of the microcontroller (like
5+
an SD card)
6+
7+
:param filepath: The filepath to the log file
8+
:param mode: Whether to write ('w') or append ('a'); default is to append
9+
"""
10+
11+
def __init__(self, filepath: str, mode: str = "a"):
12+
self.logfile = open(filepath, mode, encoding="utf-8")
13+
14+
def close(self):
15+
"""Closes the file"""
16+
self.logfile.close()
17+
18+
def format(self, level: int, msg: str):
19+
"""Generate a string to log
20+
21+
:param level: The level of the message
22+
:param msg: The message to format
23+
"""
24+
return super().format(level, msg) + "\r\n"
25+
26+
def emit(self, level: int, msg: str):
27+
"""Generate the message and write it to the UART.
28+
29+
:param level: The level of the message
30+
:param msg: The message to log
31+
"""
32+
self.logfile.write(self.format(level, msg))

0 commit comments

Comments
 (0)