Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
S
seminar-breakout
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Shashank Suhas
seminar-breakout
Commits
9ec5ca49
Commit
9ec5ca49
authored
Sep 26, 2016
by
Yuxin Wu
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
improve logging
parent
47b93ed9
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
13 additions
and
8 deletions
+13
-8
tensorpack/utils/logger.py
tensorpack/utils/logger.py
+13
-8
No files found.
tensorpack/utils/logger.py
View file @
9ec5ca49
...
@@ -41,20 +41,22 @@ def _getlogger():
...
@@ -41,20 +41,22 @@ def _getlogger():
_logger
=
_getlogger
()
_logger
=
_getlogger
()
def
get_time_str
():
def
_
get_time_str
():
return
datetime
.
now
()
.
strftime
(
'
%
m
%
d-
%
H
%
M
%
S'
)
return
datetime
.
now
()
.
strftime
(
'
%
m
%
d-
%
H
%
M
%
S'
)
# logger file and directory:
# logger file and directory:
global
LOG_FILE
,
LOG_DIR
global
LOG_FILE
,
LOG_DIR
LOG_DIR
=
None
LOG_DIR
=
None
def
_set_file
(
path
):
def
_set_file
(
path
):
if
os
.
path
.
isfile
(
path
):
if
os
.
path
.
isfile
(
path
):
backup_name
=
path
+
'.'
+
get_time_str
()
backup_name
=
path
+
'.'
+
_
get_time_str
()
shutil
.
move
(
path
,
backup_name
)
shutil
.
move
(
path
,
backup_name
)
info
(
"Log file '{}' backuped to '{}'"
.
format
(
path
,
backup_name
))
info
(
"Log file '{}' backuped to '{}'"
.
format
(
path
,
backup_name
))
hdl
=
logging
.
FileHandler
(
hdl
=
logging
.
FileHandler
(
filename
=
path
,
encoding
=
'utf-8'
,
mode
=
'w'
)
filename
=
path
,
encoding
=
'utf-8'
,
mode
=
'w'
)
hdl
.
setFormatter
(
_MyFormatter
(
datefmt
=
'
%
m
%
d
%
H:
%
M:
%
S'
))
hdl
.
setFormatter
(
_MyFormatter
(
datefmt
=
'
%
m
%
d
%
H:
%
M:
%
S'
))
_logger
.
addHandler
(
hdl
)
_logger
.
addHandler
(
hdl
)
_logger
.
info
(
"Argv: "
+
' '
.
join
(
sys
.
argv
))
def
set_logger_dir
(
dirname
,
action
=
None
):
def
set_logger_dir
(
dirname
,
action
=
None
):
"""
"""
...
@@ -74,13 +76,13 @@ If you're resuming from a previous run you can choose to keep it.""")
...
@@ -74,13 +76,13 @@ If you're resuming from a previous run you can choose to keep it.""")
action
=
input
()
.
lower
()
.
strip
()
action
=
input
()
.
lower
()
.
strip
()
act
=
action
act
=
action
if
act
==
'b'
:
if
act
==
'b'
:
backup_name
=
dirname
+
get_time_str
()
backup_name
=
dirname
+
_
get_time_str
()
shutil
.
move
(
dirname
,
backup_name
)
shutil
.
move
(
dirname
,
backup_name
)
info
(
"Directory '{}' backuped to '{}'"
.
format
(
dirname
,
backup_name
))
info
(
"Directory '{}' backuped to '{}'"
.
format
(
dirname
,
backup_name
))
elif
act
==
'd'
:
elif
act
==
'd'
:
shutil
.
rmtree
(
dirname
)
shutil
.
rmtree
(
dirname
)
elif
act
==
'n'
:
elif
act
==
'n'
:
dirname
=
dirname
+
get_time_str
()
dirname
=
dirname
+
_
get_time_str
()
info
(
"Use a new log directory {}"
.
format
(
dirname
))
info
(
"Use a new log directory {}"
.
format
(
dirname
))
elif
act
==
'k'
:
elif
act
==
'k'
:
pass
pass
...
@@ -92,19 +94,22 @@ If you're resuming from a previous run you can choose to keep it.""")
...
@@ -92,19 +94,22 @@ If you're resuming from a previous run you can choose to keep it.""")
LOG_FILE
=
os
.
path
.
join
(
dirname
,
'log.log'
)
LOG_FILE
=
os
.
path
.
join
(
dirname
,
'log.log'
)
_set_file
(
LOG_FILE
)
_set_file
(
LOG_FILE
)
_LOGGING_METHOD
=
[
'info'
,
'warning'
,
'error'
,
'critical'
,
'warn'
,
'exception'
,
'debug'
]
# export logger functions
# export logger functions
for
func
in
[
'info'
,
'warning'
,
'error'
,
'critical'
,
'warn'
,
'exception'
,
'debug'
]
:
for
func
in
_LOGGING_METHOD
:
locals
()[
func
]
=
getattr
(
_logger
,
func
)
locals
()[
func
]
=
getattr
(
_logger
,
func
)
def
disable_logger
():
def
disable_logger
():
""" disable all logging ability from this moment"""
""" disable all logging ability from this moment"""
for
func
in
[
'info'
,
'warning'
,
'error'
,
'critical'
,
'warn'
,
'exception'
,
'debug'
]
:
for
func
in
_LOGGING_METHOD
:
globals
()[
func
]
=
lambda
x
:
None
globals
()[
func
]
=
lambda
x
:
None
def
auto_set_dir
(
action
=
None
,
overwrite
_setting
=
False
):
def
auto_set_dir
(
action
=
None
,
overwrite
=
False
):
""" set log directory to a subdir inside 'train_log', with the name being
""" set log directory to a subdir inside 'train_log', with the name being
the main python file currently running"""
the main python file currently running"""
if
LOG_DIR
is
not
None
and
not
overwrite_setting
:
if
LOG_DIR
is
not
None
and
not
overwrite
:
# dir already set
return
return
mod
=
sys
.
modules
[
'__main__'
]
mod
=
sys
.
modules
[
'__main__'
]
basename
=
os
.
path
.
basename
(
mod
.
__file__
)
basename
=
os
.
path
.
basename
(
mod
.
__file__
)
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a 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