appendLogToFile function

void appendLogToFile(
  1. String message
)

Append a message to the log file.

This function adds a new message to the end of the log file, automatically adding a newline. The operation is skipped in CI/CD environments to avoid unnecessary file I/O.

Parameters:

  • message: The message to append to the log

The log file ('morpheme_log.txt') is created automatically if it doesn't exist. If logging fails, the error is written to stderr but doesn't interrupt the main application flow.

Example:

// Log application events
appendLogToFile('Application started');
appendLogToFile('Processing file: example.txt');
appendLogToFile('Operation completed successfully');

// Log error information
appendLogToFile('Error: ${error.toString()}');

Implementation

void appendLogToFile(String message) {
  if (isCiCdEnvironment) return;

  join(current, 'morpheme_log.txt').append(message);
}