Code not writing properly

Hello guys, I was working on a project which involves writing the pressure and temperature onto an sd card. I use an sd card shield. When running the code on my Arduino Uno it only writes 1 measurement. I was wondering if any of you could help me. (It does work on the serial monitor)

Code:

#include <Wire.h>
#include <SFE_BMP180.h>
#include <SPI.h>
#include <SD.h>

SFE_BMP180 bmp180;
File logData;

int buttonPin = 3;
int ledPin = 13;

bool logStatus = false;

void setup() {
Serial.begin(9600);
bool success = bmp180.begin();

pinMode(buttonPin, INPUT);
pinMode(ledPin, OUTPUT);

if (success) {
Serial.println("BMP180 init success");
} else {
Serial.println("Sensor not initialized!!");
}

//SD Shizzle
Serial.print("Initializing SD card...");

if (!SD.begin(10)) {
Serial.println("initialization failed!");
while (1);
}
Serial.println("initialization done.");

logData = SD.open("log.txt", FILE_WRITE);
}

void loop() {

char status;
double T, P;
bool success = false;

if(digitalRead(buttonPin) == LOW){
if (logStatus == true){
logStatus = false;
logData.println("Jelle");
logData.close();
Serial.println("Jelle");
digitalWrite(ledPin, LOW);
} else {
logStatus = true;
digitalWrite(ledPin, HIGH);
}
}

status = bmp180.startTemperature();

if (status != 0) {
delay(1000);
status = bmp180.getTemperature(T);

if (status != 0) {
status = bmp180.startPressure(3);

if (status != 0) {
delay(status);
status = bmp180.getPressure(P, T);

if (status != 0 && logStatus == true) {

logData.print("Pressure: ");
logData.print(P);
logData.println(" hPa");

logData.print("Temperature: ");
logData.print(T);
logData.println(" C");

Serial.print("Pressure: ");
Serial.print(P);
Serial.println(" hPa");

Serial.print("Temperature: ");
Serial.print(T);
Serial.println(" C");

}
}
}
}
}

    if (logStatus == true){
      logStatus = false;
      logData.println("Jelle");
      logData.close();
      Serial.println("Jelle");
      digitalWrite(ledPin, LOW);
    } else {
      logStatus = true;
      digitalWrite(ledPin, HIGH);
    }

If it is OK to write to the file, write to it, close it, and say that it is no longer OK to write to the file.

If it isn't OK to write to the file, say that it is OK, but don't bother opening the file.

Well, how do you expect to be able to write again?

PaulS:

    if (logStatus == true){

logStatus = false;
      logData.println("Jelle");
      logData.close();
      Serial.println("Jelle");
      digitalWrite(ledPin, LOW);
    } else {
      logStatus = true;
      digitalWrite(ledPin, HIGH);
    }



If it is OK to write to the file, write to it, close it, and say that it is no longer OK to write to the file.

If it isn't OK to write to the file, say that it is OK, but don't bother opening the file.

Well, how do you expect to be able to write again?

Sorry I do not understand what I should change, could you elaborate?

Sorry I do not understand what I should change, could you elaborate?

Suppose that you have a two year old, with toys all over the floor, and a toy box. You tell him to put his toys in the box, when the lights in the room are on.

Then, you turn the lights off, and close the box. So, he stops trying to put toys away.

Then, you turn the lights on. What else do you need to do for him to be able to put his toys away?

Don't you think that opening the box would be a necessary step?

Don't you think that when your code says that is now OK to write to the file that you should only say that AFTER you've made it possible to write to the file, by opening it?