Contextlog implementation

use `nonlocal`