clearml/examples/reporting/text_reporting.py

93 lines
2.8 KiB
Python
Raw Normal View History

2020-12-22 21:25:37 +00:00
# ClearML - Example of manual graphs and statistics reporting
2020-06-15 19:48:51 +00:00
#
2020-12-10 07:41:31 +00:00
from __future__ import print_function
2020-06-15 19:48:51 +00:00
import logging
import sys
import six
2020-12-22 21:25:37 +00:00
from clearml import Logger, Task
2020-06-15 19:48:51 +00:00
def report_logs(logger):
# type: (Logger) -> ()
"""
reporting text to logs section
:param logger: The task.logger to use for sending the text
"""
# standard python logging
logging.info("This is an info message")
# this is a loguru test example
try:
from loguru import logger as loguru_logger # noqa
2020-06-15 19:48:51 +00:00
loguru_logger.info(
"That's it, beautiful and simple logging! (using ANSI colors)"
)
2020-06-15 19:48:51 +00:00
except ImportError:
print("loguru not installed, skipping loguru test")
2020-06-15 19:48:51 +00:00
# report text
logger.report_text("hello, this is plain text")
def report_debug_text(logger):
# type: (Logger) -> ()
"""
reporting text to debug sample section
:param logger: The task.logger to use for sending the sample
"""
text_to_send = """
Lorem ipsum dolor sit amet, consectetur adipiscing elit.
Suspendisse ac justo ut dolor scelerisque posuere.
Donec hendrerit, purus viverra congue maximus, neque orci vehicula elit, pulvinar elementum diam lorem ut arcu.
Sed convallis ipsum justo. Duis faucibus consectetur cursus. Morbi eleifend nisl vel maximus dapibus.
Vestibulum commodo justo eget tellus interdum dapibus. Curabitur pulvinar nibh vitae orci laoreet, id sodales justo ultrices.
Etiam mollis dui et viverra ultrices. Vestibulum vitae molestie libero, quis lobortis risus. Morbi venenatis quis odio nec efficitur.
Vestibulum dictum ipsum at viverra ultrices. Aliquam sed ante massa. Quisque convallis libero in orci fermentum tincidunt.
"""
logger.report_media(
title="text title",
series="text series",
iteration=1,
stream=six.StringIO(text_to_send),
file_extension=".txt",
)
2020-06-15 19:48:51 +00:00
def main():
2020-12-23 22:30:32 +00:00
# Connecting ClearML with the current process,
# from here on everything is logged automatically
2020-06-15 19:48:51 +00:00
task = Task.init(project_name="examples", task_name="text reporting")
print("reporting text logs")
2020-06-15 19:48:51 +00:00
# report regular console print
print("This is standard output test")
2020-06-15 19:48:51 +00:00
# report stderr
print("This is standard error test", file=sys.stderr)
2020-06-15 19:48:51 +00:00
# Get the task logger,
# You can also call Task.current_task().get_logger() from anywhere in your code.
logger = task.get_logger()
# report text based logs
report_logs(logger)
# report text as debug example
report_debug_text(logger)
2020-06-15 19:48:51 +00:00
# force flush reports
# If flush is not called, reports are flushed in the background every couple of seconds,
# and at the end of the process execution
logger.flush()
print("We are done reporting, have a great day :)")
2020-06-15 19:48:51 +00:00
if __name__ == "__main__":
main()