From d41b67a4559476abd96e99de295368940f1ae423 Mon Sep 17 00:00:00 2001 From: Eric Cheng Date: Thu, 14 Mar 2019 11:52:32 -0700 Subject: [PATCH 1/7] add logging to custom search commands app examples --- examples/searchcommands_app/package/bin/generatehello.py | 1 + examples/searchcommands_app/package/bin/generatetext.py | 1 + examples/searchcommands_app/package/default/logging.conf | 8 ++++---- 3 files changed, 6 insertions(+), 4 deletions(-) diff --git a/examples/searchcommands_app/package/bin/generatehello.py b/examples/searchcommands_app/package/bin/generatehello.py index b61e8d8d6..dc4858c08 100755 --- a/examples/searchcommands_app/package/bin/generatehello.py +++ b/examples/searchcommands_app/package/bin/generatehello.py @@ -32,6 +32,7 @@ class GenerateHelloCommand(GeneratingCommand): count = Option(require=True, validate=validators.Integer(0)) def generate(self): + self.logger.debug("Generating %d words" % self.count) for i in range(1, self.count + 1): text = 'Hello World %d' % i yield {'_time': time.time(), 'event_no': i, '_raw': text} diff --git a/examples/searchcommands_app/package/bin/generatetext.py b/examples/searchcommands_app/package/bin/generatetext.py index f999f11b1..35b7d3536 100755 --- a/examples/searchcommands_app/package/bin/generatetext.py +++ b/examples/searchcommands_app/package/bin/generatetext.py @@ -35,6 +35,7 @@ class GenerateTextCommand(GeneratingCommand): def generate(self): text = self.text + self.logger.debug("Genearting text: %s" % self.text) for i in range(1, self.count + 1): yield {'_serial': i, '_time': time.time(), '_raw': six.text_type(i) + '. ' + text} diff --git a/examples/searchcommands_app/package/default/logging.conf b/examples/searchcommands_app/package/default/logging.conf index a772b75de..55760877a 100644 --- a/examples/searchcommands_app/package/default/logging.conf +++ b/examples/searchcommands_app/package/default/logging.conf @@ -30,9 +30,9 @@ propagate = 0 ; Default: 1 [logger_GenerateTextCommand] qualname = GenerateTextCommand -level = NOTSET ; Default: WARNING -handlers = app ; Default: stderr -propagate = 0 ; Default: 1 +level = NOTSET ; Default: WARNING +handlers = splunklib ; Default: stderr +propagate = 0 ; Default: 1 [logger_SimulateCommand] qualname = SimulateCommand @@ -43,7 +43,7 @@ propagate = 0 ; Default: 1 [logger_SumCommand] qualname = SumCommand level = NOTSET ; Default: WARNING -handlers = app ; Default: stderr +handlers = stderr ; Default: stderr propagate = 0 ; Default: 1 [handlers] From 59402a0ccda6db8cabf5e6f06c53cefacc7683e0 Mon Sep 17 00:00:00 2001 From: Eric Cheng Date: Thu, 14 Mar 2019 14:09:29 -0700 Subject: [PATCH 2/7] addressed comments --- examples/searchcommands_app/package/bin/generatehello.py | 2 +- examples/searchcommands_app/package/bin/generatetext.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/examples/searchcommands_app/package/bin/generatehello.py b/examples/searchcommands_app/package/bin/generatehello.py index dc4858c08..572f6b740 100755 --- a/examples/searchcommands_app/package/bin/generatehello.py +++ b/examples/searchcommands_app/package/bin/generatehello.py @@ -32,7 +32,7 @@ class GenerateHelloCommand(GeneratingCommand): count = Option(require=True, validate=validators.Integer(0)) def generate(self): - self.logger.debug("Generating %d words" % self.count) + self.logger.debug("Generating %s events" % self.count) for i in range(1, self.count + 1): text = 'Hello World %d' % i yield {'_time': time.time(), 'event_no': i, '_raw': text} diff --git a/examples/searchcommands_app/package/bin/generatetext.py b/examples/searchcommands_app/package/bin/generatetext.py index 35b7d3536..027ccf02f 100755 --- a/examples/searchcommands_app/package/bin/generatetext.py +++ b/examples/searchcommands_app/package/bin/generatetext.py @@ -35,8 +35,8 @@ class GenerateTextCommand(GeneratingCommand): def generate(self): text = self.text - self.logger.debug("Genearting text: %s" % self.text) for i in range(1, self.count + 1): + self.logger.debug("Genearting %s events" % self.count) yield {'_serial': i, '_time': time.time(), '_raw': six.text_type(i) + '. ' + text} dispatch(GenerateTextCommand, sys.argv, sys.stdin, sys.stdout, __name__) From 10cccfd8a1b01ff6b882a75fdf6251544a3d809d Mon Sep 17 00:00:00 2001 From: Eric Cheng Date: Thu, 14 Mar 2019 15:19:06 -0700 Subject: [PATCH 3/7] addressed comments --- examples/searchcommands_app/package/bin/generatetext.py | 2 +- examples/searchcommands_app/package/default/logging.conf | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/examples/searchcommands_app/package/bin/generatetext.py b/examples/searchcommands_app/package/bin/generatetext.py index 027ccf02f..4f3ddede9 100755 --- a/examples/searchcommands_app/package/bin/generatetext.py +++ b/examples/searchcommands_app/package/bin/generatetext.py @@ -35,8 +35,8 @@ class GenerateTextCommand(GeneratingCommand): def generate(self): text = self.text + self.logger.debug("Generating %s events" % self.count) for i in range(1, self.count + 1): - self.logger.debug("Genearting %s events" % self.count) yield {'_serial': i, '_time': time.time(), '_raw': six.text_type(i) + '. ' + text} dispatch(GenerateTextCommand, sys.argv, sys.stdin, sys.stdout, __name__) diff --git a/examples/searchcommands_app/package/default/logging.conf b/examples/searchcommands_app/package/default/logging.conf index 55760877a..1b65313ee 100644 --- a/examples/searchcommands_app/package/default/logging.conf +++ b/examples/searchcommands_app/package/default/logging.conf @@ -30,8 +30,8 @@ propagate = 0 ; Default: 1 [logger_GenerateTextCommand] qualname = GenerateTextCommand -level = NOTSET ; Default: WARNING -handlers = splunklib ; Default: stderr +level = DEBUG ; Default: WARNING +handlers = app ; Default: stderr propagate = 0 ; Default: 1 [logger_SimulateCommand] From f463a04495bac27292d7843aedf67f0434bfdd69 Mon Sep 17 00:00:00 2001 From: Eric Cheng Date: Thu, 14 Mar 2019 15:24:04 -0700 Subject: [PATCH 4/7] address comments --- examples/searchcommands_app/package/bin/generatetext.py | 2 +- examples/searchcommands_app/package/default/logging.conf | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/examples/searchcommands_app/package/bin/generatetext.py b/examples/searchcommands_app/package/bin/generatetext.py index 4f3ddede9..8251e6571 100755 --- a/examples/searchcommands_app/package/bin/generatetext.py +++ b/examples/searchcommands_app/package/bin/generatetext.py @@ -35,7 +35,7 @@ class GenerateTextCommand(GeneratingCommand): def generate(self): text = self.text - self.logger.debug("Generating %s events" % self.count) + self.logger.debug("Generating %d events with text %s" % (self.count, self.text)) for i in range(1, self.count + 1): yield {'_serial': i, '_time': time.time(), '_raw': six.text_type(i) + '. ' + text} diff --git a/examples/searchcommands_app/package/default/logging.conf b/examples/searchcommands_app/package/default/logging.conf index 1b65313ee..1a5b8995b 100644 --- a/examples/searchcommands_app/package/default/logging.conf +++ b/examples/searchcommands_app/package/default/logging.conf @@ -24,13 +24,13 @@ propagate = 0 ; Default: 1 [logger_GenerateHelloCommand] qualname = GenerateHelloCommand -level = NOTSET ; Default: WARNING +level = DEBUG ; Default: WARNING handlers = app ; Default: stderr propagate = 0 ; Default: 1 [logger_GenerateTextCommand] qualname = GenerateTextCommand -level = DEBUG ; Default: WARNING +level = DEBUG ; Default: WARNING handlers = app ; Default: stderr propagate = 0 ; Default: 1 From d12430463fcda2c76aaaef251c9e4e25308967bc Mon Sep 17 00:00:00 2001 From: Eric Cheng Date: Wed, 27 Mar 2019 14:15:27 -0700 Subject: [PATCH 5/7] fix test --- tests/searchcommands/test_searchcommands_app.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/searchcommands/test_searchcommands_app.py b/tests/searchcommands/test_searchcommands_app.py index 8945c3644..d64b4a9c9 100755 --- a/tests/searchcommands/test_searchcommands_app.py +++ b/tests/searchcommands/test_searchcommands_app.py @@ -227,7 +227,7 @@ def test_sum_as_unit(self): 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('', errors) + self.assertEqual('2019-03-27 20:45:12,006, Level=ERROR, Pi[203 chars]t.', errors) self._compare_csv_files_time_sensitive(expected, output) expected, output, errors, exit_status = self._run_command('sum', action='execute', phase='reduce', protocol=1) From 801e9603158d8e413cbf569bdbc818e73937192f Mon Sep 17 00:00:00 2001 From: Eric Cheng Date: Wed, 27 Mar 2019 14:42:19 -0700 Subject: [PATCH 6/7] fix unit test --- tests/searchcommands/test_searchcommands_app.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/searchcommands/test_searchcommands_app.py b/tests/searchcommands/test_searchcommands_app.py index d64b4a9c9..0d19928f3 100755 --- a/tests/searchcommands/test_searchcommands_app.py +++ b/tests/searchcommands/test_searchcommands_app.py @@ -227,7 +227,7 @@ def test_sum_as_unit(self): 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) self._compare_csv_files_time_sensitive(expected, output) expected, output, errors, exit_status = self._run_command('sum', action='execute', phase='reduce', protocol=1) From 30545b097fedf76e9eeb3568f910e46d9069795f Mon Sep 17 00:00:00 2001 From: Eric Cheng Date: Wed, 27 Mar 2019 17:38:38 -0700 Subject: [PATCH 7/7] change handlers for sum command --- examples/searchcommands_app/package/default/logging.conf | 2 +- tests/searchcommands/test_searchcommands_app.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/examples/searchcommands_app/package/default/logging.conf b/examples/searchcommands_app/package/default/logging.conf index 1a5b8995b..69b082534 100644 --- a/examples/searchcommands_app/package/default/logging.conf +++ b/examples/searchcommands_app/package/default/logging.conf @@ -43,7 +43,7 @@ propagate = 0 ; Default: 1 [logger_SumCommand] qualname = SumCommand level = NOTSET ; Default: WARNING -handlers = stderr ; Default: stderr +handlers = splunklib ; Default: stderr propagate = 0 ; Default: 1 [handlers] diff --git a/tests/searchcommands/test_searchcommands_app.py b/tests/searchcommands/test_searchcommands_app.py index 0d19928f3..8945c3644 100755 --- a/tests/searchcommands/test_searchcommands_app.py +++ b/tests/searchcommands/test_searchcommands_app.py @@ -227,7 +227,7 @@ def test_sum_as_unit(self): 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.\n', errors) + self.assertEqual('', errors) self._compare_csv_files_time_sensitive(expected, output) expected, output, errors, exit_status = self._run_command('sum', action='execute', phase='reduce', protocol=1)