Skip to main content
Participant
April 19, 2014
Question

Logging logs

  • April 19, 2014
  • 2 replies
  • 3676 views

Hello,

In coldfusion there is error and information log types.

In developer server i want to log both log type and in production server i want to log only error type log.

so is it possible??

If yes the how?

This topic has been closed for replies.

2 replies

Legend
April 22, 2014

Another option is to research log4j as this is what ColdFusion uses for cflog. Myself, I bypass the cflog layer and instead create my own org.apache.log4j.Logger instance. This might sound cryptic but if you plan to write and maintain production applications in CF, the time you spend researching this route is well worth it as log4j handles the log level via a config setting so you can have various levels: debug, info, warn, error.

Anit_Kumar
Community Manager
Community Manager
April 22, 2014

In case of ColdFusion 10, go to \cfusion\runtime\conf\logging.properties. Set org.apache.catalina.core.ContainerBase.[Catalina].[localhost].level to WARN and then restart ColdFusion services.

Regards,

Anit Kumar

Known Participant
April 23, 2014

When i try to

Set org.apache.catalina.core.ContainerBase.[Catalina].[localhost].level to WARN in \cfusion\runtime\conf\logging.properties then i got "Access is Denied". So how can i set it?

And also tell me how to restart ColdFusion services.?

Carl Von Stetten
Legend
April 21, 2014

How are you recording "information log" entries?  Are you using <cflog>?  If so, then you'll need to set an application variable that tracks whether you are on development or production.  Typically, this is done by taking a look at cgi.server_name and either using string comparison or regex to determine which environment you might be in.  You could put something like this in your Application.cfm or in the OnApplicationStart() method of Application.cfc:

<cfif cgi.server_name is "localhost">

     <!--- I'm the dev server --->

     <cfset application.environment = "development">

<cfelse>

     <!--- I'm the production server --->

     <cfset application.environment = "production">

</cfif>

Then, anywhere you do <cflog> to store "information log" entries, wrap the <cflog> in a <cfif> like this:

<cfif application.environment = "development">

     <cflog ...>

</cfif>

If you are using a community-supported MVC framework such as FW/1 or ColdBox, the environment tracking is built in and more sophisticated.

HTH,

-Carl V.

Message was edited by: Carl Von Stetten - clarified where the first code block would go.