Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to write clear code with logging?

logging is cluttering my "beautiful" clean simple short code. instead of a simple

def mymethod = dosomething // scala

my code is also having also all these nasty logging statements which and immediately i have to add new lines and curly braces to mymethod. now i don't like AOP it would just make clear code --> unclear. anyway to get over this? I have when simple code turns to less simple, but i also need logging. help.

how to make this code clear simple short and also with logging?

like image 827
Jas Avatar asked Dec 15 '22 22:12

Jas


1 Answers

A typical approach in functional programming would be to add a higher-order logging combinator.

log :: IO a -> String -> IO a 
log f s = do
    v <- f
    print ("My message: " ++ s)
    return v

Such a wrapper augments evaluation of a function with a log message. The general pattern is \x y -> .. something with y .. return x

like image 122
Don Stewart Avatar answered Dec 28 '22 03:12

Don Stewart