Skip to content

Commit 75421e8

Browse files
author
David Noble
committed
splunklib.searchcommands.logging update
- Updated probing path for logging configuration file - Updated logging.conf files to prevent creation of the file referenced in the file handler section The Python logger creates all files fully realizes all logging handler, whether they're used or not.
1 parent b65ff69 commit 75421e8

File tree

4 files changed

+19
-21
lines changed

4 files changed

+19
-21
lines changed

examples/searchcommands_app/default/app.conf

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ author = Splunk
1010
version = 1.0
1111

1212
[package]
13-
id = custom_search_commands
13+
id = searchcommands_app
1414

1515
[install]
1616
is_configured = 1

examples/searchcommands_app/default/logging.conf

Lines changed: 5 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2,32 +2,26 @@
22
keys = root, CountMatchesCommand, SimulateCommand, SumCommand
33

44
[logger_root]
5-
level = DEBUG ; Default: WARNING
5+
level = DEBUG ; Default: WARNING
66
handlers = stderr ; Default: stderr
77

88
[logger_CountMatchesCommand]
99
qualname = CountMatchesCommand
10-
level = NOTSET ; Default: WARNING
10+
level = NOTSET ; Default: WARNING
1111
handlers = stderr ; Default: stderr
1212

1313
[logger_SimulateCommand]
1414
qualname = SimulateCommand
15-
level = NOTSET ; Default: WARNING
15+
level = NOTSET ; Default: WARNING
1616
handlers = stderr ; Default: stderr
1717

1818
[logger_SumCommand]
1919
qualname = SumCommand
20-
level = NOTSET ; Default: WARNING
20+
level = NOTSET ; Default: WARNING
2121
handlers = stderr ; Default: stderr
2222

2323
[handlers]
24-
keys=file, stderr
25-
26-
[handler_file]
27-
class = logging.FileHandler
28-
level = NOTSET
29-
args = ('custom_search_commands.log',)
30-
formatter = search_command
24+
keys=stderr
3125

3226
[handler_stderr]
3327
class = logging.StreamHandler

examples/searchcommands_scaffolding/default/logging.conf

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -11,13 +11,7 @@ level = WARNING ; Default: WARNING
1111
handlers = stderr ; Default: stderr
1212

1313
[handlers]
14-
keys=file, stderr
15-
16-
[handler_file]
17-
class = logging.FileHandler
18-
level = NOTSET
19-
args = ('%(app_id).log',)
20-
formatter = search_command
14+
keys=stderr
2115

2216
[handler_stderr]
2317
class = logging.StreamHandler

splunklib/searchcommands/logging.py

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,14 +43,24 @@ def configure(cls, path=None):
4343
The current directory is reset to its previous value before this function
4444
returns.
4545
46+
#Arguments:
47+
4648
:param cls: Class contained in <app-root>/bin/<module>.py
49+
:type cls: type
4750
:param path: Location of an alternative logging configuration file or `None`
51+
:type path: str or NoneType
4852
4953
"""
54+
logger_name = cls.__name__
5055
module = inspect.getmodule(cls)
5156
app_directory = os.path.dirname(os.path.dirname(module.__file__))
5257
if path is None:
53-
for relative_path in 'local/logging.conf', 'default/logging.conf':
58+
probing_path = [
59+
'local/%s.logging.conf' % logger_name,
60+
'default/%s.logging.conf' % logger_name,
61+
'local/logging.conf',
62+
'default/logging.conf']
63+
for relative_path in probing_path:
5464
configuration_file = os.path.join(app_directory, relative_path)
5565
if os.path.exists(configuration_file):
5666
path = configuration_file
@@ -63,5 +73,5 @@ def configure(cls, path=None):
6373
fileConfig(path)
6474
finally:
6575
os.chdir(working_directory)
66-
logger = getLogger(cls.__name__)
76+
logger = getLogger(logger_name)
6777
return logger, path

0 commit comments

Comments
 (0)