~vila/byoci/trunk

« back to all changes in this revision

Viewing changes to byoci/monitor/options.py

  • Committer: Vincent Ladeuil
  • Date: 2018-02-18 18:22:55 UTC
  • mto: (157.2.7 shared-secrets)
  • mto: This revision was merged to the branch mainline in revision 158.
  • Revision ID: v.ladeuil+lp@free.fr-20180218182255-45vwiejg6snzyqls
Fix logging for all byo-ci-* commands using specific stacks.

Show diffs side-by-side

added added

removed removed

Lines of Context:
13
13
#
14
14
# You should have received a copy of the GNU General Public License along with
15
15
# this program.  If not, see <http://www.gnu.org/licenses/>.
 
16
import logging
 
17
import sys
16
18
 
17
19
from byoci import options
18
20
 
51
53
register(options.Option('slave.idle.delay', default='5',
52
54
                        help_string='''\
53
55
The delay (in minutes) before stopping a slave.'''))
 
56
 
 
57
 
 
58
######################################################################
 
59
# logging options (shamelessly copied from byov)
 
60
######################################################################
 
61
def level_from_store(s):
 
62
    val = None
 
63
    try:
 
64
        # Yes, _levelNames and _nameToLevel are private, but better use a
 
65
        # private than duplicate its content and get out of date.
 
66
        if sys.version_info < (3,):
 
67
            valid_levels = logging._levelNames
 
68
        else:
 
69
            valid_levels = logging._nameToLevel
 
70
        val = valid_levels[s.upper()]
 
71
    except KeyError:
 
72
        pass
 
73
    return val
 
74
 
 
75
 
 
76
register(options.Option('logging.level', default='ERROR',
 
77
                        from_unicode=level_from_store,
 
78
                        help_string='''\
 
79
Logging level (same as python: error, warning, info, debug).'''))
 
80
 
 
81
register(options.Option('logging.format',
 
82
                        default='%(asctime)s %(levelname)s %(message)s',
 
83
                        help_string='''\
 
84
Logging format (see python doc).'''))