@@ -37,10 +37,12 @@ static void ami_callback(struct ami_session *ami, struct ami_event *event)
3737{
3838 const char * eventname = ami_keyvalue (event , "Event" );
3939 (void ) ami ;
40- printf ("(Callback) Event Received: %s\n" , eventname );
41- #ifdef PRINT_EVENTS
42- ami_dump_event (event ); /* Do something with event */
43- #endif
40+ if (ami_debug_level (ami ) >= 1 ) {
41+ printf ("(Callback) Event Received: %s\n" , eventname );
42+ }
43+ if (ami_debug_level (ami ) >= 2 ) {
44+ ami_dump_event (event ); /* Do something with event */
45+ }
4446 ami_event_free (event ); /* Free event when done with it */
4547}
4648
@@ -133,7 +135,9 @@ static int single_ami_command(struct ami_session *ami)
133135 fprintf (stderr , "AMI action '%s' failed\n" , action );
134136 return -1 ;
135137 }
136- ami_dump_response (resp );
138+ if (ami_debug_level (ami ) >= 1 ) {
139+ ami_dump_response (resp );
140+ }
137141 ami_resp_free (resp ); /* Free response when done with it (just LF or CR LF) */
138142 return 1 ;
139143}
@@ -198,11 +202,14 @@ int main(int argc,char *argv[])
198202 return -1 ;
199203 }
200204
205+ ami_set_debug_level (NULL , debug );
206+ ami_set_debug (NULL , STDERR_FILENO );
201207 ami = ami_connect (ami_host , 0 , ami_callback , ami_disconnect_callback );
202208 if (!ami ) {
203209 fprintf (stderr , "Failed to connect to %s\n" , ami_host );
204210 return -1 ;
205211 }
212+
206213 ami_set_debug_level (ami , debug );
207214 ami_set_debug (ami , STDERR_FILENO );
208215 ami_set_discard_on_failure (ami , 0 );
@@ -211,7 +218,9 @@ int main(int argc,char *argv[])
211218 return -1 ;
212219 }
213220
214- fprintf (stderr , "*** Successfully logged in to AMI on %s (%s) ***\n" , ami_host , ami_username );
221+ if (ami_debug_level (ami ) >= 1 ) {
222+ fprintf (stderr , "*** Successfully logged in to AMI on %s (%s) ***\n" , ami_host , ami_username );
223+ }
215224 while (single_ami_command (ami ) > 0 );
216225 ami_disconnect (ami );
217226 ami_destroy (ami );
0 commit comments