summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDavid Schmitt <david@black.co.at>2016-10-08 18:28:22 +0100
committerDavid Schmitt <david@black.co.at>2016-10-09 22:03:32 +0100
commitbec521e6b79dd612a73e742d1cb6371e17ade1a9 (patch)
treeae483c1f2c14cbf5919e4e0679057677cc02003e
parente44238a9c7da7ad4a872ba86cd103becadd51b3b (diff)
Update deprecation() so warnings can be disabled for CI
-rw-r--r--README.markdown15
-rw-r--r--lib/puppet/functions/deprecation.rb4
2 files changed, 17 insertions, 2 deletions
diff --git a/README.markdown b/README.markdown
index 838a065..c90c9c3 100644
--- a/README.markdown
+++ b/README.markdown
@@ -344,7 +344,20 @@ Deletes all instances of the undef value from an array or hash. For example, `$h
#### `deprecation`
-Prints deprecation warnings and logs a warning once for a given key. The uniqueness key - can appear once. The msg is the message text, including any positional information that is formatted by the user or caller of the method. The Puppet setting 'strict' affects this function. Set 'strict' to :error to output an error message, :off to output no message or error, or :warning (default) to output a warning. In Puppet versions lower than 4.0, you can set an environment variable to decide whether or not to log deprecation warnings (`ENV[STDLIB_LOG_DEPRECATION]`). If this environment variable is set to true, the functions log a warning. *Type*: String, String.
+Prints deprecation warnings and logs a warning once for a given key:
+
+```
+deprecation(key, message)
+```
+
+* key: to keep the number of messages low, during the lifetime of a puppet process, only one message per key is logged.
+* message: the text to be logged.
+
+The Puppet settings '[disable_warnings](https://docs.puppet.com/puppet/latest/reference/configuration.html#disablewarnings)', '[max_deprecations](https://docs.puppet.com/puppet/latest/reference/configuration.html#maxdeprecations)', and '[strict](https://docs.puppet.com/puppet/latest/reference/configuration.html#strict)' affect this function. Set 'strict' to `error` to fail immediately with the deprecation message, `off` to output emit no messages at all, or `warning` (default) to log all warnings.
+
+Additionally you can set the environment variable `STDLIB_LOG_DEPRECATION` to decide whether or not to log deprecation warnings: if this environment variable is set to `true`, the functions log a warning, if it is set to `false`, no warnings are logged. If no value is set at all, Puppet 4 will emit warnings, while Puppet 3 will not. Using this setting is especially useful for automated tests to avoid flooding your logs before you are ready to migrate.
+
+*Type*: String, String.
#### `difference`
diff --git a/lib/puppet/functions/deprecation.rb b/lib/puppet/functions/deprecation.rb
index 6b7b977..a860aa2 100644
--- a/lib/puppet/functions/deprecation.rb
+++ b/lib/puppet/functions/deprecation.rb
@@ -15,7 +15,9 @@ Puppet::Functions.create_function(:deprecation) do
when :error
fail("deprecation. #{key}. #{message}")
else
- Puppet.deprecation_warning(message, key)
+ unless ENV['STDLIB_LOG_DEPRECATIONS'] == 'false'
+ Puppet.deprecation_warning(message, key)
+ end
end
end
end