No. You need to dig into the regulations a bit to get at the answer:
§ 61.51(e):
Logging pilot-in-command flight time.
(1) A sport, recreational, private, commercial, or airline transport pilot may log pilot in command flight time for flights-
(i) Except when logging flight time under § 61.159(c), when the pilot is the sole manipulator of the controls of an aircraft for which the pilot is rated, or has sport pilot privileges for that category and class of aircraft, if the aircraft class rating is appropriate;
This seems to imply you can at first glance, but you need to dig into the definitions of the terms used. § 1.1 defines "flight time":
Pilot time that commences when an aircraft moves under its own power for the purpose of flight and ends when the aircraft comes to rest after landing
and then § 61.1 defines "pilot time":
Pilot time means that time in which a person -
(i) Serves as a required pilot flight crewmember;
(ii) Receives training from an authorized instructor in an aircraft, full flight simulator, flight training device, or aviation training device;
(iii) Gives training as an authorized instructor in an aircraft, full flight simulator, flight training device, or aviation training device; or
(iv) Serves as second in command in operations conducted in accordance with § 135.99(c) of this chapter when a second pilot is not required under the type certification of the aircraft or the regulations under which the flight is being conducted, provided the requirements in § 61.159(c) are satisfied.
The only one here that could possibly apply to you, assuming your friend is not a CFI, is the first. However, you cannot serve as a required flight crewmember without a medical, as stated in § 61.3(c)(1):
A person may serve as a required pilot flight crewmember of an aircraft only if that person holds the appropriate medical certificate issued under part 67 of this chapter, or other documentation acceptable to the FAA, that is in that person's physical possession or readily accessible in the aircraft. Paragraph (c)(2) of this section provides certain exceptions to the requirement to hold a medical certificate.
unless one of the exceptions in § 61.3(c)(2) applies to you.
In short, you can only log "flight time," which is a type of "pilot time," which only accrues if you are a "required flight crewmember." Since you are not allowed to be a required flight crewmember without a medical, you can't log time either.
You can log PIC time if you are receiving training from a CFI in a plane you are rated for. If your medical has lapsed and you don't have a medical condition that makes flying unsafe, picking up some training from a CFI is a safe and legal way to continue flying and logging time while you work on getting your medical in order.