I think this can be done, at least for rational cohomology, using the Lefschetz hyperplane theorem and the Hard Lefschetz theorem.
The pullback map $H^i (X, \mathbb Q) \to H^i ( Z, \mathbb Q)$ is an isomorphism for $i < n-1$ and injective for $i=n-1$.
Thus Poincare duality gives an isomorphism $H^i (Z, \mathbb Q) = H^{2n-2-i}(X,\mathbb Q)^\vee$ for $i > n+1$.
For $i = n+1$, the image of $H^i(X,\mathbb Q)$ inside $H^i (Z,\mathbb Q)$ is a non-degenerate subspace for the Poincare duality pairing by the Hard Lefschetz theorem. So it has an orthogonal complement $V$, whose dimension you can calculate.
We can thus describe $H^i (Z, \mathbb Q)$ as $H^i(X,\mathbb Q)$ for $i<n$, $H^i (X,\mathbb Q) \oplus V$ for $i=n$, and $ H^{2n-2-i}(X,\mathbb Q)^\vee$ for $i>n$.
Using this, we can obtain the ring structure. Consider two classes $\alpha,\beta$, let's calculate the cup product $\alpha \cup \beta$.
If $\alpha \in H^i(X,\mathbb Q)$ and $\beta \in H^j(X,\mathbb Q)$, then we can take $\alpha \cup \beta \in H^{i+j}(X,\mathbb Q)$ because the pullback map is compatible with cup products. If $i+j>n$, we need to know how to map to $H^{2n-2-i-j}(X,\mathbb Q)^\vee$, which is equivalent to taking a class $\gamma$ in $H^{2n-2-i-j}(X,\mathbb Q)$ and integrating $\alpha \cup \beta \cup \gamma$ over $Z$, which is the same as integrating $\alpha \cup \beta \cup \gamma \cup L$ over $X$, which we can do by describing the ring structure of $X$.
If $\alpha \in H^i (X,\mathbb Q)$ and $\beta \in V$, then $\alpha \cup \beta$ has degree $>n-1$ so it suffices to integrate $\alpha \cup \beta \cup \gamma$ over $Z$ for $\gamma \in H^{n-1-i} (X,\mathbb Q)$. But $(\alpha \cup \beta \cup \gamma) = (\alpha \cup \gamma) \cup \beta =0$ since $\beta$ is in the orthogonal complement of $H^{n-1}(X,\mathbb Q)$.
If $\alpha \in H^i (X,\mathbb Q)$ and $\beta \in H^{2n-2-j}(X,\mathbb Q)^\vee$, then it suffices to integrate $(\alpha \cup \beta \cup \gamma)$ for $\gamma \in H^{2n-2-i-j}(X,\mathbb Q)$, but this is just the linear form $\beta$ applied to $\alpha \cup \gamma$.
If $\alpha, \beta \in V$, then $\alpha \cup \beta$ has degree $2n-2$ so it suffices to calculate the Poincare duality pairing on $V$. This is a nondegenerate symmetric pairing if $n-1$ is even or a nondegenerate symplectic pairing if $n-1$ is odd. There is a unique such up to isomorphism, so we can always choose that one.
Any other pairing will have degree $>2n-2$ and thus vanish.