Skip to content

Commit

Permalink
Fix logging samples (#29281)
Browse files Browse the repository at this point in the history
  • Loading branch information
lzchen authored Mar 14, 2023
1 parent 6e779b1 commit bd87920
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,11 @@
handler = LoggingHandler()
logger = logging.getLogger(__name__)
logger.addHandler(handler)
logger.setLevel(logging.NOTSET)
logger.setLevel(logging.INFO)

logger.info("INFO: Outside of span")
with tracer.start_as_current_span("foo"):
logger.warning("WARNING: Inside of span")
logger.error("ERROR: After span")

input()
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@
handler = LoggingHandler()
logger = logging.getLogger(__name__)
logger.addHandler(handler)
logger.setLevel(logging.NOTSET)

# The following code will generate two pieces of exception telemetry
# that are identical in nature
Expand All @@ -43,3 +42,5 @@
print(val)
except ZeroDivisionError:
logger.error("Error: Division by zero", stack_info=True, exc_info=True)

input()
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@
handler = LoggingHandler()
logger = logging.getLogger(__name__)
logger.addHandler(handler)
logger.setLevel(logging.NOTSET)
logger.setLevel(logging.INFO)

logger.warning("Hello World!")
logger.info("Hello World!")

input()
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,9 @@
handler = LoggingHandler()
logger = logging.getLogger(__name__)
logger.addHandler(handler)
logger.setLevel(logging.NOTSET)
logger.setLevel(logging.DEBUG)

# Custom properties
logger.debug("DEBUG: Debug with properties", extra={"debug": "true"})

input()

0 comments on commit bd87920

Please sign in to comment.