English English Spanish EspañolKorea한국어

Server-side Logging

ZoomFlex server-side components can leverage the logging functionality provided by ShadoCMS. When using server-side logging, you need invoke the logging functionality and pass it a message that needs to be logged and the name of the log file to log the message to. If a log file already exists, the message is appended to the log file. If the log file does not exist, a new one is created and the message is written to it.

The syntax for using logging is:

<cfset application.shado.serviceManager.getService("logging").writeToLog(message="Some message will go here",source="[name of server-side component here]",type="debug",log="[name_of_app].[name_of_log]")>

 

In this code replace the [name of server-side component] with the name of the CFC that you are using this piece of code in, e.g., cars.cfc. Replace the [name_of_app] with name of your application, e.g., "gettingstarted". And replace the [name_of_log] with the name of the log file, e.g., cars. So the above example would look like like the following once you make the replacements:

<cfset application.shado.serviceManager.getService("logging").writeToLog(message="cars.cfc",source="[name of server-side component here]",type="debug",log="gettingstarted.cars")>

 

The base directory for log files is [yoursite]/app_config/logs directory. You can pass in path in dot notation, e.g., gettingstarted.cars, and it will create a directory called "gettingstarted" in the base logging directory, and then create a file callled "cars.cfm" inside that directory. You can then view the log file using RDS or FTP.

A typical scneario for using server-side logging in a ZoomFlex application would be if you have written a function in the server-side component, and wish to keep track of what is happening inside the function. You can multiple calls to the logging functionality from within that function.

Apart from being a debugging mechanism, server-side logging comes in handy as an auditing mechanism as well. For example, if you wanted to keep track of some server-side functionality, e.g., successful/unsuccessful logins, sending emails, any caught errors, you can use server-side logging as an auditing mechanism.

You can only write strings to log files. Complex data structures would need to be converted into string using a format like WDDX.

Also, server-side logging can be implemented in the server-side methods that you write. For the inherited methods, like all the CRUD functionality, you will have have override the functions first, implement logging, and then call the super method.

Next approach: Server-side Debug using <cfdump> »

 


Comments

There are no comments for this page as yet.

Add a comment