Tropo is part of CiscoLearn More

Logging from your application

In many cases, Tropo logging alone will give you the information you need to troubleshoot any issues. But if you want to check specific items - the value of variables, the results of function calls and events - then you can log your own data to our logs.

With Tropo Scripting, there's a log function that enables you to insert whatever you want into the log. You give it a string as the only parameter, it interprets it and adds the result into the log with the other debugging information.

log("Call was from: " + currentCall.callerID);
log "Call was from: " + $currentCall.callerID
_log("Call was from: " . $currentCall->callerID);
log("Call was from: " + currentCall.callerID)
log("Call was from: " + currentCall.callerID)

The example above shows how you could insert the caller ID of the current call into the log. Note that with PHP, it's _log rather than log; the logarithm function in PHP already lays claim to log.

With WebAPI, you'll need to utilize one of the libraries and work with the logging built into the language (either to the console or to an actual log). The Handling Call Failure Quickstart contains examples for Ruby, Node.js, PHP and Python; here's an abbreviated form:

require 'tropo-webapi-ruby'
require 'sinatra'

post '/index.json' do
  
  t = Tropo::Generator.new
  
  t.call(:to => "Q")
  t.say(:value => "Tag, you're it!")
  
  t.on :event => 'incomplete', :next => '/incomplete.json'

  t.response
  
end

post '/incomplete.json' do
  puts "The call did not complete."
end
var sys = require('sys');
var express = require('express');
var app = express.createServer();
var tropo_webapi = require('tropo-webapi');

app.post('/', function(req, res){
	
	var tropo = new TropoWebAPI();
	
	tropo.call("Q");
	tropo.say("Tag, you're it!!");

	tropo.on("incomplete", null, "/incomplete", true);
	
	res.send(TropoJSON(tropo));
});
	
app.post('/incomplete', function(req, res){
	console.log("The call did not complete.");
});	

app.listen(8000);
console.log('Server running on port :8000');
<?php
 
require 'tropo.class.php';
require 'lib/limonade.php';

dispatch_post('/start', 'app_start');
function app_start() {
	     
	$tropo = new Tropo();
     
	$tropo->call("Q"); 
	$tropo->say("Tag, you're it!");
 
	$tropo->on(array("event" => "incomplete", "next" => "hello_world.php?uri=incomplete"));

	return $tropo->RenderJson();

}

dispatch_post('/incomplete', 'app_incomplete');
function app_incomplete() {
	error_log("The call did not complete.");
}

run();

?>
from itty import *
from tropo import Tropo

@post('/index.json')
def index(request):

	t = Tropo()

	t.call("Q")
	t.say("Tag, you're it!")
	
	t.on(event = "incomplete", next ="/incomplete.json")
	
	return t.RenderJson()
	
@post("/incomplete.json")
def index(request):
	
	print "The call did not complete."

run_itty(server='wsgiref', host='0.0.0.0', port=8888)

Note that if you use PHP, the above example includes the Limonade framework, so you would need to define the end of the start URL in Tropo to include the resource name, like http://www.example.com/test.php?uri=start: