Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 32 additions & 3 deletions module_utils/juniper_junos_common.py
Original file line number Diff line number Diff line change
Expand Up @@ -332,7 +332,7 @@ class ModuleDocFragment(object):
- The log file must be writeable. If the file already exists, it is
appended. It is the users responsibility to delete/rotate log files.
- The level of information logged in this file is controlled by
Ansible's verbosity and debug options
Ansible's verbosity, debug options and level option in task
- 1) By default, messages at level C(WARNING) or higher are logged.
- 2) If the C(-v) or C(--verbose) command-line options to the
C(ansible-playbook) command are specified, messages at level
Expand All @@ -341,6 +341,8 @@ class ModuleDocFragment(object):
C(ansible-playbook) command is specified, or the C(ANSIBLE_DEBUG)
environment variable is set, then messages at level C(DEBUG) or
higher are logged.
- 4) If C(level) is mentioned then messages at level C(level) or more are
logged.
- The I(logfile) and I(logdir) options are mutually exclusive. The
I(logdir) option is recommended for all new playbooks.
required: false
Expand All @@ -355,7 +357,7 @@ class ModuleDocFragment(object):
- The log file must be writeable. If the file already exists, it is
appended. It is the users responsibility to delete/rotate log files.
- The level of information logged in this file is controlled by
Ansible's verbosity and debug options
Ansible's verbosity, debug options and level option in task
- 1) By default, messages at level C(WARNING) or higher are logged.
- 2) If the C(-v) or C(--verbose) command-line options to the
C(ansible-playbook) command are specified, messages at level
Expand All @@ -364,6 +366,8 @@ class ModuleDocFragment(object):
C(ansible-playbook) command is specified, or the C(ANSIBLE_DEBUG)
environment variable is set, then messages at level C(DEBUG) or
higher are logged.
- 4) If C(level) is mentioned then messages at level C(level) or more are
logged.
- When tasks are executed against more than one target host,
one process is forked for each target host. (Up to the maximum
specified by the forks configuration. See
Expand All @@ -381,6 +385,27 @@ class ModuleDocFragment(object):
type: path
aliases:
- log_file
level:
description:
- The level of information to be logged can be modified using this option
- 1) By default, messages at level C(WARNING) or higher are logged.
- 2) If the C(-v) or C(--verbose) command-line options to the
C(ansible-playbook) command are specified, messages at level
C(INFO) or higher are logged.
- 3) If the C(-vv) (or more verbose) command-line option to the
C(ansible-playbook) command is specified, or the C(ANSIBLE_DEBUG)
environment variable is set, then messages at level C(DEBUG) or
higher are logged.
- 4) If C(level) is mentioned then messages at level C(level) or more are
logged.
required: false
default: WARNING
type: str
choices:
- INFO
- DEBUG


'''

# _SUB_CONNECT_DOCUMENTATION is just _CONNECT_DOCUMENTATION with each
Expand Down Expand Up @@ -497,7 +522,8 @@ class ModuleDocFragment(object):
# Specify the logging spec.
logging_spec = {
'logfile': dict(type='path', required=False, default=None),
'logdir': dict(type='path', required=False, default=None)
'logdir': dict(type='path', required=False, default=None),
'level': dict(choices=[None, 'INFO', 'DEBUG'], required=False, default=None)
}

# The logdir and logfile options are mutually exclusive.
Expand Down Expand Up @@ -874,6 +900,9 @@ def process(self, msg, kwargs):
level = logging.INFO
elif self._verbosity > 1:
level = logging.DEBUG
# Set level as mentioned in task
elif self.params.get('level') is not None:
level = self.params.get('level')
# Get the logger object to be used for our logging.
logger = logging.getLogger('jnpr.ansible_module.' + self.module_name)
# Attach the NullHandler to avoid any errors if no logging is needed.
Expand Down