-
Notifications
You must be signed in to change notification settings - Fork 23
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #36 from JustKappaMan/pieraknet
Refactoring, optimizations, improvements
- Loading branch information
Showing
7 changed files
with
62 additions
and
41 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,12 @@ | ||
from piemc.handlers.command import Command | ||
|
||
|
||
@Command | ||
def ping(self): | ||
self.logger.info("Pong!") | ||
|
||
|
||
|
||
@Command | ||
def stop(self): | ||
self.logger.info("Stopping the server...") | ||
self.stop() | ||
self.stop() |
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
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 |
---|---|---|
@@ -1,32 +1,35 @@ | ||
import logging | ||
import os | ||
import logging | ||
|
||
import piemc.config | ||
|
||
|
||
def create_logger(name): | ||
log_level_mapping = { | ||
'DEBUG': logging.DEBUG, | ||
'INFO': logging.INFO, | ||
'WARNING': logging.WARNING, | ||
'ERROR': logging.ERROR, | ||
'CRITICAL': logging.CRITICAL | ||
"DEBUG": logging.DEBUG, | ||
"INFO": logging.INFO, | ||
"WARNING": logging.WARNING, | ||
"ERROR": logging.ERROR, | ||
"CRITICAL": logging.CRITICAL, | ||
} | ||
log_level = log_level_mapping.get(piemc.config.LOG_LEVEL.upper(), logging.INFO) | ||
logger = logging.getLogger(name) | ||
logger.setLevel(log_level) | ||
|
||
log_dir = './log' | ||
log_dir = "./log" | ||
os.makedirs(log_dir, exist_ok=True) | ||
|
||
log_file = os.path.join(log_dir, name + '.log') | ||
fhandler = logging.FileHandler(log_file, 'w', 'utf-8') | ||
log_file = os.path.join(log_dir, name + ".log") | ||
fhandler = logging.FileHandler(log_file, "w", "utf-8") | ||
shandler = logging.StreamHandler() | ||
|
||
formatter = logging.Formatter( | ||
"[%(name)s]" + str(' ' * (11 - len(name))) + "[%(asctime)s] [%(levelname)s] : %(message)s") | ||
"[%(name)s]" + str(" " * (11 - len(name))) + "[%(asctime)s] [%(levelname)s] : %(message)s" | ||
) | ||
fhandler.setFormatter(formatter) | ||
shandler.setFormatter(formatter) | ||
|
||
logger.addHandler(fhandler) | ||
logger.addHandler(shandler) | ||
|
||
return logger | ||
return logger |
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