Skip to content

Commit

Permalink
modification on DepthMod,
Browse files Browse the repository at this point in the history
sort in functions, add doctest function
  • Loading branch information
JouSF-1409 committed Oct 27, 2023
1 parent ddeb266 commit c700b91
Showing 1 changed file with 29 additions and 28 deletions.
57 changes: 29 additions & 28 deletions seispy/setuplog.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,41 +3,42 @@


class setuplog(object):
default_logs={
"RF2depthlog":("RF2depth","INFO","stream_handler"),
"RFlog":("RF","INFO","stream_handler"),
"Batlog":("Bat","INFO","stream_handler","file_handler"),
"CCPlog":("CCP","INFO","stream_handler"),
"ModCreatorlog":("ModCreator","INFO","stream_handler"),
"PickDepthlog": ("PickDepth", "INFO","stream_handler")
}
def __init__(self, filename=join(expanduser('~'), '.RF.log')):
"""
use default_logs to gen loggers
change default_logs for future changes if needed,
check logger level with logger.getEffectiveLevel
"""
self.filename = filename
fh = logging.FileHandler(filename)
ch = logging.StreamHandler()
formatter = logging.Formatter('%(asctime)s [%(name)s] %(levelname)s: %(message)s')
fh.setFormatter(formatter)
ch.setFormatter(formatter)
self.RF2depthlog = logging.getLogger('RF2depth')
if not self.RF2depthlog.handlers:
self.RF2depthlog.setLevel(logging.INFO)
self.RF2depthlog.addHandler(ch)
self.RFlog = logging.getLogger('RF')
if not self.RFlog.handlers:
self.RFlog.setLevel(logging.INFO)
# self.RFlog.removeHandler(ch)
self.RFlog.addHandler(ch)
self.Batlog = logging.getLogger('Bat')
if not self.Batlog.handlers:
self.Batlog.setLevel(logging.INFO)
# self.Batlog.removeHandler(ch)
# self.Batlog.removeHandler(fh)
self.Batlog.addHandler(ch)
self.Batlog.addHandler(fh)
self.CCPlog = logging.getLogger('CCP')
if not self.CCPlog.handlers:
self.CCPlog.setLevel(logging.INFO)
self.CCPlog.addHandler(ch)
self.ModCreatorlog = logging.getLogger('ModCreator')
if not self.ModCreatorlog.handlers:
self.ModCreatorlog.setLevel(logging.INFO)
self.ModCreatorlog.addHandler(ch)
self.PickDepthlog = logging.getLogger('PickDepth')
if not self.PickDepthlog.handlers:
self.PickDepthlog.setLevel(logging.INFO)
# self.PickDepthlog.addHandler(ch)

for loger_branch, config in self.default_logs.items():
# init, setlevel
log = logging.getLogger(config[0])
log.setLevel(config[1])
next if log.hasHandlers else None

# add handler
if "file_handler" in config:
log.addHandler(fh)
if "stream_handler" in config:
log.addHandler(ch)

# attach to class
setattr(self,loger_branch,log)


if __name__ == '__main__':
Expand Down

0 comments on commit c700b91

Please sign in to comment.