• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
1

Logging logs

New Here ,
Apr 19, 2014 Apr 19, 2014

Copy link to clipboard

Copied

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?

Views

2.4K

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guide ,
Apr 21, 2014 Apr 21, 2014

Copy link to clipboard

Copied

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.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Advocate ,
Apr 22, 2014 Apr 22, 2014

Copy link to clipboard

Copied

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.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Adobe Employee ,
Apr 22, 2014 Apr 22, 2014

Copy link to clipboard

Copied

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

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Apr 22, 2014 Apr 22, 2014

Copy link to clipboard

Copied

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.?

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Adobe Employee ,
Apr 23, 2014 Apr 23, 2014

Copy link to clipboard

Copied

If you are getting access denied, that means, that you don't have appropriate privileges (or privileges equivalent to Admin). Please contact your IT.

Alternatively, you can move the logging.properties to your Desktop and make changes there. Once done, save it back to \cfusion\runtime\conf\.

Shraddha Prajapati wrote:

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?


To restart ColdFusion Services:-

Start>>Run>>services.msc and restart "ColdFusion 10 Application Server" (for windows)

Shraddha Prajapati wrote:

And also tell me how to restart ColdFusion services.?

Regards,

Anit Kumar

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Apr 23, 2014 Apr 23, 2014

Copy link to clipboard

Copied

Hi Anit

          according you say i follow the step , Set org.apache.catalina.core.ContainerBase.[Catalina].[localhost].level to WARN and then restart ColdFusion services.

But its not work Both Error and Information type log write in my logfile...I log only Error or Information type log in my logfile...Even i write both type of log in my code..Any other way to solve it?

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Advocate ,
Apr 24, 2014 Apr 24, 2014

Copy link to clipboard

Copied

Instead of WARN, try INFO.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Apr 24, 2014 Apr 24, 2014

Copy link to clipboard

Copied

By default in that file "INFO" But its not work..And According You say i also try "WARN" but its not work...Have you any another way to solve it?

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Advocate ,
Apr 25, 2014 Apr 25, 2014

Copy link to clipboard

Copied

Like I originally mentioned, learn log4j. Even if you get the CF setting to work, you will be missing other capabilities like logging to devices, logging message at specified level to multiple log files, etc. To get you started, here are some key functions in my logging wrapper. While some of the supporting details may be missing, I think it is enough to give you a jump start:

<cffunction access="private" name="logInit" output="yes" returntype="utilities">
  <cfargument name="applicationName" type="string" required="yes" />
  <cfset var local = structNew() />
 
  <cfset variables.baseLogName = arguments.applicationName />

  <cfset local.basePath = "" />
  <cfset local.path = replace(getCurrentTemplatePath(),"\","/","ALL") />
  <cfif reFindNoCase("(.*/)(htdocs|pub|wwwroot)(/.*|$)",local.path)>
   <cfset local.basePath = reReplaceNoCase(local.path,"(.*/)(htdocs|pub|wwwroot)(/.*|$)","\1\2") />
  <cfelse>
   <cfloop index="local.i" list="#local.path#" delimiters="/">
    <cfif local.i EQ arguments.applicationName>
     <cfbreak />
    </cfif>
    <cfset local.basePath = listAppend(local.basePath,local.i,"/") />
   </cfloop>
   <cfset local.basePath = listAppend(local.basePath,arguments.applicationName,"/") />
  </cfif>
  <cfset local.cfgName = local.basePath & "/#application.settings.dataPath#/#variables.baseLogName#_log4j.properties" />
  <cfset local.logName = local.basePath & "/#application.settings.dataPath#/logs/#variables.baseLogName#.log" />
  <cfset local.errName = local.basePath & "/#application.settings.dataPath#/logs/#variables.baseLogName#-err.log" />

  <cfif NOT isDefined("application.loggerInit")>
   <cflock name="loggerInit" timeout="20" throwontimeout="yes" type="exclusive">
    <cfif NOT isDefined("application.loggerInit")>
                 <cfif NOT fileExists(local.cfgName)>
                     <cfsavecontent variable="local.cfgText"><cfoutput>## #variables.baseLogName#_log4j.properties
##
## This file is created by the logger.cfc init() function if it does not exist. Once created, you are free to edit it.
##
## Create a logger called #variables.baseLogName#, set it's level to INFO, and set the appender to myAppen (you can name this anything, but keep it simple).
## Valid levels are: ALL < DEBUG < INFO < WARN < ERROR < FATAL < OFF
log4j.logger.#variables.baseLogName#=INFO, myAppen, myError

## myAppen is set to be a DailyRollingFileAppender (hourly).
## Most common appenders are: ConsoleAppender, FileAppender, RollingFileAppender, and DailyRollingFileAppender. Other standard appenders
## include: WritterAppender, SocketAppender, SMTPAppender, JMSAppender, and AsyncAppender. For a detailed explaination and property
## settings, see the full documentation.
log4j.appender.myAppen=org.apache.log4j.DailyRollingFileAppender
log4j.appender.myAppen.File=#local.logName#
log4j.appender.myAppen.DatePattern=.yyyyMMdd-HH'.log'

## we'll use a standard layout
log4j.appender.myAppen.layout=org.apache.log4j.PatternLayout
log4j.appender.myAppen.layout.ConversionPattern=%d{yyyy-MM-dd HH:mm:ss.SSS} %p %t %c - %m%n

## myError is set to be a DailyRollingFileAppender.
log4j.appender.myError=org.apache.log4j.DailyRollingFileAppender
log4j.appender.myError.File=#local.errName#
log4j.appender.myError.DatePattern=.yyyyMMdd'.log'
log4j.appender.myError.Threshold=WARN

## we'll use a standard layout
log4j.appender.myError.layout=org.apache.log4j.PatternLayout
log4j.appender.myError.layout.ConversionPattern=%d{yyyy-MM-dd HH:mm:ss.SSS} %p %t %c - %m%n
                     </cfoutput></cfsavecontent>
                     <cffile action="write" addnewline="no" file="#local.cfgName#" output="#local.cfgText#" fixnewline="no" />
                 </cfif>
                 <cfset local.configurator = createObject("java", "org.apache.log4j.PropertyConfigurator") />
                 <!--- one time vs. poll for changes (in ms) - pick one
     <cfset local.configurator.configure(local.cfgName) />
     <cfset local.configurator.configureAndWatch(local.cfgName,300000) />
     --->
                 <cfset local.configurator.configureAndWatch(local.cfgName,300000) />
                 <cfset application.loggerInit = true />
             </cfif>
   </cflock>
  </cfif>
  <cfset local.loggerObj = createObject("java", "org.apache.log4j.Logger") />
  <cfset this.myLogger = local.loggerObj.getLogger(variables.baseLogName) />
  <cfset logMsg(type="INFO",module="logger.cfc",text="Initiated") />

  <cfif NOT syslogInit()>
   <cfset logMsg(type="WARN",module="logger.cfc",text="Syslog writer failed to initialize (System.Diagnostics.EventLog)") />
  </cfif>

  <cfreturn this />
</cffunction>

    <cffunction name="logDeinit" access="public" returntype="void">
  <cfset this.syslogDeinit() />
</cffunction>

<cffunction name="logTrace" access="public" returntype="void">
  <cfargument name="text" type="string" required="yes" />
  <cfset this.myLogger.trace(arguments.text) />
</cffunction>

  <cffunction name="logDebug" access="public" returntype="void">
  <cfargument name="text" type="string" required="yes" />
  <cfset this.myLogger.debug(arguments.text) />
</cffunction>

  <cffunction name="logInfo" access="public" returntype="void">
  <cfargument name="text" type="string" required="yes" />
  <cfset this.myLogger.info(arguments.text) />
</cffunction>

  <cffunction name="logWarn" access="public" returntype="void">
  <cfargument name="text" type="string" required="yes" />
  <cfset this.myLogger.warn(arguments.text) />
</cffunction>

  <cffunction name="logError" access="public" returntype="void">
  <cfargument name="text" type="string" required="yes" />
  <cfset this.myLogger.error(arguments.text) />
</cffunction>

  <cffunction name="logFatal" access="public" returntype="void">
  <cfargument name="text" type="string" required="yes" />
  <cfset this.myLogger.fatal(arguments.text) />
</cffunction>

  <cffunction name="syslogMsg" access="public" returntype="void">
  <cfargument name="text" type="string" required="yes" />
  <cfif this.syslogReady>
   <cfset this.syslogLogger.WriteEntry(arguments.text) />
  </cfif>
</cffunction>

  <cffunction name="logMsg" access="public" returntype="void">
  <cfargument name="text" type="string" required="yes" />
        <cfargument name="type" type="string" required="no" default="Information" />
        <cfargument name="module" type="string" required="no" default="unknown" />
  <cfset var outText = "#CGI.REMOTE_ADDR# #arguments.module# - #arguments.text#" />
 
  <cfswitch expression="#arguments.type#">
   <cfcase value="Trace">
    <cfset this.logTrace(outText) />
   </cfcase>
   <cfcase value="Debug">
    <cfset this.logDebug(outText) />
   </cfcase>
   <cfcase value="Information,Info">
    <cfset this.logInfo(outText) />
   </cfcase>
   <cfcase value="Warning,Warn">
    <cfset this.logWarn(outText) />
   </cfcase>
   <cfcase value="Error,Err">
    <cfset this.logError(outText) />
   </cfcase>
   <cfcase value="Fatal Information,Fatal">
    <cfset this.logFatal(outText) />
   </cfcase>
   <cfdefaultcase>
    <cfset this.logInfo(outText) />
   </cfdefaultcase>
  </cfswitch>

</cffunction>

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Apr 27, 2014 Apr 27, 2014

Copy link to clipboard

Copied

Where i have to write this code?

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Advocate ,
Apr 28, 2014 Apr 28, 2014

Copy link to clipboard

Copied

I put the code in a cfc called logger.cfc that I initiat at application startup and hold in the application scope. The to log:

<cfset application.logger.logMsg(type="WARN",type="fatal,error,warning,info,debug" module="Some module name with maybe line number xyz:25",text="Something to log") />

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Apr 28, 2014 Apr 28, 2014

Copy link to clipboard

Copied

Hi Steve, I try to implement it according you say..I make one component (logger.cfc) and put above function in that...And after i put

public boolean function onApplicationStart() {

                    obj=new logger();

                    return true;

          }

code in to Application.cfc

and then add Logmsg line in my component (MyFirstComponent.cfc)

<cfcomponent hint="first component">

          <cffunction name="getSum" returntype="numeric" access="public">

<cfset obj.logMsg(type="WARN",module="logger.cfc",text="Something to log") />

                              <cfset a = 10>

                              <cfset b = 20>

                              <cfset c = a + b>

                              <cfreturn c>

          </cffunction>

</cfcomponent>

But its not work....I got the error like:

Variable OBJ is undefined.

I am begginer in Coldfusion Please tell me in Details....

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Advocate ,
Apr 29, 2014 Apr 29, 2014

Copy link to clipboard

Copied

"new logger()" I'm surprised works. It may be perfectly valid, but I have never used it that way. Assuming it is working, the problem you're having is with the scopes. Within cfc's the "variables" scope is to the cfc you are in. In other words, variables.obj in application.cfc is different than variables.obj in myfirstcomponent.cfc, thus the varialbe.obj is undefined message.

Try this, within logger.cfc:

<cffunction access="private" name="logInit" output="yes" returntype="utilities">

<cffunction access="public" name="init" output="no" returntype="logger">

Witin application.cfc:

obj.new logger();

this.logger = createObject("component","logger").init( applicationName="myFirstApp" );

Within MyFirstComponent.cfc:

<cfset obj.logMsg(type="WARN",module="logger.cfc",text="Something to log") />

<cfset application.logger.logMsg(type="WARN",module="MyFirstComponent.cfc",text="Something to log") />

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Apr 29, 2014 Apr 29, 2014

Copy link to clipboard

Copied

Hi, When i changes like above i got the following error:

The web site you are accessing has experienced an unexpected error.
Please contact the website administrator.


The following information is meant for the website developer for debugging purposes.
Error Occurred While Processing Request

Element SETTINGS.DATAPATH is undefined in APPLICATION.



The error occurred in C:/ColdFusion10/cfusion/wwwroot/demo/Login/logger.cfc: line 23

21 :<cfset local.basePath = listAppend(local.basePath, arguments.applicationName, "/")/>

22 :</cfif>

23 :<cfset local.cfgName = local.basePath & "/#application.settings.dataPath#/#variables.baseLogName#_log4j.prope rties"/>

24 :<cfset local.logName = local.basePath & "/#application.settings.dataPath#/logs/#variables.baseLogName#.log"/>

25 :<cfset local.errName = local.basePath & "/#application.settings.dataPath#/logs/#variables.baseLogName#-err.lo g"/>

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Advocate ,
Apr 30, 2014 Apr 30, 2014

Copy link to clipboard

Copied

The three lines using application.settings.dataPath are just setting file locations. You can change that logic to work withing the confines of your CF server. For simplicity, change "local.basePath & "/#application.settings.dataPath#/" to something like "c:/logs/".

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Apr 30, 2014 Apr 30, 2014

Copy link to clipboard

Copied

Hi I am bigner in CF...So please tell me in details, where to define this three variable, and how??

local.basePath=?

application.settings.dataPath=?

variables.baseLogName=?

Where and How?

I try to define it..In logger.cfc i defined following:

<cfset local.basePath = "C:\ColdFusion10\cfusion\wwwroot\"/>

And in Application.cfc i define following variable:

this.settings.dataPath="demo\LogingLog";

But i got the error like:

The web site you are accessing has experienced an unexpected error.
Please contact the website administrator.


The following information is meant for the website developer for debugging purposes.
Error Occurred While Processing Request

Element SETTINGS.DATAPATH is undefined in APPLICATION.



The error occurred in C:/ColdFusion10/cfusion/wwwroot/demo/LogingLog/logger.cfc: line 23

23 : <cfset local.cfgName = local.basePath & "/#application.settings.dataPath#/#variables.baseLogName#_log4j.prope rties"/>

24 :           <cfset local.logName = local.basePath & "/#application.settings.dataPath#/logs/#variables.baseLogName#.log"/>

25 :           <cfset local.errName = local.basePath & "/#application.settings.dataPath#/logs/#variables.baseLogName#-err.lo g"/>



Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
May 01, 2014 May 01, 2014

Copy link to clipboard

Copied

Shraddha Prajapati wrote:

Hi I am bigner in CF...So please tell me in details, where to define this three variable, and how??

local.basePath=?

application.settings.dataPath=?

variables.baseLogName=?

Where and How?

I try to define it..In logger.cfc i defined following:

<cfset local.basePath = "C:\ColdFusion10\cfusion\wwwroot\"/>

And in Application.cfc i define following variable:

this.settings.dataPath="demo\LogingLog";

Those variables are already defined. Look back, and you will see

<cfset var local = structNew() />

<cfset variables.baseLogName = arguments.applicationName /> 

<cfset local.basePath = "" />

etc

You should therefore not redefine them. What you should do is implement the corrections that Steve made on April 29, 2014 at 5:36 PM.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Advocate ,
May 01, 2014 May 01, 2014

Copy link to clipboard

Copied

Sorry I don't have the time to continue this thread. I consider myself a very strong fixer and a very weak teacher -- no patience as you can tell. In the early days of my ColdFusion experience, I had a couple books that for the life of me I cannot remember the names but there are a lot out there. Don't be offended but I think there is even a ColdFusion for Dummies -- I like all the Dummies books I have read and they are probably the best beginner books for most any topic. Also a great site I used was www.easycfm.com -- a lot of tutorials. Good luck.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Engaged ,
May 01, 2014 May 01, 2014

Copy link to clipboard

Copied

Also, you might want to check out www.learncfinaweek.com .  That will at least give you a base foundation to build apps so you can get past the basic issues you are having.  After reading this thread and others I feel that you are trying to create an app without any understanding of how to write the language.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
May 04, 2014 May 04, 2014

Copy link to clipboard

Copied

Hi,I know how to write language of CF, I already made one project in CF and i already read www.learncfinaweek.com...I am beginner not means that i dont know language...

I want to know that how to define application.settings.dataPath=?, because i got error:

Element SETTINGS.DATAPATH is undefined in APPLICATION.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Participant ,
May 05, 2014 May 05, 2014

Copy link to clipboard

Copied

No need to get upset. When you ask how to set a variable in the application scope, it is not a far stretch to think you 'don't know the language'.

Simply use:

<cfset application.settings.datapath = {some path you want to set} />

Where {some path you want to set} is the actual path to whatever it is you need.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
May 05, 2014 May 05, 2014

Copy link to clipboard

Copied

hi I add it Now i get another issue::

The following information is meant for the website developer for debugging purposes.
Error Occurred While Processing Request

Variable SYSLOGINIT is undefined.

The error occurred in C:/ColdFusion10/cfusion/wwwroot/demo/LogingLog/logger.cfc: line 72

70 : <cfset this.myLogger = local.loggerObj.getLogger(variables.baseLogName)/>

71 : <cfset logMsg(type="INFO", module="logger.cfc", text="Initiated")/>

72 : <cfif NOT syslogInit()>

73 : <cfset logMsg(type="WARN", module="logger.cfc",

74 : text="Syslog writer failed to initialize (System.Diagnostics.EventLog)")/

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
May 05, 2014 May 05, 2014

Copy link to clipboard

Copied

Whai i have to add syslogInit() method????

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Advocate ,
May 06, 2014 May 06, 2014

Copy link to clipboard

Copied

Simply remove that entire cfif block. This code was pulled out of a cfc that does quite a bit more than what is demonstrated here.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Resources
Documentation