import time
import codecs
from termcolor import colored

class Logging(object):

    log_file = None # type: file

    @staticmethod
    def set_log_file(path):
        """ Sets up the file where the logging will be done. """
        Logging.log_file = codecs.open(path, 'w', 'utf-8', buffering=0)

    @staticmethod
    def log_print(text):
        """ Prints a string both to console and a log file is it si defined. """
        if Logging.log_file is not None:
            if not isinstance(text, str):
                text = str(text)
            Logging.log_file.write(text+"\n")
            Logging.log_file.flush()

        print(text)

    @staticmethod
    def log(message, color='yellow'):
        """ Logs message with a colored timestamp. """
        log_print("{}: {}".format(colored(time.strftime("%Y-%m-%d %H:%M:%S"), color), message))


    @staticmethod
    def print_header(title):
        """
        Prints the title of the experiment and the set of arguments it uses.
        """
        log_print(colored("".join("=" for _ in range(80)), 'green'))
        log_print(colored(title.upper(), 'green'))
        log_print(colored("".join("=" for _ in range(80)), 'green'))
        log_print("Launched at {}".format(time.strftime("%Y-%m-%d %H:%M:%S")))

        log_print("")

log = Logging.log
log_print = Logging.log_print

@@ -1,12 +1,26 @@
+#tests: lint%0A%0A
 import time%0A
@@ -122,16 +122,139 @@
 : file%0A%0A
+    ## 'all' and 'none' are special symbols,%0A    ## others are filtered according the labels%0A    debug_enabled = %5B'all'%5D%0A%0A%0A
     @sta
@@ -302,17 +302,16 @@
      %22%22%22
- 
 Sets up 
@@ -350,17 +350,16 @@
 be done.
- 
 %22%22%22%0A    
@@ -481,17 +481,16 @@
      %22%22%22
- 
 Prints a
@@ -516,16 +516,24 @@
 sole and
+%0A       
  a log f
@@ -542,18 +542,18 @@
 e is it 
-s
 i
+s
  defined
@@ -553,16 +553,24 @@
 defined.
+%0A       
  %22%22%22%0A   
@@ -854,17 +854,16 @@
      %22%22%22
- 
 Logs mes
@@ -892,17 +892,16 @@
 mestamp.
- 
 %22%22%22%0A    
@@ -938,16 +938,29 @@
 colored(
+%0A            
 time.str
@@ -1006,17 +1006,16 @@
 sage))%0A%0A
-%0A
     @sta
@@ -1064,25 +1064,16 @@
      %22%22%22
-%0A        
 Prints t
@@ -1102,16 +1102,24 @@
 ment and
+%0A       
  the set
@@ -1445,16 +1445,533 @@
 nt(%22%22)%0A%0A
+    @staticmethod%0A    def debug(message, label=None):%0A        if 'none' in Logging.debug_enabled:%0A            return%0A%0A        if (label not in Logging.debug_enabled and%0A                'all' not in Logging.debug_enabled):%0A            return%0A%0A        if label:%0A            prefix = %22DEBUG (%7B%7D):%22.format(label)%0A        else:%0A            prefix = %22DEBUG:%22%0A%0A        log_print(%22%7B%7D%7B%7D%22.format(colored(prefix, color=%22cyan%22), message))%0A%0A%0A# pylint: disable=invalid-name%0A# we want these helper functions to have this exact name%0A
 log = Lo
@@ -2006,12 +2006,34 @@
 g.log_print%0A
+debug = Logging.debug%0A

debug to logging