10
10
11
11
__author__ = 'Jim Ewald'
12
12
13
- # Constants
13
+ # Platform constants
14
+ PLATFORM_LINUX = 'linux2'
14
15
PLATFORM_MACOS = 'darwin'
15
16
PLATFORM_WINDOWS = 'win32'
16
17
18
+ # Default log path for each platform
17
19
DEFAULT_PATH_MACOS = '/Library/Logs/Parallax'
18
20
DEFAULT_PATH_WINDOWS = '/AppData/Local/Parallax'
19
- DEFAULT_PATH_LINUX = '/tmp/ '
21
+ DEFAULT_PATH_LINUX = '/tmp'
20
22
23
+ # Resulting path for log file
21
24
path = None
22
25
23
26
@@ -41,13 +44,17 @@ def emit(self, record):
41
44
# Set correct log file location
42
45
if platform == PLATFORM_MACOS :
43
46
logfile_name = __set_macos_logpath (filename )
44
- if logfile_name is None :
45
- disable_filelogging = True
46
- else :
47
- # Set the module-level path
48
- path = logfile_name
49
47
elif platform == PLATFORM_WINDOWS :
50
48
logfile_name = __set_windows_logpath (filename )
49
+ elif platform == PLATFORM_LINUX :
50
+ logfile_name = __set_linux_logpath (filename )
51
+
52
+ # Verify that we have a valid location
53
+ if logfile_name is None :
54
+ disable_filelogging = True
55
+ else :
56
+ # Set the module-level path
57
+ path = logfile_name
51
58
52
59
# Create a logger
53
60
logger = logging .getLogger ('blockly' )
@@ -74,6 +81,24 @@ def emit(self, record):
74
81
logger .info ("Logger has been started." )
75
82
76
83
84
+ # Set the default log file location on a Linux system
85
+ def __set_linux_logpath (filename ):
86
+ user_home = os .path .expanduser ('~' )
87
+ log_path = user_home + DEFAULT_PATH_LINUX
88
+
89
+ # Does the log directory exist
90
+ try :
91
+ result = __verify_logpath (log_path )
92
+ if result is None and __create_logpath (log_path ) is None :
93
+ return None
94
+ else :
95
+ return log_path + '/' + filename
96
+
97
+ except OSError :
98
+ return None
99
+
100
+
101
+ # Set the default log file location on a MacOS system
77
102
def __set_macos_logpath (filename ):
78
103
user_home = os .path .expanduser ('~' )
79
104
log_path = user_home + DEFAULT_PATH_MACOS
@@ -86,13 +111,14 @@ def __set_macos_logpath(filename):
86
111
log_path = '/tmp'
87
112
result = __verify_logpath (log_path )
88
113
if result is None :
89
- return 1
114
+ return None
90
115
91
116
return log_path + '/' + filename
92
117
except OSError :
93
- return 2
118
+ return None
94
119
95
120
121
+ # Set the default log file location on a Windows system
96
122
def __set_windows_logpath (filename ):
97
123
user_home = os .path .expanduser ('~' )
98
124
log_path = user_home + DEFAULT_PATH_WINDOWS
@@ -107,11 +133,11 @@ def __set_windows_logpath(filename):
107
133
result = __verify_logpath (log_path )
108
134
109
135
if result is None :
110
- return 1
136
+ return None
111
137
112
138
return log_path + '/' + filename
113
139
except OSError :
114
- return 2
140
+ return None
115
141
116
142
117
143
# Create a file path for the log file
0 commit comments