This is actually a bit complicated, depending on the scenario.
- If you log off while somebody has your ship warp scrammed or disrupted, your ship will go nowhere. Instead it will stay right where it is and whomever is shooting at you can continue to do so. This is to prevent people from logging off to try to save their ship. It would make for a very boring battle if everybody could do this.
- If you have recently been engaged in combat when you log off, after a short delay (observation seems to indicate about 30 seconds) your ship will emergency warp to a random point in space a few AU away from where you were located. It will then stay at this spot for a period of time. I'll have to find source, but I believe your ship will stay where it is until the standard 15 minute aggression timer (from the start of combat) has expired. During this time, your ship will still be "visible" on direction scan, and it can be probed out with combat probes. Again, this is to prevent somebody from attempt a logoffski to save their ship. After this timer has expired your ship will simply disappear from space.
- If you have not engaged in combat and you are not pointed, when you log off in space your ship will emergency warp to a random point not too far off grid. Again, This emergency warp generally seems to take place within 30 seconds or so. And again, the exact place will vary, but experience has shown it to be no more than a couple AU from where you logged off. After your ship lands at its safe spot, it will disappear from the server.
- If you log off while in a POS shield, your ship will not emergency warp, with the assumption being that a POS is supposed to be a safe spot for your ship. After a period of time, your ship will simply disappear in space. While I haven't fully tested this, the period of time seems to vary and is most likely either 30 seconds with no aggression, or the end of the aggression timer if you've recently been engaged in combat.
- If you log off while in warp, your ship will continue to warp to the already assigned location in space. Once there, after a brief delay, it will proceed to enter an emergency warp and leave grid. At this point, it will either shortly disappear from space or remain until the aggression timer has expired, just like cases 2 and 3.
What happens when you log back on? In case #1, your ship will still be in place if your enemy hasn't destroyed it yet. In cases #2, #3 and #5 where your ship has performed an emergency warp, it will reappear in space at the emergency warp location and automatically warp back to the location you were at when logging off. This is assuming that the enemy has not probed you down in case #2 and destroyed your ship.
In case #4, your ship will actually appear at some random point in space a couple AU from the POS and automatically warp back to the location in the POS from which you logged off. Note that in case #4, your ship will actually warp through any warp disruption bubbles that may or may not have been erected around your POS when you logged off. Again, the assumption is that inside your POS shields your ship should be safe, so you should not be able to lose your ship just because you logged off at an in opportune time.
In EVE, nothing is simple, but I think this covers just about any log off scenario and the various game mechanics involved.