As many hardcoded things, I suppose you cannot get that variable, it will be private.
What you want to do is very difficult and complicated. It needs a loads of variables and Jass as I suppose.
The problem would be easier, if there was a way to detect which animation a unit is currently playing - but there is no way to detect that.
I think there is no real method to make that work as you like it, so I suggest a workaround:
Replace the harvest abilities.
I know this is not what you wanted, but it is easier to detect.
I.e. give the unit the "eat tree" ability, to make the unit right click trees easy. When the unit does start casting, order it to stop. Then "Animation"-> play the "Stand Work Lumber"-Animation (I think it is called "stand,work,lumber") and add it to a unit group which you watch on "issued an order" (any order), where you can stop that animation.
Now you think of any way to set the amount of lumber it has achieved till now, there are several.
You use a JASS function for that, if you want to do it that way, I can help you with that.
Anyway, that way you can successful detect the amount of lumber the unit has and that is has lumber carried. The only possibility to lose it, is either a suitable building or dying.
If it dies now, you have what you wanted.
Anyway if that unit stops lumbering or your timer ran out, so the unit has full lumber and that way stops lumbering, you add them to another unit group. Those are the units, that have lumber, but are not gathering.
Of course, if it has full lumber, you issue an order to make it return.
Anyway, you can now detect if a unit of this unit group comes in range of a suitable building to return that ressource (when such building finishes built, add new event, unit comes in range of building, condition: triggering unit is in that unit group).
Then you can return the lumber and even show a text for it if you want, do not forget to remove it out of the unit group.
Well I know that this will be a complicated way, but I really think, that it will be easier.
If you want it that way, I can help you make it work.
For Gold it should be easier, as you need to watch units approach to gold mines.