File: log.py

package info (click to toggle)
whichwayisup 0.7.9-8
  • links: PTS, VCS
  • area: main
  • in suites: bullseye
  • size: 1,808 kB
  • sloc: python: 2,372; sh: 3; makefile: 2
file content (32 lines) | stat: -rw-r--r-- 1,111 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
"""A logging module - error messages using the error_message function
will only be displayed on screen if the verbose setting is on, and written
to the log variable by default. The log doesn't need to be initialized
to be used, but you must call the write_log function in util.py on exit if you
want the log to be saved."""

from variables import Variables

def error_message(string):
    """Add a message specified as an error to the message log."""
    log_message("Error: " + string)
    return

def log_message(string):
    """Add a message to the message log, which can be written on disk later."""

    #Multiple messages of the same type aren't added to the log:
    if "last_log_message" in Variables.vdict:
      if string == Variables.vdict["last_log_message"]:
        return
        
    if Variables.vdict['verbose']:
        print(string)        

    Variables.vdict["last_log_message"] = string

    if "log" in Variables.vdict:
        Variables.vdict["log"] = string + "\n" + Variables.vdict["log"]
    else:
        Variables.vdict["log"] = string

    return