create contain file log coldfusion

后端 未结 2 990
天命终不由人
天命终不由人 2021-01-14 22:25

I want create a log file. I tried but its show me an error. Can anyone help? I show my full code here:

http://pastebin.com/SxAMCUnv

Please see this line. I d

相关标签:
2条回答
  • 2021-01-14 22:56

    A few things.

    1. When you are getting an error: tell us what the error is, don't simply say you got one.
    2. When you're posting code, only post code that's relevant to your situation, don't post all the code. You've given us almost 200 lines of code to wade through, almost all of it not being relevant.
    3. You've given no indication of what troubleshooting of your own you've done here. It's basically like you're asking us to simply do your work for you.

    If you clarify your question, I'll take my down vote off.

    A superficial glance at your code suggests you're trying to write out a variable fileContent, but at no point do you actually set that variable. Without seeing the error, there;s no way of knowing if that's the problem, or the variable is being created in code that you haven't included.

    Another consideration is that you're re-inventing the wheel slightly here. ColdFusion has an inbuilt <cflog> tag or writeLog() statement for writing to log files.

    =====

    UPDATE (based on updates to the question) That's a compile error you're getting, and the line that's erroring is not the line you indicated in your code (@ pastebin), which is a bit odd. Can you confirm line 213 is that <cffile> line? And can you reproduce that line in its entirety (the snippet you quoted was incomplete). But basically the error message is telling you what's wrong: you have a syntax error in your code. It could be in the specific statement the error message says (line and column), although sometimes depending on the code, the CF compiler can get confused and a syntax error in a preceding line might be reported as being further down the file than it actually is. But for starters, post the whole line of code, not just the first bit of it.

    0 讨论(0)
  • 2021-01-14 23:09

    comments tl;dr version - This answer worked but asker began asking questions about the new error, he was urged to create a new question.

    Answer: I don't see this line in the link you posted (I searched for api.log). Invalid CFML construct typically means you have a syntax error, usually forgetting a closing quote, second pound, or closing your tag (greater than). If the below suggestion doesn't work, look above or below the line containing the cffile for a missing part of a closing pair.

    The code you posted:

    <cffile action="WRITE" file="#expandpath('API.log')#" output="#filecontent#" addnewline="Yes" fixnewline="No"
    

    ...does not have a closing greater than to close your tag. If that is your actual code, I would suspect that is the problem.

    <cffile ...  >
                ^^^ this is missing right here
    

    If you're not going to take Adam's suggestion and use cflog (which you should), you also probably want action="append" or you will keep overwriting the file with the contents of fileContent.

    ==edit==

    On a side note, this will not solve your problem but you should be using cfqueryparam, especially when using user entered data.

    For example:

    Select * 
    FROM   Purchasers 
    WHERE  PurchaserID = #PurchaserID#
    

    Should be

    Select * 
    FROM   Purchasers 
    WHERE  PurchaserID = <cfqueryparam cfsqltype="cf_sql_integer" value="#PurchaserID#">
    
    0 讨论(0)
提交回复
热议问题