-
Notifications
You must be signed in to change notification settings - Fork 29
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
changes to make logs splunk compatible
Signed-off-by: Gulshan Bhatia <[email protected]>
- Loading branch information
Gulshan Bhatia
committed
Mar 27, 2024
1 parent
cfc048e
commit b3d1358
Showing
2 changed files
with
7 additions
and
28 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,45 +1,23 @@ | ||
import logging | ||
import structlog | ||
from structlog import processors, stdlib | ||
|
||
|
||
def configure_logger(log_level: str = "INFO"): | ||
def configure_logger(): | ||
"""Configure struct logger for the UDFs.""" | ||
shared_processors = [ | ||
stdlib.add_log_level, | ||
stdlib.PositionalArgumentsFormatter(), | ||
processors.TimeStamper(fmt="iso"), | ||
processors.StackInfoRenderer(), | ||
processors.format_exc_info, | ||
processors.UnicodeDecoder(), | ||
] | ||
structlog.configure( | ||
processors=[ | ||
stdlib.filter_by_level, | ||
stdlib.add_log_level, | ||
stdlib.PositionalArgumentsFormatter(), | ||
processors.TimeStamper(fmt="iso"), | ||
processors.StackInfoRenderer(), | ||
processors.format_exc_info, | ||
processors.UnicodeDecoder(), | ||
structlog.stdlib.ProcessorFormatter.wrap_for_formatter, | ||
], | ||
logger_factory=structlog.stdlib.LoggerFactory(), | ||
wrapper_class=structlog.stdlib.BoundLogger, | ||
cache_logger_on_first_use=True, | ||
) | ||
|
||
formatter = structlog.stdlib.ProcessorFormatter( | ||
foreign_pre_chain=shared_processors, | ||
processors=[ | ||
structlog.stdlib.ProcessorFormatter.remove_processors_meta, | ||
processors.KeyValueRenderer(key_order=["uuid", "event"]), | ||
stdlib.ProcessorFormatter.wrap_for_formatter, | ||
], | ||
logger_factory=stdlib.LoggerFactory(), | ||
wrapper_class=stdlib.BoundLogger, | ||
cache_logger_on_first_use=True, | ||
) | ||
|
||
handler = logging.StreamHandler() | ||
handler.setFormatter(formatter) | ||
logger = structlog.getLogger(__name__) | ||
logger.addHandler(handler) | ||
logger.setLevel(log_level) | ||
|
||
return structlog.getLogger(__name__) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters