Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
csst-sims
csst_mci_sim
Commits
80fa496c
Commit
80fa496c
authored
Oct 25, 2024
by
Yan Zhaojun
Browse files
Upload New File
parent
5a9e03e0
Changes
1
Show whitespace changes
Inline
Side-by-side
csst_mci_sim/support/logger.py
0 → 100644
View file @
80fa496c
"""
These functions can be used for logging information.
.. Warning:: logger is not multiprocessing safe.
:version: 0.3
"""
import
logging
import
logging.handlers
def
setUpLogger
(
log_filename
,
loggername
=
'logger'
):
"""
Sets up a logger.
:param: log_filename: name of the file to save the log.
:param: loggername: name of the logger
:return: logger instance
"""
# create logger
logger
=
logging
.
getLogger
(
loggername
)
logger
.
setLevel
(
logging
.
DEBUG
)
# Add the log message handler to the logger
handler
=
logging
.
handlers
.
RotatingFileHandler
(
log_filename
)
# maxBytes=20, backupCount=5)
# create formatter
formatter
=
logging
.
Formatter
(
'%(asctime)s - %(module)s - %(funcName)s - %(levelname)s - %(message)s'
)
# add formatter to ch
handler
.
setFormatter
(
formatter
)
# add handler to logger
if
(
logger
.
hasHandlers
()):
logger
.
handlers
.
clear
()
logger
.
addHandler
(
handler
)
return
logger
# class SimpleLogger(object):
# """
# A simple class to create a log file or print the information on screen.
# """
# def __init__(self, filename, verbose=False):
# self.file = open(filename, 'w')
# self.verbose = verbose
# def write(self, text):
# """
# Writes text either to file or screen.
# """
# print >> self.file, text
# if self.verbose: print( text)
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment