Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
OpenDAS
ColossalAI
Commits
7d81b5b4
Unverified
Commit
7d81b5b4
authored
Mar 29, 2022
by
Jiarui Fang
Committed by
GitHub
Mar 29, 2022
Browse files
[logging] polish logger format (#543)
parent
1f90a3b1
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
27 additions
and
3 deletions
+27
-3
colossalai/logging/logger.py
colossalai/logging/logger.py
+27
-3
No files found.
colossalai/logging/logger.py
View file @
7d81b5b4
...
...
@@ -5,15 +5,18 @@ import colossalai
import
logging
from
pathlib
import
Path
from
typing
import
Union
import
inspect
from
colossalai.context.parallel_mode
import
ParallelMode
try
:
from
rich.logging
import
RichHandler
_FORMAT
=
'colossalai - %(name)s - %(asctime)s %(levelname)s: %(message)s'
logging
.
basicConfig
(
level
=
logging
.
INFO
,
format
=
_FORMAT
,
handlers
=
[
RichHandler
()])
_FORMAT
=
'colossalai - %(name)s - %(levelname)s: %(message)s'
logging
.
basicConfig
(
level
=
logging
.
INFO
,
format
=
_FORMAT
,
handlers
=
[
RichHandler
(
show_path
=
False
,
markup
=
True
,
rich_tracebacks
=
True
)])
except
ImportError
:
_FORMAT
=
'colossalai - %(name)s -
%(asctime)s
%(levelname)s: %(message)s'
_FORMAT
=
'colossalai - %(name)s - %(levelname)s: %(message)s'
logging
.
basicConfig
(
level
=
logging
.
INFO
,
format
=
_FORMAT
)
...
...
@@ -50,6 +53,19 @@ class DistributedLogger:
self
.
_logger
=
logging
.
getLogger
(
name
)
DistributedLogger
.
__instances
[
name
]
=
self
@
staticmethod
def
__get_call_info
():
stack
=
inspect
.
stack
()
# stack[1] gives previous function ('info' in our case)
# stack[2] gives before previous function and so on
fn
=
stack
[
2
][
1
]
ln
=
stack
[
2
][
2
]
func
=
stack
[
2
][
3
]
return
fn
,
ln
,
func
@
staticmethod
def
_check_valid_logging_level
(
level
:
str
):
assert
level
in
[
'INFO'
,
'DEBUG'
,
'WARNING'
,
'ERROR'
],
'found invalid logging level'
...
...
@@ -122,6 +138,8 @@ class DistributedLogger:
:param ranks: List of parallel ranks
:type ranks: list
"""
message_prefix
=
"{}:{} {}"
.
format
(
*
self
.
__get_call_info
())
self
.
_log
(
'info'
,
message_prefix
,
parallel_mode
,
ranks
)
self
.
_log
(
'info'
,
message
,
parallel_mode
,
ranks
)
def
warning
(
self
,
message
:
str
,
parallel_mode
:
ParallelMode
=
ParallelMode
.
GLOBAL
,
ranks
:
list
=
None
):
...
...
@@ -134,6 +152,8 @@ class DistributedLogger:
:param ranks: List of parallel ranks
:type ranks: list
"""
message_prefix
=
"{}:{} {}"
.
format
(
*
self
.
__get_call_info
())
self
.
_log
(
'warning'
,
message_prefix
,
parallel_mode
,
ranks
)
self
.
_log
(
'warning'
,
message
,
parallel_mode
,
ranks
)
def
debug
(
self
,
message
:
str
,
parallel_mode
:
ParallelMode
=
ParallelMode
.
GLOBAL
,
ranks
:
list
=
None
):
...
...
@@ -146,6 +166,8 @@ class DistributedLogger:
:param ranks: List of parallel ranks
:type ranks: list
"""
message_prefix
=
"{}:{} {}"
.
format
(
*
self
.
__get_call_info
())
self
.
_log
(
'debug'
,
message_prefix
,
parallel_mode
,
ranks
)
self
.
_log
(
'debug'
,
message
,
parallel_mode
,
ranks
)
def
error
(
self
,
message
:
str
,
parallel_mode
:
ParallelMode
=
ParallelMode
.
GLOBAL
,
ranks
:
list
=
None
):
...
...
@@ -158,4 +180,6 @@ class DistributedLogger:
:param ranks: List of parallel ranks
:type ranks: list
"""
message_prefix
=
"{}:{} {}"
.
format
(
*
self
.
__get_call_info
())
self
.
_log
(
'error'
,
message_prefix
,
parallel_mode
,
ranks
)
self
.
_log
(
'error'
,
message
,
parallel_mode
,
ranks
)
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