This is a loaded question with three answers to it.
First answer: for permanent docklines in your home slip, the lines should be the length from boat cleat to dock cleat and a little more to tie it off or an eye splice at either end to the exact length needed to keep the boat in the perfect position.
As you can tell, there is no set rule with this one about lengths since these are purpose made lines with one single application.
Bow and Stern: length from boat cleat to dock cleat
Spring: length from boat cleat to dock cleat
Second answer: for the day sailor or weekend cruiser, the lines should be made relative to the boat length. The bow and stern lines should be 2/3rds the boat length and the spring lines should be 1x the boat length. These lines will be used for tying up to new piers or to other boats when you are rafted up. The bow and stern lines will have a short run to their cleat and therefore don’t need a lot of extra line. The spring lines will run a longer distance for and aft so they will need to be a full boat length.
Bow and Stern: 2/3x boat length
Spring: 1x boat length
Third answer: for the serious cruiser, short docklines will not suffice. Day sailors and weekend cruisers have the opportunity to choose what weather they go out in, so they can choose to only sail on the good days! As a full time cruiser, you will be forced to sail in all the weathers: good days and awful nights! Your docklines will need to be up for the challenge.
The bow and stern lines need to be 1.5x the boat length and the spring lines need to be at least the boat length.
Why such long bow and stern lines? Imagine a horrible situation where you enter a port in the dark in a storm and manage to get the bow up to a pier where you can toss a line to shore and be held to a fixed point. You were smart and came up on the lee side of the pier but now the boat is being blown off from the pier and there is no way you can get the stern up to the pier under motor. How do you tie up in this situation? Easy! Having a really long stern line will allow you to walk the stern line up to the bow and toss it to shore. Now all you need to do is pull the stern in from land where you can get the proper leverage and angle to do so safely.
This may sound rather far fetched but we did just this one night in the Mediterranean where we were being pounded by 50 knot winds and short, close together seas. After being hammered for a day and a half, we sailed into a marina and tied up in 40 knots of wind. It was a horrible experience, but we made it through safely because we had a long enough line.
The bow and stern lines need to be long enough that you can toss it from the other position. Being able to toss the bow line from the stern or the stern line from the bow will make all the difference when those rare situations rise from the deep.
Once you are in the slip, you can then tie up the spring lines which should be at least the boats length (but longer is useful). Long lines are also needed if you sail into places with extreme tides. Tides greater than 10 feet are common on the Atlantic coast of Europe and the USA, and when you tie up to a quay and the tide goes out, you will need to constantly adjust your lines (if you tied to a close cleat). This is laborious and time consuming, so it won’t work out! You need to tie to a cleat that’s far away from the boat so that when the tide changes the line just changes angle slightly and won’t need any adjustments. Reaching a far away clear also means that you will need a long line to reach it!
An additional line that will be very handy is a Breast Line. This is a short line that runs straight out from the boat to the pier and is used to keep the boat close to the pier for easy boarding. This line is too short to setup to a fixed pier for a long time as tides will be a bother, but it can be left permanently attached to a floating pier (as the tide will not change the length from the boat cleat to pier cleat).
Bow and Stern: 1.5x boat length
Spring: 1x boat length (or longer)
Breast: 1/2 boat length (minimum 10 feet)
While many lines are convenient to have when tying up, you also need to store them when underway. Lots of thick heavy lines will get in the way when they fill up all your lazarette space! The ideal is to have 2 bow lines, 2 stern lines, 4 spring lines, and breast line.
When we are going to be in a place for a long time, especially if you are going to leave the boat unattended for a long time, it would behoove you to double up the lines. Thankfully, any marina you are leaving the boat in will probably have a chandler nearby which means you can buy some additional lines! When you finally leave the port, you can decide to bring them all with you or retire your older lines and keep the new ones.