function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion 

Apex File logging.


    It would be great if some one can suggest me a way to develop Logger class that will log all my apex messages to a local file.

    This would greatly help me, as this would give me an ability to go through the failure messages, and debug the application             more effectively. 
    I created an apex class that logs into Salesforce Document object, but it would create 2 additional calls to Salesforce and is lot     of overhead for each request. Suggestions would be greatly appreciated.

public class Logger {
 private static final Document log = [Select d.Body From Document d where d.Name='LogFile'][0];
 private String logMessage = '';
 public void addToLog(String message){
  logMessage = logMessage + + '::' +message + '\n';
 public void logmessage(){
  log.body= Blob.valueOf(log.body.toString()+ logMessage);
  update log;
  logMessage = '';



    Girish S
What do you mean by "local" file - all Apex execution happens on the platform?

I guess you could log to a document like you seem to be trying to do, but that seems like a really bad idea.  Why not just log to a Log custom object?