~jstys-z/helioviewer.org/client5

402.4.26 by Keith Hughitt
Reorganized installer and downloader code
1
"""Helioviewer Python utility mehtods"""
2
import os
3
import logging
4
5
def init_logger(filepath):
6
    """Initializes logging"""
7
    # Check for logging directory
8
    directory, filename = os.path.split(os.path.expanduser(filepath))
9
    
10
    if not os.path.exists(directory):
11
        os.makedirs(directory)
12
        
13
    os.chdir(directory)
14
        
15
    # TODO: Rotate logs
16
    # e.g. Move previous log to hvpull.log.1, hvpull.log.1 to hvpull.log.2, etc
17
    # and delete any logs greater than 10.    
18
    logging.basicConfig(filename=filename, level=logging.INFO,
19
                        format='%(asctime)s.%(msecs)03d [%(levelname)s] %(message)s',
20
                        datefmt='%Y-%m-%d %H:%M:%S')
21
    
22
    # Also log INFO or higher messages to STDOUT
23
    console = logging.StreamHandler()
24
    console.setLevel(logging.INFO)
25
    logging.getLogger('').addHandler(console)