void log (string fmt, ...) {
  String_Builder* sb = thread_context()->log_builder;
  
  va_list args;
  va_start(args, fmt);
  print_to_builder_internal(sb, fmt, args);
  va_end(args);
  
  // Append newline if needed
  string result = string_view(sb);
  bool ends_with_newline = (result.data[result.count-1] == '\n');
  if (!ends_with_newline) {
    append(sb, "\n");
  }
  
  string message = string_view(sb);
  
  Logger* logger = context_logger();
  logger->proc(message, Log_Level::None, logger->data);
  
  reset_string_builder(sb, true);
}

void print (string message) {
  Logger* logger = context_logger();
  logger->proc(message, Log_Level::None, logger->data);
}

void print_error (string error_message) {
  Logger* logger = context_logger();
  logger->proc(error_message, Log_Level::Error, logger->data);
}
