question

LiangChen-4275 avatar image
0 Votes"
LiangChen-4275 asked PRADEEPCHEEKATLA-MSFT commented

How to use create custom logs by using the output texts from Synapse notebook?

Hi,

I am developing a Synapse notebook, and I want to use an output from Synapse notebook to create custom logs in Azure Log Analytics.

For example:

In a Synapse notebook, I define a string variable s = 'Cannot get the file status', and I want to output this text message into custom logs in Azure Log Analytics every time when I run this Synapse notebook.

How can I realize this?

Thanks,
Liang

azure-synapse-analyticsazure-monitor
· 1
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

Hello @LiangChen-4275,

Following up to see if the below suggestion was helpful. And, if you have any further query do let us know.


  • Please don't forget to click on 130616-image.png or upvote 130671-image.png button whenever the information provided helps you.

0 Votes 0 ·

1 Answer

PRADEEPCHEEKATLA-MSFT avatar image
0 Votes"
PRADEEPCHEEKATLA-MSFT answered PRADEEPCHEEKATLA-MSFT commented

Hello @LiangChen-4275,

Thanks for the question and using MS Q&A platform.

You may try with below sample code for python logging with different format and customized log level.

  import logging
        
  # Customize the logging format for all loggers
  FORMAT = "%(asctime)s - %(name)s - %(levelname)s - %(message)s"
  formatter = logging.Formatter(fmt=FORMAT)
  for handler in logging.getLogger().handlers:
      handler.setFormatter(formatter)
        
  # Customize log level for all loggers
  logging.getLogger().setLevel(logging.INFO)
        
  # Customize the log level for a specific logger
  customizedLogger = logging.getLogger('customized')
  customizedLogger.setLevel(logging.WARNING)
        
  # logger that use the default global log level
  defaultLogger = logging.getLogger('default')
        
  defaultLogger.debug("default debug message")
  defaultLogger.info("default info message")
  defaultLogger.warning("default warning message")
  defaultLogger.error("default error message")
  defaultLogger.critical("default critical message")
        
  # logger that use the customized log level
  customizedLogger.debug("customized debug message")
  customizedLogger.info("customized info message")
  customizedLogger.warning("customized warning message")
  customizedLogger.error("customized error message")
  customizedLogger.critical("customized critical message")

Here is the expected output for the above sample code for python logging with different format and customized log level.

197011-image.png

Hope this will help. Please let us know if any further queries.


  • Please don't forget to click on 130616-image.png or upvote 130671-image.png button whenever the information provided helps you. Original posters help the community find answers faster by identifying the correct answer. Here is how

  • Want a reminder to come back and check responses? Here is how to subscribe to a notification

  • If you are interested in joining the VM program and help shape the future of Q&A: Here is how you can be part of Q&A Volunteer Moderators


image.png (91.2 KiB)
· 1
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

Hello @LiangChen-4275,

Just checking in to see if the above answer helped. If this answers your query, do click Accept Answer and Up-Vote for the same. And, if you have any further query do let us know.

0 Votes 0 ·