- 
                Notifications
    
You must be signed in to change notification settings  - Fork 11
 
feat: add exception logging function, add tests #344
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is what I got during my testing:
    def stream_events(self, inputs, event_writer):
        for input_name, input_item in inputs.inputs.items():
            normalized_input_name = input_name.split("/")[-1]
            logger = logger_for_input(normalized_input_name)
            try:
                session_key = self._input_definition.metadata["session_key"]
                log_level = conf_manager.get_log_level(
                    logger=logger,
                    session_key=session_key,
                    app_name=ADDON_NAME,
                    conf_name=f"{ADDON_NAME}_settings",
                )
                logger.setLevel(log_level)
                log.modular_input_start(logger, normalized_input_name)
                data = get_data_from_api(logger, "hello world")
                sourcetype = "dummy-data"
                for line in data:
                    event_writer.write_event(
                        smi.Event(
                            data=json.dumps(line, ensure_ascii=False, default=str),
                            index=input_item.get("index"),
                            sourcetype=sourcetype,
                        )
                    )
                raise ValueError("throwing a random exception out of nowhere")
                log.events_ingested(
                    logger, normalized_input_name, sourcetype, len(data)
                )
                log.modular_input_end(logger, normalized_input_name)
            except Exception as e:
                log.log_exception(
                    logger,
                    e,
                    msg_before="Exception raised while ingesting data for ",
                    log_level=logging.ERROR,
                )
That error log message should be shown as one line?
| 
           🎉 This PR is included in version 4.13.0-beta.1 🎉 The release is available on GitHub release Your semantic-release bot 📦🚀  | 
    
| 
           🎉 This PR is included in version 4.13.0 🎉 The release is available on GitHub release Your semantic-release bot 📦🚀  | 
    

this feature adds exception logging functionality