Slice the bottoms off the onions and remove their skins, then cut in half from top to bottom. Slice each onion half into thin, half-moon slices.
Heat the butter and olive oil in a large pot over medium heat. Add the onions and cook for 5 minutes. Stir, and reduce heat to medium-low. Let the onions cook, stirring occasionally, until they shrink down and get brown in color, about 40-45 minutes. If you want to cook them for a longer time for a stronger caramelized taste, you can.
Add the salt, flour, and garlic to the onions once they are caramelized to your liking. Stir and cook for a few more minutes.
Pour the white wine into the pot and use your spoon to scrape off any of the bits of caramelized onion stuck to the bottom. Add the vegetable broth, balsamic, thyme, and dried lentils to the pot. Increase heat and bring to a boil. Cover, then reduce heat to low and let the soup simmer for 20-25 minutes, or until the lentils are tender.
While the soup is cooking, slice the baguette and shred the cheese. If desired, you can toast the baguette slices by placing them on a baking sheet under the broiler for a couple of minutes.
Ladle the soup into oven-safe bowls, top with 1-2 slices of bread, and sprinkle the shredded Gruyere evenly over the bowls. Transfer the bowls to the oven, by placing them directly on the center rack or on a baking sheet, and turn on the broiler to high. Cook for 1-2 minutes or until the cheese is melted. Carefully remove from oven and enjoy!