To calculate the average luminance of an 8x8 block, centred at each pixel in an input greyscale image, you could perform a 2D convolution of that image with an 8x8 kernel containing the value 1/64 i.e. 1/(8*8) in each cell.
This is referred to as a normalised box filter / box blur.
You can then sample the resulting image e.g. at (x,y) to yield the average luminance of the 8x8 block centred at (x,y).
There is code in the OpenCV manual for a normalised box filter, with user selectable size.
http://docs.opencv.org/doc/tutorials/imgproc/imgtrans/filter_2d/filter_2d.html
Regarding the 'log' of this value, you can then use OpenCV function cvLog to take the log of the filtered image and obtain your result.