-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
167 additions
and
45 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,4 +5,7 @@ datasets | |
tree-sitter | ||
docstring-parser | ||
bs4 | ||
Levenshtein | ||
Levenshtein | ||
|
||
# for post-processing | ||
cloc |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
import logging | ||
import time | ||
from datetime import timedelta | ||
|
||
|
||
class LogFormatter: | ||
def __init__(self): | ||
self.start_time = time.time() | ||
|
||
def format(self, record): | ||
elapsed_seconds = round(record.created - self.start_time) | ||
|
||
prefix = "%s - %s - %s" % ( | ||
record.levelname, | ||
time.strftime("%x %X"), | ||
timedelta(seconds=elapsed_seconds), | ||
) | ||
message = record.getMessage() | ||
message = message.replace("\n", "\n" + " " * (len(prefix) + 3)) | ||
return "%s - %s" % (prefix, message) if message else "" | ||
|
||
|
||
def create_logger(filepath, rank): | ||
""" | ||
Create a logger. | ||
Use a different log file for each process. | ||
""" | ||
# create log formatter | ||
log_formatter = LogFormatter() | ||
|
||
# create file handler and set level to debug | ||
if filepath is not None: | ||
if rank > 0: | ||
filepath = "%s-%i" % (filepath, rank) | ||
file_handler = logging.FileHandler(filepath, "a") | ||
file_handler.setLevel(logging.DEBUG) | ||
file_handler.setFormatter(log_formatter) | ||
|
||
# create console handler and set level to info | ||
console_handler = logging.StreamHandler() | ||
console_handler.setLevel(logging.INFO) | ||
console_handler.setFormatter(log_formatter) | ||
|
||
# create logger and set level to debug | ||
logger = logging.getLogger() | ||
logger.handlers = [] | ||
logger.setLevel(logging.DEBUG) | ||
logger.propagate = False | ||
if filepath is not None: | ||
logger.addHandler(file_handler) | ||
logger.addHandler(console_handler) | ||
|
||
# reset logger elapsed time | ||
def reset_time(): | ||
log_formatter.start_time = time.time() | ||
|
||
logger.reset_time = reset_time | ||
|
||
return logger |