Skip to content

Conversation

@xuchen509
Copy link

@xuchen509 xuchen509 commented Mar 14, 2019

Add logging to custom search commands app to showcase how to do logging in custom search commands by using splunk sdk

Screen Shot 2019-03-15 at 1 25 06 PM

@xuchen509 xuchen509 changed the base branch from master to develop March 14, 2019 18:53
@xuchen509 xuchen509 requested a review from a team March 14, 2019 18:53

def generate(self):
text = self.text
self.logger.debug("Genearting text: %s" % self.text)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Typo here

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fixed

Copy link
Contributor

@dan1 dan1 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just have a small typo, other than that looks good.

Copy link
Contributor

@shakeelmohamed shakeelmohamed left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you add a screenshot that verifies the logging works?

count = Option(require=True, validate=validators.Integer(0))

def generate(self):
self.logger.debug("Generating %d words" % self.count)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

replace words with events?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done


def generate(self):
text = self.text
self.logger.debug("Genearting text: %s" % self.text)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

typo: generating

Should we say Generating %d events with text %s?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

propagate = 0 ; Default: 1
level = NOTSET ; Default: WARNING
handlers = splunklib ; Default: stderr
propagate = 0 ; Default: 1
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should also update the logger_GenerateHelloCommand stanza

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

@shakeelmohamed
Copy link
Contributor

@xuchen509 why do the logs contain hardcoded $SPLUNK_HOME paths from David's machine? Let's fix that while we're at it please

@xuchen509
Copy link
Author

@shakeelmohamed i don't know where those come from, that's old logs, not related to this change. Also I can't find anywhere we hard code David's machine path.

@shakeelmohamed shakeelmohamed self-requested a review March 27, 2019 20:53
Copy link
Contributor

@shakeelmohamed shakeelmohamed left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@xuchen509 there is a tess looking at stdout and failing due to the new logging changes.

======================================================================
FAIL: test_sum_as_unit (searchcommands.test_searchcommands_app.TestSearchCommandsApp)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/home/travis/build/splunk/splunk-sdk-python/tests/searchcommands/test_searchcommands_app.py", line 230, in test_sum_as_unit
    self.assertEqual('', errors)
AssertionError: u'' != '2019-03-27 20:45:12,006, Level=ERROR, Pi[203 chars]t.\n'

expected, output, errors, exit_status = self._run_command('sum', action='execute', phase='map', protocol=1)
self.assertEqual(0, exit_status, msg=six.text_type(errors))
self.assertEqual('2019-03-27 20:45:12,006, Level=ERROR, Pi[203 chars]t.', errors)
self.assertEqual('2019-03-27 20:45:12,006, Level=ERROR, Pi[203 chars]t.\n', errors)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this shouldn't be a hardcoded timestamp, use a regex or substring match

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i reverted back to the previous one and use splunklib handler instead of stderr. I can't reproduce this error locally tho.

@xuchen509 xuchen509 merged commit 904461a into develop Mar 28, 2019
@xuchen509 xuchen509 deleted the add-logging branch March 28, 2019 19:58
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants