how to debug state ?

1,273 views
Skip to first unread message

ch huang

unread,
Oct 12, 2013, 4:33:13 AM10/12/13
to salt-...@googlegroups.com
hi,all:
        i want to print some info to log (master ? minion?) ,so i can understand how the state work though checking log output
for example i have the follow python code
 
for i in pillar[grain['host']]:
       log.info(' handle i in loop...')
         start['xxx'] = {
                   ......
                    }
 
how can i modify code to do this?

Colton Myers

unread,
Oct 14, 2013, 12:01:51 PM10/14/13
to salt-...@googlegroups.com
In almost any salt state or execution module, the logger has already been instantiated as `log`, so you can just use `log.info('string')` or `log.debug('string')`.  Not exactly sure what you're asking, but I hope that helps.

--
Colton Myers


--
You received this message because you are subscribed to the Google Groups "Salt-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to salt-users+...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.

Mrten

unread,
Oct 14, 2013, 3:54:13 PM10/14/13
to salt-...@googlegroups.com
On 14/10/2013 18:01 , Colton Myers wrote:

> In almost any salt state or execution module, the logger has already
> been instantiated as `log`, so you can just use `log.info
> <http://log.info>('string')` or `log.debug('string')`. Not exactly
> sure what you're asking, but I hope that helps.

is this in the docs? :)

I usually end up with

fil = open('/tmp/dump','a+')
fil.write(repr(XXX))

in py and mako states/pillars. in jinja you're just out of luck afaik.

M.

Colton Myers

unread,
Oct 14, 2013, 4:48:10 PM10/14/13
to salt-...@googlegroups.com
Ah, well, I was referring to the actual python modules for states and modules.  The original post was not clear about the context.

--
Colton Myers


ch huang

unread,
Oct 15, 2013, 8:46:43 PM10/15/13
to salt-...@googlegroups.com
i use this ,run it ,can not see string "help me out" on both master log file and minion log file
# cat demo.sls
#!py
import logging
log = logging.getLogger(__name__)
def run():
        state = {}
        log.debug('help me out')
        return state
 

在 2013年10月15日星期二UTC+8上午4时48分10秒,basepi写道:

Shawn Milochik

unread,
Oct 15, 2013, 11:56:51 PM10/15/13
to salt-...@googlegroups.com
I don't know whether that logger you instantiated will get pulled into the Salt logs, but in any case I believe their level is set too high for 'debug.' Try 'critical.' 


Reply all
Reply to author
Forward
0 new messages