├── .gitignore ├── LICENSE ├── README.asciidoc ├── _modules └── logger_mod.py └── _states └── logging.py /.gitignore: -------------------------------------------------------------------------------- 1 | # Byte-compiled / optimized / DLL files 2 | __pycache__/ 3 | *.py[cod] 4 | 5 | # C extensions 6 | *.so 7 | 8 | # Distribution / packaging 9 | .Python 10 | env/ 11 | build/ 12 | develop-eggs/ 13 | dist/ 14 | downloads/ 15 | eggs/ 16 | lib/ 17 | lib64/ 18 | parts/ 19 | sdist/ 20 | var/ 21 | *.egg-info/ 22 | .installed.cfg 23 | *.egg 24 | 25 | # PyInstaller 26 | # Usually these files are written by a python script from a template 27 | # before PyInstaller builds the exe, so as to inject date/other infos into it. 28 | *.manifest 29 | *.spec 30 | 31 | # Installer logs 32 | pip-log.txt 33 | pip-delete-this-directory.txt 34 | 35 | # Unit test / coverage reports 36 | htmlcov/ 37 | .tox/ 38 | .coverage 39 | .cache 40 | nosetests.xml 41 | coverage.xml 42 | 43 | # Translations 44 | *.mo 45 | *.pot 46 | 47 | # Django stuff: 48 | *.log 49 | 50 | # Sphinx documentation 51 | docs/_build/ 52 | 53 | # PyBuilder 54 | target/ 55 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) 2015 Joe Julian 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | 23 | -------------------------------------------------------------------------------- /README.asciidoc: -------------------------------------------------------------------------------- 1 | saltstack-logging 2 | ================= 3 | :Author: Joe Julian 4 | :Email: 5 | 6 | Logging Module for Salt 7 | 8 | Installation 9 | ------------ 10 | * Copy the contents of the +_modules+ and +_states+ directories into those same directories under your +'{file_roots}'+ on your *salt-master*. 11 | * Install the modules on the minions with +state.highstate+, or +saltutil.sync_all+ 12 | 13 | Documentation 14 | ------------- 15 | 16 | Use this module for outputting the contents of variables to the log file. You can output to each of the log levels: 17 | 18 | * debug 19 | * info 20 | * warning 21 | * error 22 | * critical 23 | 24 | Logs will be written to wherever you have salt configured to write logs. 25 | 26 | Examples 27 | -------- 28 | 29 | Execution Module 30 | ~~~~~~~~~~~~~~~~ 31 | 32 | [source,jinja] 33 | ---- 34 | {% set myvar = salt['pillar.get']('foo') %} 35 | {% do salt['logger.debug'](myvar, "(module) pillar[foo]: ") %} 36 | ---- 37 | 38 | With debug logging enabled, this might log: 39 | 40 | .Output 41 | ---- 42 | [DEBUG ] (module) pillar[foo]: {'aliases': ['fubar'], 43 | 'favorites': [{'foods': ['chocolate', 'strawberries']}, 44 | {'phrase': ['Oh! F@#%!']}], 45 | 'friends': ['bar', 'baz'], 46 | 'name': 'foo'} 47 | ---- 48 | 49 | State Module 50 | ~~~~~~~~~~~~ 51 | 52 | [source,jinja] 53 | ---- 54 | test: 55 | logging.error: 56 | - obj: {{ salt['pillar.get']('foo') }} 57 | - string: '(state) pillar[foo]: ' 58 | ---- 59 | 60 | Using the same pillar as the previous example: 61 | 62 | .Output 63 | ---- 64 | [ERROR ] (state) pillar[foo]: {'aliases': ['fubar'], 65 | 'favorites': [{'foods': ['chocolate', 'strawberries']}, 66 | {'phrase': ['Oh! F@#%!']}], 67 | 'friends': ['bar', 'baz'], 68 | 'name': 'foo'} 69 | ---- 70 | 71 | [NOTE] 72 | This example ouputs log level '*error*'. 73 | -------------------------------------------------------------------------------- /_modules/logger_mod.py: -------------------------------------------------------------------------------- 1 | # -*- coding: utf-8 -*- 2 | ''' 3 | Execution module to provide logging 4 | ========================== 5 | :maintainer: Joe Julian 6 | :maturity: new 7 | :platform: Linux 8 | .. versionadded:: 2014.7.0 9 | ''' 10 | 11 | __virtualname__ = 'logger' 12 | 13 | import logging as log 14 | from pprint import pformat 15 | import json 16 | import yaml 17 | 18 | def pretty(var): 19 | return pformat(yaml.load(json.dumps(var))) 20 | 21 | def __virtual__(): 22 | return __virtualname__ 23 | 24 | def debug(var, string = ""): 25 | ''' 26 | Print a var to a debug output. 27 | ''' 28 | ret = string + pretty(var) 29 | log.debug(ret) 30 | return ret 31 | 32 | def info(var, string = ""): 33 | ''' 34 | Print a var to a info output. 35 | ''' 36 | ret = string + pretty(var) 37 | log.info(ret) 38 | return ret 39 | 40 | def warning(var, string = ""): 41 | ''' 42 | Print a var to a warning output. 43 | ''' 44 | ret = string + pretty(var) 45 | log.warning(ret) 46 | return ret 47 | 48 | def error(var, string = ""): 49 | ''' 50 | Print a var to a error output. 51 | ''' 52 | ret = string + pretty(var) 53 | log.error(ret) 54 | return ret 55 | 56 | def critical(var, string = ""): 57 | ''' 58 | Print a var to a critical output. 59 | ''' 60 | ret = string + pretty(var) 61 | log.critical(ret) 62 | return ret 63 | -------------------------------------------------------------------------------- /_states/logging.py: -------------------------------------------------------------------------------- 1 | # -*- coding: utf-8 -*- 2 | ''' 3 | Logging output 4 | ========================== 5 | :maintainer: Joe Julian 6 | :maturity: new 7 | :platform: Linux 8 | .. versionadded:: 2014.7.0 9 | :configuration: See :py:mod:`salt.modules.logging` for setup instructions. 10 | .. code-block:: yaml 11 | debugmyvar: 12 | logger.debug: 13 | - name: myvar 14 | - string: "myvar is :" 15 | ''' 16 | 17 | __virtual_name__ = 'logging' 18 | 19 | def __virtual__(): 20 | return __virtual_name__ 21 | 22 | def debug(name, obj, string = ''): 23 | ret = {'name': name, 24 | 'changes': {}, 25 | 'result': True, 26 | 'comment': __salt__['logger.debug'](obj, string)} 27 | return ret 28 | 29 | def info(name, obj, string = ''): 30 | ret = {'name': name, 31 | 'changes': {}, 32 | 'result': True, 33 | 'comment': __salt__['logger.info'](obj, string)} 34 | return ret 35 | 36 | def warning(name, obj, string = ''): 37 | ret = {'name': name, 38 | 'changes': {}, 39 | 'result': True, 40 | 'comment': __salt__['logger.warning'](obj, string)} 41 | return ret 42 | 43 | def error(name, obj, string = ''): 44 | ret = {'name': name, 45 | 'changes': {}, 46 | 'result': True, 47 | 'comment': __salt__['logger.error'](obj, string)} 48 | return ret 49 | 50 | def critical(name, obj, string = ''): 51 | ret = {'name': name, 52 | 'changes': {}, 53 | 'result': True, 54 | 'comment': __salt__['logger.critical'](obj, string)} 55 | return ret 56 | --------------------------------------------------------------------------------