Accessing Application Logs In Bluemix

Being able to view your application’s log files is essential for any developer.  Developers use their log statements to gain insight into what is happening in their application throughout the application lifecycle.  Accessing your logs when running your application locally is easy, but when the application is deployed to a remote server things get a little bit trickier.  In the past, when deploying your app to your own infrastructure or even infrastructure-as-a-service (IaaS) you could access your like files via SSH or FTP.  With a platform-as-a-service (PaaS) things are much different, there is no way to SSH or FTP into the infrastructure running your app because that is all controlled by the platform.  In Cloud Foundry based PaaSes such as Bluemix, access to logs from an application are exposed via something called theLoggerator.  The Loggerator is a fantastic piece of software, but luckily as a developer you don’t need to know anything about it except for the fact all the logs from your application are made available through it.  The most common way to access log files is via the Cloud Foundry command line interface (CLI).

$ cf logs

If you are going to be doing development on Bluemix, than I suggest you install the Cloud Foundry CLI even if you are not a fan of the command line.  The tool is easy to use and there are plenty of guides out there that go through the details of using it.  In some cases the only option may be to use the CLI so it is a good tool to have installed.  One of the most useful commands in the CLI is cf logs.  cf logsallows you to access the logs from your application deployed to Bluemix right from your command line so it is extremely useful when doing development.  You can access a snapshot of recent logs or stream logs right to your command line.  Here are the basic uses.

cf logs appName –recent
This command will show a subset of recent logs from the application deployed to Bluemix with the name appName.

cf logs appName
This command will tail the logs from the application deployed to Bluemix with the name appName.  You will not be able to see any of the past logs with this command.

Here is a short video describing how to use cf logs.

I generally use cf logs when doing development and testing, I almost always have a window open tailing the logs of the application I am working on.  Tailing the log files of your application is very useful when deploying applications to Bluemix.  Often times you may run into errors when doing deployments to Bluemix and it is not clear what went wrong.  Your first instinct might be to run cf logs appName –recentto see what went wrong.  Unfortunately you will notice that in most cases the commands exits without showing you any logs.  This happens because the file system is temporary, meaning that the contents of the file system (including your logs) are lost when the application is stopped, and since your application failed to start your logs don’t stick around for too long.  To solve this problem what I do when I deploy an application is use cf logs appName to tail the logs while the deployment is taking place.  This works as long as the application is created in Bluemix by the time you run the command.  For a quick demo of how to do this take a look at this video.

Using Persistent Logging Services

Once your application is deployed and somewhat stable you will want to use a logging service.  There are a couple of reasons for wanting to use a logging service.  The first reason is using cf logs appName –recent will only allow you to see so far back in your logs.  The only way to view logs of your app over a long period of time is to use a logging service.  Second, as discussed above, logs are deleted after the application restarts, and restarts can happen as a normal corse of operation, especially if you are practicing continuous integration and delivery.  As with any type of cloud service you have a couple of options when it comes to logging services.

IBM’s Monitoring And Analytics

If you browse the Bluemix catalog you will come across the Monitoring and Analytics service.  This service can be used with any app using the IBM Liberty or Node.js runtimes.  This service offers a variety of additional features besides log collection but log collection comes in the free plan.  With this service you can only view logs from the past 24 hours, so if you need your logs to be persisted longer than 24 hours consider one of the 3rd party services.  The nice thing about this service is that it offers great searching functionality so you can easily identify patterns in your logs.  Here is a short video that describing how to use the Monitoring and Analytics service.

3rd Paty Logging Services

In addition to the Monitoring And Analytics service in the IBM Bluemix catalog, you are free to use any 3rd party logging service that supports the syslog protocol.  This includes services such as Papertail, Splunk Storm, SumoLogic, and Logentries.  To use one of these services you must first setup an account with one of them.  Most of them offer some level of functionality for free giving you an opportunity to try out each of them and pick the one you like best.  After picking a service to use, you will go through a process where you register the application with the service and it provides you with a syslog URL to use.  Once you have this URL the process of connecting the Loggerator in Bluemix to the 3rd party service is the same.  To do this you need to use the Cloud Foundry CLI to create whats called a user provided service (this is one of those cases where you need to use the CLI to do this).  The command is simple, just run

cf cups -l </em> </p>

In the above command, replace with any name you would like and with the URL you got from your 3rd party logging service.  The URL should begin with syslog://, for example here is an example of a URL from the Papertrail service. </p>

syslog://logs.papertrailapp.com:1234

Using 3rd party logging services is pretty simple as you can see in this video.

</div>

Why I Have Started To Embrace The Command Line

Last night my tweet inspired a debate on Twitter about the use of the command line.  Oddly enough I was in a meeting with a customer yesterday and due to some problem I encountered during my demo I had to open the command line.  Once I did this he immediately asked me “Do I need to use the command line?”.  (As a side note the person who asked this question was not a developer or system admin.)   In addition a few weeks ago at MWLUG, Nathan Freeman, who I have the utmost respect for as a person and a developer, stopped me in the middle of my presentation and told me he was completely lost because I was using the Git CLI.  So with so much talk about my use of the command line I figured I would explain why I use it.

Using Your Domino Data In Apps Deployed To Bluemix

Over the past few weeks I have done presentations on Bluemix at two ICS user groups, MWLUG and ICONUK.  I did pretty much the same presentation at both mainly focused on introducing developers to Bluemix.  Obviously, since these user groups are focused mainly around ICS, there is interest in how Domino and XPages fits into the Bluemix story.  Well as of right now you cannot deploy your XPages apps to Bluemix.  However, Kramer Reeves announced at MWLUG that ICS is investigating how to make this dream come true.  As we all know an investigation is no guarantee, so what is a Domino developer to do in the mean time?  While you can’t deploy your XPage applications, there is no reason why you can’t use the data stored in your NSFs.  You just need to use another runtime, such as Java, Node.js, Ruby, PHP, or any other runtime Bluemix supports, to build the front end and business logic of your application.

Deploying Your Hybrid Cloud Apps Has Never Been Easier With Bluemix

Public clouds are great.  They offer great elasticity and cost savings, and in the case of a PaaS like Bluemix, allows us (developers) to forget about maintaining any infrastructure and focus in on our code.  However we all realize that public cloud can’t be used for everything.  There are some applications and services that must remain in our own data centers on private networks.  The reasons why vary, maybe it is too much work to move the resource to the cloud, or maybe the data in the resource is too sensitive to risk exposing outside of your firewall.  Whatever the reason may be, you are bound to come across a scenario where you need to access private resources in your public cloud applications.  What are your options?  One option is to try to setup some type of VPN and create a secure connection between the public cloud and your private network.  This is probably the route to take if you are using an IaaS provider like SoftLayer to run your application.  With a PaaS this is not possible, you don’t have access to the machine your application is running on or the network it is using, so if you choose Bluemix to deploy your application what are your options?

Bluemix Session At MWLUG

mwlug2014_banner

Upcoming Bluemix Days For My Canadian Friends

If you live “north of the border” (to me anyways) there are a number of Bluemix Days that are coming up that you might be interested in attending.  This is a great opportunity to learn more about Bluemix and get started building your first app.  See the below flyer for more details and dates.

Webinar: Building Highly Scalable Applications With Bluemix

The elasticity of the cloud is a huge selling point for most developers when considering where to deploy their applications.  The ability to add and remove instances of your application based on the load against it saves you a lot of time and money.  However you can’t just deploy any application to the cloud and expect it will behave properly when scaled horizontally.  In fact, if you didn’t think about scalability when building your application chances are your application will break when scaled.

Replay of the Bluemix Virtual Meetup on Mobile Services

Watch Today’s Bluemix Virtual Meetup Live On YouTube

You can watch today’s Bluemix Virtual Meetup on mobile cloud services live at 10 AM EST on YouTube.  There are 3 options for watching.

Build a REST API For Your IoT Data Using MongoDB, Node-RED, and Bluemix

In my previous post I talked about how to use the IBM IoT Cloud and Bluemix to build apps based on data coming from an TI Sensor Tag.  One of the apps I showed was Node-RED, however it was very basic in that it only printed the data to a debug node.  In this video I show you how you can store that data in a MongoDB and create a REST API for the data all in Node-RED without writing any code!  Enjoy!