Easily Monitor Log File Output in OSX Terminal (tail -F)

Here's a quick tip that is a real time saver in some situations. As a developer you often come across programs, tools or servers that produce output in form of a log file. Or maybe - and this includes myself - you use logs for debugging purposes.

In ColdFusion for example I regularly find myself adding cflog tags to my code in order to get a view into what my code is doing. Having to open and close log files constantly can be tedious at best, but luckily there is a really simple way of displaying a live view of the most recent entries using the standard Unix tail -F command.

Whereas tail on its own simply displays the last part of a file, the -F option will not stop when the end of the file is reached but will keep monitoring the file for new lines and displaying them, thereby giving you effectively a live console view into the file.

Taking ColdFusion logs as an example, here's how you'd monitor a particular log file (mine are typically named according to the site or application I am working on):

view plain
1cd /Applications/ColdFusion9/logs/
2tail -F playingornot.log
3"Information","jrpp-4","02/21/12","17:40:30","PLAYINGORNOT","/index.cfm"
4"Information","jrpp-5","02/21/12","17:40:33","PLAYINGORNOT","/index.cfm"
5"Information","jrpp-5","02/21/12","17:40:35","PLAYINGORNOT","/cfc/Auth.cfc"
6"Information","jrpp-5","02/21/12","17:40:35","PLAYINGORNOT","/cfc/Players.cfc"
7"Information","jrpp-5","02/21/12","17:40:36","PLAYINGORNOT","/cfc/PlayTimes.cfc"
8"Information","jrpp-1","02/28/12","09:37:37","PLAYINGORNOT","/index.cfm"
9"Information","jrpp-1","02/28/12","09:37:40","PLAYINGORNOT","/cfc/Auth.cfc"
10"Information","jrpp-1","02/28/12","09:37:41","PLAYINGORNOT","/cfc/Players.cfc"
11"Information","jrpp-1","02/28/12","09:37:42","PLAYINGORNOT","/cfc/PlayTimes.cfc"
12"Information","jrpp-2","02/28/12","09:40:30","PLAYINGORNOT","/cfc/PlayTimes.cfc"

As my application runs I can see new entries being displayed in real time in my log file - very handy. This particular log is produced by adding

view plain
1<cflog file="#this.name#" type="information" text="#arguments.targetPage#">
to my Application.cfc's OnRequestStart handler.

This technique works for any kind of text based log file on operating systems that have the tail command or similar available.


Uploading Files To Amazon S3 With ColdFusion

Since version 9.0.1 (if I am not mistaken) ColdFusion supports Amazon's S3 file storage pretty much out of the box. The complexities of access control to your bucket is abstracted away and you can use S3 almost like a local file system. You can read more about it in the CF docs and on Ray Camden's blog.

My task at hand was to accept user submitted file uploads and store them in S3. According to the CF documentation the full set of cffile operations is supported, however I could not get it to work.
The following failed for me with a 'destination invalid' error:

view plain
1<cfset mydir = "s3://media.mysite.com/logos">
2<cffile action="upload" filefield="logo" destination="#mydir#" nameconflict="makeunique" charset="utf-8" />

Please note that in order for the s3:// syntax to resolve to your bucket you need to follow some setup steps which I won't cover here. Also watch out for a bug related to setting metadata.

› Read Full Article


System.Runtime.InteropServices.ExternalException With .NET in ColdFusion

Just a brief heads up if you are working with .NET components in ColdFusion. I've recently ported some CF code to a new server and suddenly saw this cryptic error: "System.Runtime.InteropServices.ExternalException".

It appeared that the line of code that was causing the error was

view plain
1<cfset img.Save("#newimg#")>
in which img is an instance of a .NET Bitmap object. I persevered and managed to get some clues from various .NET posts, some of which pointed at file system problems. I was able to determine that I was trying to write to a non-existent directory when calling the img.Save method. I fixed the directory path and pointed it to a valid location and it solved my issue.

An easy fix in the end but potentially hard to track down. And before you say anything, yes I should have wrapped all of this in a DirectoryExists() method in the first place :-)


Trimming ColdFusion List Items For Use In Cfqueryparam

Yesterday I was working on a new feature for the Scribblar.com API that would allow users to delete multiple rooms at once by passing in a series of roomids (in my case those roomids are varchars, an example roomid would be 'g8m2ps88').
In order to process these easily in one SQL statement I wanted to use the SQL IN statement.

view plain
1SELECT roomid, id from rooms
2WHERE roomid IN ( <cfqueryparam cfsqltype="cf_sql_varchar" value="#roomidlist#" list="true" separator="," /> )
This worked fine if the roomids were defined without spaces in between. The following list worked fine:
view plain
1<cfset roomids="g8m2ps88,u3s29kk">
The following worked without errors, but returned the wrong number of results:
view plain
1<cfset roomids="g8m2ps88, u3s29kk">
Spaces between the list elements would result in only one result from the SELECT IN query and I knew that that was wrong, I should see two results. It appeared that the list attribute in cfqueryparam would ignore any items after the space, even though dumping a Listlen(roomids,",") would correctly show all three items.

I had several options for fixing this, and since my roomids never contain any spaces themselves I simply removed any spaces that may exist. This is what I am using now:

view plain
1SELECT roomid, id from rooms
2WHERE roomid IN ( <cfqueryparam cfsqltype="cf_sql_varchar" value="#Replace(roomids, ' ', '', 'all')#" list="true" separator="," /> )
I double checked with Ray Camden as I wasn't sure if I had overlooked another obvious solution (thanks for your advice Ray!), but Mr Jedi himself approved of my workaround - the only caveat being that this will not work if your roomids contain spaces themselves (such as '3kd 933js').

Hope this helps someone, it certainly took me a little while to figure out what was going on.


Some Tips For ColdFusion Remoting Over SSL in Flex

I apologise in advance for this slightly unstructured post but this topic has been in the back of my mind for a while, so before I completely forget the details I btter write it down.

I've recently had to port one of my Flex applications, a simple CRUD admin console hitting a MySQL database via CF9, to use a Remoting connection over SSL. I recalled hat in the past this setup had given me some headaches: 'normal' CF Remoting from Flex over HTTP was pretty simple to get going, but switching to HTTPS had not been as simple. Therefore here is a quick checklist (and note: it may be incomplete) if you have the same task at hand.

› Read Full Article


Configuring an Access Database on ColdFusion for 64bit Windows 2008

I've just had to move a website from one Windows 2008 R2 Server (64bit) to another. The site was running on an Access database backend (don't ask...!) and I had forgotten how I managed to set up the datasource a couple of years ago - however I do remember that it was a PITA.

Unsurprisingly it took me a good 2 hours again today until the site was back up and running on the new server and there were a couple of things involved (at least I think these two steps are the important ones):
1) Make sure your site runs in a 32bit Application Pool in IIS. Ok, admittedly I am no longer 100% sure if this is needed but it works for me. I set up the site in IIS and configured it to use its own separate Application Pool. Then I selected 'Application Pools' in the tree under the server node in IIS, selected my site's Application Pool, then chose 'Advanced Settings' on the right under 'Edit Application Pool' and in the window that opened I set 'Enable 32-Bit Applications' to True. I also changed the '.NET Framework Version' to 'No managed code' in order to disable .NET altogether for this site (it does not use .NET and I think some server error 500s I was seeing were caused by this, however I cannot be sure anymore. What I am sure about though is that my site works using this setting :-)

2) Next I needed to set up the datasource. Usually you do this in CF Admin but if you try this on a 64bit Windows machine it is likely that you're presented with an error. If you use the OS's ODBC Data Source Admin then you won't see any Access Drivers listed because the default ODBC Admin is the 64bit version and that one does not have an Access Driver. You must therefore use the 32bit version which can be found at C:\Windows\SysWOW64\odbcad32.exe

Once I set up my datasource using this tool I was able to get my site up and running again.
Hope this helps someone. And no, the site in question is not this blog :-P


Securing Remoting Access To ColdFusion CFCs From Flex

Today I was working on a Flex application which uses a lot of Remoting calls to a bunch of ColdFusion CFC methods. I wondered what the most efficient way of securing these methods would be since they are effectively wide open to the world as they all (have to) specify access="remote". This means that anyone with a web browser can invoke the methods and they will even return nice error messages when certain parameters are missing.
One way of restricting access would be to run all Remoting calls through an intermediate page or CFC which handles authentication and access control and which in turn invokes the (now private) CFC methods. I found this a bit cumbersome and I also knew that there was a better way - I remembered the setCredentials method back from the AS2 days. You can see this described in greater detail by Brandon Purcell in his MAX session Securing Applications from 2003(!), but unfortunately it is not directly usable in today's Flex world.

While Brandon's example is great, and Ray Camden also has some details to add, neither example had all the pieces I needed, particularly an example of not just authenticating a Flex application properly with a CFC but also how to log out again (and to jump ahead, simply running a cflogout tag did not work...).

› Read Full Article


Installing ColdFusion 9 on Windows Server 2008 64bit

This blog is slowly turning into a ColdFusion site it seems :-) Blame ColdFusion for that, it's the one application server that I know a bit about and I really like working with.
Today I needed to install CF9 on Windows Server 2008 64bit and I ran into a few issues which forced me to reinstall a few times. I've now managed to install it successfully so here are a two tips that may safe you some hassle if you like me encounter a HTTP Error 404.3 - Not Found.

First off, I was using IIS 7.5. As you may know, you need to install the web server role onto Windows Server 2008 first and it seems that everything labeled IIS6 tools and compatibility tools should be installed as well, so do that first. Then when running the CF installer right click and 'Run as Administrator'. Once I did that it was plain sailing, but not much joy without those two boxes ticked.


Installing ColdFusion 9 on OSX Snow Leopard with MAMP

I've had a few issues getting ColdFusion 9 to run under OSX when trying to leverage an existing MAMP install (note: I was not using MAMP Pro. If you are using MAMP Pro then Mike has got some advice for you).

I have not got enough time right now to run the whole install process again and take screenshots along the way but I'll do my best to summarise what I think may help some others who want to use MAMP and CF9 together. I took some hints from this excellent post by Paul Pounder, however my install differed in that I chose a single server installation. Saying that, I think I encountered similar permission issues as the ones that Paul describes.

› Read Full Article


Tip for Debugging Remoting Calls in Flex Builder 3

Imagine the times when Flash Builder (Gumbo) was still in beta, times when the Network Monitor was still only a twinkle in the corner of a Flex engineer's eye. Imagine... your current day job, and a Flex 3 project with a bit of ColdFusion powered Remoting (other Remoting gateways are available) thrown in. Which is going wrong. And you need to debug the Remoting calls.
Ok, that doesn't require much imagination, I know. We know that Flash Builder will make our lives somewhat easier when it finally ships, but in the meantime your boss doesn't allow you to run beta software so what does one do besides coming to work for me? And maybe, just maybe, your boss is really mean (unlike myself) and won't even pay out for a license of Charles. So now what?

I present to you . It's a little tag tat does wonders to your Flex Builder 3 Console, and I don't know why it isn't being promoted much more. I've been using it for quite a while, and while I do not recall how I discovered it I am sure it's never too late to tell the world all about it.

So what does TraceTarget do? In a nutshell it outputs a ton of logging information into your Console when you debug your Flex project, and in particular it tells you a lot about the Remoting calls that you are undoubtedly making. Here's an example of my current project, first without TraceTarget added:

view plain
1[SWF] Users:stefan:Documents:dev:flex:fb3:demo:bin-debug:index.swf - 1,379,424 bytes after decompression
2result getUserDetails
Yeah, nothing basically besides one trace that I out in there to signal the return from CF. Now let's add to the main.mxml file and debug the app again:
view plain
1[SWF] Users:stefan:Documents:dev:flex:fb3:demo:bin-debug:index.swf - 1,383,632 bytes after decompression
2'9670B130-68C5-3D75-D251-3D30C4A99F2E' producer set destination to 'ColdFusion'.
3'F2AF48B3-896A-FA9D-D77A-3D30C4AF2A71' producer set destination to 'ColdFusion'.
4'8495032E-7DE7-49B1-124E-3D30C4EB0643' producer set destination to 'ColdFusion'.
5'8495032E-7DE7-49B1-124E-3D30C4EB0643' producer sending message '17E7B79A-6D4E-21C3-4F67-3D30C4EE538F'
6'my-cfamf' channel endpoint set to http://www.demo.com/flex2gateway/
7'my-cfamf' channel settings are:
8<channel id="my-cfamf" type="mx.messaging.channels.AMFChannel">
9 <endpoint uri="http://www.demo.com/flex2gateway/"/>
10 <properties>
11 <polling-enabled>false</polling-enabled>
12 </properties>
13</channel>
14'my-cfamf' pinging endpoint.
15'my-cfamf' channel is connected.
16'my-cfamf' channel sending message:
17(mx.messaging.messages::RemotingMessage)#0
18 body = (Array)#1
19 [0] "abcd"
20 clientId = (null)
21 destination = "ColdFusion"
22 headers = (Object)#2
23 messageId = "17E7B79A-6D4E-21C3-4F67-3D30C4EE538F"
24 operation = "getRoomDetails"
25 source = "api.v1.private.rooms"
26 timestamp = 0
27 timeToLive = 0
28'8495032E-7DE7-49B1-124E-3D30C4EB0643' producer connected.
29'8495032E-7DE7-49B1-124E-3D30C4EB0643' producer acknowledge of '17E7B79A-6D4E-21C3-4F67-3D30C4EE538F'.
301
31'9670B130-68C5-3D75-D251-3D30C4A99F2E' producer sending message '01B287E5-5EF5-1B40-75EE-3D30C648A026'
32'9670B130-68C5-3D75-D251-3D30C4A99F2E' producer connected.
33'my-cfamf' channel sending message:
34(mx.messaging.messages::RemotingMessage)#0
35 body = (Array)#1
36 clientId = (null)
37 destination = "ColdFusion"
38 headers = (Object)#2
39 messageId = "01B287E5-5EF5-1B40-75EE-3D30C648A026"
40 operation = "getUserDetails"
41 source = "api.v1.private.users"
42 timestamp = 0
43 timeToLive = 0
44'9670B130-68C5-3D75-D251-3D30C4A99F2E' producer acknowledge of '01B287E5-5EF5-1B40-75EE-3D30C648A026'.
45result getUserDetails

Pretty cool, right? You can read more about TraceTarget and other logging frameworks here. But if you just want a quick and dirty way to see some more debug info on your Remoting calls then you could do worse than simply sticking the TraceTarget tag into your main.mxml file and save yourself some hassle. It may not be as slick as Charles or the upcoming Network Monitor but it can be handy nevertheless. Have fun coding.


More Entries