Yun Bridge - error when printing to client

I am using the bridge example as a framework to log sensor data to a remote server. The url command is http://yun.local/arduino/log/25 which should log 25 values and then print a confirmation to clients browser. The problem is that client.print sometimes prints to browser and sometimes doesn’t print at all.

Here are the print commands:

client.print(F(“Logged “));
client.print(n);
client.println(F(” sensor values to datalog.txt”));

I have narrowed the issue down to one line earlier in the code:

n = client.parseInt();

When I try to parse the int, it gets it just fine, but then the prints don’t show in the browser. Commenting out that line makes it print to browser perfectly.

Here is the log function where I suspect the error is located:

void logCommand(BridgeClient client) {

  
  int n = 10;

  // read number of analog readings
  // n = client.parseInt();
  
  
  lcd.setCursor(0,1);
  lcd.print("");

  // open the file. note that only one file can be open at a time,
  // so you have to close this one before opening another.
  // The FileSystem card is mounted at the following "/mnt/FileSystema1"
  File dataFile = FileSystem.open("/mnt/sd/datalog.txt", FILE_APPEND);
    
  for (int x = 0; x < n; x++) {
      
    // make a string that starts with a timestamp for assembling the data to log:
    String dataString;
    dataString += getTimeStamp();
    dataString += " = ";

    // read three sensors and append to the string:
    int sensor_val = analogRead(analogPin);
    dataString += String(sensor_val);

      
    // if the file is available, write to it:
    if (dataFile) {
      dataFile.println(dataString);
      lcd.setCursor(0, 1);
      lcd.print(x);
      }
      
    delay(100);
    
    }

  if (dataFile) {
    dataFile.close();
    }

  client.print(F("Logged "));
  client.print(n);
  client.println(F(" sensor values to datalog.txt"));
  lcd.setCursor(0, 1);
  lcd.print("Done");
  
}

And here is the entire program, sorry for the mess. Appreciate any and all help!

#include <Wire.h>
#include <FileIO.h>
#include <Bridge.h>  
#include <BridgeServer.h>
#include <BridgeClient.h>
#include <LiquidCrystal.h>


// Listen to the default port 5555, the Yún webserver
// will forward there all the HTTP requests you send
BridgeServer server;

// Photoresistor
#define analogPin 0


// LCD address
int tmp102Address = 0x48;

// initialize the library with the numbers of the interface pins
LiquidCrystal lcd(8, 9, 4, 5, 6, 7);

void setup() {
  
  Wire.begin();
  Bridge.begin();
  FileSystem.begin();

  // set up the LCD's number of columns and rows:
  lcd.begin(16, 2);
  
  // Print a static message to the LCD.
  lcd.print("Logger:");

  // Listen for incoming connection only from localhost
  // (no one from the external network could connect)
  server.listenOnLocalhost();
  server.begin();

}

void loop() {
  // Get clients coming from server
  BridgeClient client = server.accept();

  // There is a new client?
  if (client) {
    // Process request
    process(client);

    // Close connection and free resources.
    client.stop();
  }

  delay(50); // Poll every 50ms
}


void process(BridgeClient client) {
  // read the command
  String command = client.readStringUntil('/');

  // is "analog" command?
  if (command == "analog") {
    analogCommand(client);
  }

  // is "log" command?
  if (command == "log") {
    logCommand(client);
  }
}

void logCommand(BridgeClient client) {

  
  int n = 10;

  // read number of analog readings
  // n = client.parseInt();
  
  
  lcd.setCursor(0,1);
  lcd.print("");

  // open the file. note that only one file can be open at a time,
  // so you have to close this one before opening another.
  // The FileSystem card is mounted at the following "/mnt/FileSystema1"
  File dataFile = FileSystem.open("/mnt/sd/datalog.txt", FILE_APPEND);
    
  for (int x = 0; x < n; x++) {
      
    // make a string that starts with a timestamp for assembling the data to log:
    String dataString;
    dataString += getTimeStamp();
    dataString += " = ";

    // read three sensors and append to the string:
    int sensor_val = analogRead(analogPin);
    dataString += String(sensor_val);

      
    // if the file is available, write to it:
    if (dataFile) {
      dataFile.println(dataString);
      lcd.setCursor(0, 1);
      lcd.print(x);
      }
      
    delay(100);
    
    }

  if (dataFile) {
    dataFile.close();
    }

  client.print(F("Logged "));
  client.print(n);
  client.println(F(" sensor values to datalog.txt"));
  lcd.setCursor(0, 1);
  lcd.print("Done");
  
}



void analogCommand(BridgeClient client) {
  int pin, value;

  // Read pin number
  pin = client.parseInt();

  // If the next character is a '/' it means we have an URL
  // with a value like: "/analog/5/120"
  if (client.read() == '/') {
    // Read value and execute command
    value = client.parseInt();
    analogWrite(pin, value);

    // Send feedback to client
    client.print(F("Pin D"));
    client.print(pin);
    client.print(F(" set to analog "));
    client.println(value);

    // Update datastore key with the current pin value
    String key = "D";
    key += pin;
    Bridge.put(key, String(value));
  } else {
    // Read analog pin
    value = analogRead(pin);

    // Send feedback to client
    client.print(F("Pin A"));
    client.print(pin);
    client.print(F(" reads analog "));
    client.println(value);

    // Update datastore key with the current pin value
    String key = "A";
    key += pin;
    Bridge.put(key, String(value));
  }
}

// This function return a string with the time stamp
String getTimeStamp() {
  String result;
  Process time;
  // date is a command line utility to get the date and the time
  // in different formats depending on the additional parameter
  time.begin("date");
  time.addParameter("+%D-%T");  // parameters: D for the complete date mm/dd/yy
  //             T for the time hh:mm:ss
  time.run();  // run the command

  // read the output of the command
  while (time.available() > 0) {
    char c = time.read();
    if (c != '\n') {
      result += c;
    }
  }

  return result;
}