LogFly 1.8__tar.gz → 2.0__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
logfly-2.0/PKG-INFO ADDED
@@ -0,0 +1,57 @@
1
+ Metadata-Version: 2.1
2
+ Name: logfly
3
+ Version: 2.0
4
+ Summary: A simple log tool by python
5
+ Home-page: https://about.guki.me
6
+ Author: Yuan Sui
7
+ Author-email: orisui@icloud.com
8
+ License: UNKNOWN
9
+ Project-URL: Github, https://github.com/tinqlo/logfly
10
+ Platform: UNKNOWN
11
+ Classifier: Programming Language :: Python :: 3
12
+ Classifier: License :: OSI Approved :: MIT License
13
+ Classifier: Operating System :: OS Independent
14
+ Requires-Python: >=3.6
15
+ Description-Content-Type: text/markdown
16
+ License-File: LICENSE
17
+
18
+ # logfly 2.0
19
+ ### a simple log tool by python.
20
+
21
+ ## position
22
+ log will create in ./logs/[folder_name]/[date] folder.
23
+ if use hidden, log will also appear in user/.1o9f1y folder.
24
+
25
+ ## How to
26
+ ### import
27
+ import logfly
28
+ ### write log
29
+ logfly.write_log('name', 'where', 'info', 'message', mode='add', folder_name='logflys', hidden='no', color='yes', str_message='yes')
30
+
31
+ #### Description
32
+ name: (any str) logfile name, you can use diffrent string to create diffrent logfile.
33
+ where: ('CLI', 'fileCLI', 'file') position where log appear.
34
+ fileCLI means log will appear in command line window and log file.
35
+ CLI means log will only appear in command line window.
36
+ file means log will only appear in logfile.
37
+ info: (any str) custom log level, will upper and wrap with '[]'.
38
+ message: (any str) log message.
39
+ mode: ('add', 'new') default is 'add', means log will add in same day.
40
+ 'new' means logfile will create when program every once.
41
+ folder_name: (any str) custom logfly folder name, default is 'logflys'.
42
+ hidden: ('yes', 'no') default is 'no', means logfile will save a copy in user/.1o9f1y folder
43
+ color: ('yes', 'no') default is 'yes', means log will with color.
44
+ str_message: ('yes', 'no') default is 'yes', means log will print message with str()
45
+
46
+ ### use2
47
+ create_or_check_file(pathorfile, name, warning='yes'):
48
+ create or check file.
49
+ pathorfile: ('file', 'path') choose to create file or path.
50
+ name: (any str) file or path name.
51
+ if warning is 'yes', will print warning message if file or path is exist.
52
+
53
+ #### Description
54
+ pathfile is the file path that you want to create, must fill with '//'
55
+ filenname is the file name that you want to create, must is with '*.*'
56
+
57
+
logfly-2.0/README.md ADDED
@@ -0,0 +1,38 @@
1
+ # logfly 2.0
2
+ ### a simple log tool by python.
3
+
4
+ ## position
5
+ log will create in ./logs/[folder_name]/[date] folder.
6
+ if use hidden, log will also appear in user/.1o9f1y folder.
7
+
8
+ ## How to
9
+ ### import
10
+ import logfly
11
+ ### write log
12
+ logfly.write_log('name', 'where', 'info', 'message', mode='add', folder_name='logflys', hidden='no', color='yes', str_message='yes')
13
+
14
+ #### Description
15
+ name: (any str) logfile name, you can use diffrent string to create diffrent logfile.
16
+ where: ('CLI', 'fileCLI', 'file') position where log appear.
17
+ fileCLI means log will appear in command line window and log file.
18
+ CLI means log will only appear in command line window.
19
+ file means log will only appear in logfile.
20
+ info: (any str) custom log level, will upper and wrap with '[]'.
21
+ message: (any str) log message.
22
+ mode: ('add', 'new') default is 'add', means log will add in same day.
23
+ 'new' means logfile will create when program every once.
24
+ folder_name: (any str) custom logfly folder name, default is 'logflys'.
25
+ hidden: ('yes', 'no') default is 'no', means logfile will save a copy in user/.1o9f1y folder
26
+ color: ('yes', 'no') default is 'yes', means log will with color.
27
+ str_message: ('yes', 'no') default is 'yes', means log will print message with str()
28
+
29
+ ### use2
30
+ create_or_check_file(pathorfile, name, warning='yes'):
31
+ create or check file.
32
+ pathorfile: ('file', 'path') choose to create file or path.
33
+ name: (any str) file or path name.
34
+ if warning is 'yes', will print warning message if file or path is exist.
35
+
36
+ #### Description
37
+ pathfile is the file path that you want to create, must fill with '//'
38
+ filenname is the file name that you want to create, must is with '*.*'
@@ -5,7 +5,7 @@ with open("README.md", "r", encoding="utf-8") as fh:
5
5
 
6
6
  setuptools.setup(
7
7
  name="logfly",
8
- version="1.8",
8
+ version="2.0",
9
9
  author="Yuan Sui",
10
10
  author_email="orisui@icloud.com",
11
11
  description="A simple log tool by python",
@@ -0,0 +1,237 @@
1
+ #####################
2
+ # Author: Yuki Sui
3
+ # Date: 2022-3-4
4
+ #####################
5
+
6
+ import time
7
+ import shutil
8
+ import os
9
+ from pathlib import Path
10
+ from colorama import init
11
+
12
+ init(autoreset=True)
13
+ __version__ = '2.0'
14
+
15
+
16
+ def create_or_check_file(pathorfile, name, warning='yes'):
17
+ try:
18
+ if pathorfile == 'file':
19
+ if not os.path.exists(name):
20
+ with open(name, 'w', encoding='utf-8') as f:
21
+ f.write('')
22
+ f.close()
23
+ write_log('logfly-log', 'CLI', 'info', 'File ' + name + ' created!')
24
+ elif pathorfile == 'path':
25
+ if not os.path.exists(name):
26
+ os.makedirs(name)
27
+ write_log('logfly-log', 'CLI', 'info', 'Path ' + name + ' created!')
28
+ else:
29
+ raise ParameterERROR('function create_or_check_file Parameter error! pathorfile must be "file" or "path"! ')
30
+ if warning == 'yes':
31
+ write_log('logfly-log', 'CLI', 'warning', 'File(path) ' + name + ' already exists!')
32
+ elif warning == 'no':
33
+ pass
34
+ else:
35
+ raise ParameterERROR('function create_or_check_file Parameter error! warning must be "yes" or "no"! ')
36
+ except Exception as e:
37
+ linenum = e.__traceback__.tb_lineno
38
+ error(e, linenum)
39
+
40
+
41
+ def create_log_folder(folder_name, hidden):
42
+ dirs = '.\\logs\\'
43
+ dirs2 = '.\\logs\\' + folder_name + '\\' + get_time('date') + '\\'
44
+ dirs3 = str(Path.home()) + '\\.1o9f1y\\' + folder_name + '\\' + get_time('date') + '\\'
45
+ if not os.path.exists(dirs):
46
+ os.makedirs(dirs)
47
+ else:
48
+ pass
49
+ if not os.path.exists(dirs2):
50
+ os.makedirs(dirs2)
51
+ if hidden == 'yes':
52
+ if not os.path.exists(dirs3):
53
+ os.makedirs(dirs3)
54
+ else:
55
+ pass
56
+ else:
57
+ pass
58
+
59
+
60
+ def get_time(flag):
61
+ try:
62
+ if flag == 'datetime':
63
+ return time.strftime("%Y-%m-%d %H:%M:%S", time.localtime())
64
+ elif flag == 'date':
65
+ return time.strftime("%Y-%m-%d", time.localtime())
66
+ elif flag == 'times':
67
+ return time.strftime("%H:%M:%S", time.localtime())
68
+ elif flag == 'datetimefile':
69
+ return time.strftime("%Y%m%d%H%M%S", time.localtime())
70
+ elif flag == 'timestamp':
71
+ return time.time()
72
+ else:
73
+ raise ParameterERROR('function get_time Parameter error! flag must be "datetime", "date", "times", '
74
+ '"datetimefile","timestamp"! ')
75
+ except Exception as e:
76
+ linenum = e.__traceback__.tb_lineno
77
+ error(e, linenum)
78
+
79
+
80
+ def time_transfer(time_stamp, flag='timestamp2datetime'):
81
+ try:
82
+ if flag == 'timestamp2datetime':
83
+ if len(str(time_stamp)) == 10:
84
+ return time.strftime("%Y-%m-%d %H:%M:%S", time.localtime(time_stamp))
85
+ elif len(str(time_stamp)) == 13:
86
+ return time.strftime("%Y-%m-%d %H:%M:%S", time.localtime(time_stamp / 1000))
87
+ else:
88
+ raise ParameterERROR('function time_transfer Parameter error! time_stamp must be 10 bits or 13 bits! ')
89
+ elif flag == 'datetime2timestamp':
90
+ return time.mktime(time.strptime(time_stamp, "%Y-%m-%d %H:%M:%S"))
91
+ else:
92
+ raise ParameterERROR('function time_transfer Parameter error! flag must be "timestamp2datetime" or '
93
+ '"datetime2timestamp"! ')
94
+ except Exception as e:
95
+ linenum = e.__traceback__.tb_lineno
96
+ error(e, linenum)
97
+
98
+
99
+ # noinspection PyTypeChecker
100
+ def write_log(name, position, level, message, mode='add',
101
+ folder_name='logflys', hidden='no', color='yes', str_message='yes'):
102
+ global LOGFILE, LOGFILE2, logfolder, logfolder_hidden, LOGFILE_hidden
103
+ try:
104
+ if str_message == 'yes':
105
+ message = str(message)
106
+ elif str_message == 'no':
107
+ pass
108
+ else:
109
+ raise ParameterERROR('function write_log Parameter error! str_message must be "yes" or "no"! ')
110
+ if hidden == "no":
111
+ logfolder = '.\\logs\\' + folder_name + '\\' + get_time('date') + '\\'
112
+ elif hidden == 'yes':
113
+ logfolder = '.\\logs\\' + folder_name + '\\' + get_time('date') + '\\'
114
+ logfolder_hidden = str(Path.home()) + '\\.1o9f1y\\' + folder_name + '\\' + get_time('date') + '\\'
115
+ create_log_folder(folder_name, hidden)
116
+ else:
117
+ raise ParameterERROR('function write_log Parameter error! hidden must be "no" or "yes"! ')
118
+ if mode == 'add':
119
+ LOGFILE_hidden = name + '-' + get_time('date') + '.log'
120
+ LOGFILE = logfolder + name + '-' + get_time('date') + '.log'
121
+ elif mode == 'new':
122
+ LOGFILE_hidden = name + '-' + get_time('datetimefile') + '.log'
123
+ LOGFILE = logfolder + name + '-' + get_time('datetimefile') + '.log'
124
+ else:
125
+ raise ParameterERROR('function write_log Parameter error! mode must be "add" or "new"! ')
126
+ if position == 'CLI':
127
+ if color == 'no':
128
+ print(name + ' ' + get_time('datetime') + ' ' + '[' + str.upper(level) + ']' + ' ' + message + '\r\n')
129
+ elif color == 'yes':
130
+ LogFlyMessage = name + ' ' + get_time('datetime') + ' ' + '[' + str.upper(level) + ']' + ' ' + message + \
131
+ '\r\n '
132
+ if str.upper(level) == 'INFO':
133
+ print(f'\033[0;34m{LogFlyMessage}\033[0m')
134
+ elif str.upper(level) == 'WARNING':
135
+ print(f'\033[0;33m{LogFlyMessage}\033[0m')
136
+ elif str.upper(level) == 'ERROR':
137
+ print(f'\033[0;31m{LogFlyMessage}\033[0m')
138
+ else:
139
+ print(f'\033[0;37m{LogFlyMessage}\033[0m')
140
+ else:
141
+ raise ParameterERROR('function write_log Parameter error! color must be "yes" or "no"! ')
142
+ elif position == 'file':
143
+ if mode == 'add':
144
+ File = open(LOGFILE, 'a', newline='', encoding='utf-8')
145
+ File.write(get_time('datetime') + ' ' + '[' + str.upper(level) + ']' + ' ' + message + '\r\n')
146
+ File.close()
147
+ if hidden == 'yes':
148
+ LOGFILE2 = logfolder_hidden + LOGFILE_hidden
149
+ File = open(LOGFILE2, 'a', newline='', encoding='utf-8')
150
+ File.write(get_time('datetime') + ' ' + '[' + str.upper(level) + ']' + ' ' + message + '\r\n')
151
+ File.close()
152
+ else:
153
+ raise ParameterERROR('function write_log Parameter error! hidden must be "no" or "yes"! ')
154
+ elif mode == 'new':
155
+ File = open(LOGFILE, 'w', newline='', encoding='utf-8')
156
+ File.write(get_time('datetime') + ' ' + '[' + str.upper(level) + ']' + ' ' + message + '\r\n')
157
+ File.close()
158
+ if hidden == 'yes':
159
+ LOGFILE2 = logfolder_hidden + LOGFILE_hidden
160
+ File = open(LOGFILE2, 'a', newline='', encoding='utf-8')
161
+ File.write(get_time('datetime') + ' ' + '[' + str.upper(level) + ']' + ' ' + message + '\r\n')
162
+ File.close()
163
+ elif hidden == 'no':
164
+ pass
165
+ else:
166
+ raise ParameterERROR('function write_log Parameter error! hidden must be "no" or "yes"! ')
167
+ elif position == 'fileCLI':
168
+ if color == 'no':
169
+ print(name + ' ' + get_time('datetime') + ' ' + '[' + str.upper(level) + ']' + ' ' + message + '\r\n')
170
+ elif color == 'yes':
171
+ LogFlyMessage = name + ' ' + get_time('datetime') + ' ' + '[' + str.upper(level) + ']' + ' ' + message + \
172
+ '\r\n '
173
+ if str.upper(level) == 'INFO':
174
+ print(f'\033[0;34m{LogFlyMessage}\033[0m')
175
+ elif str.upper(level) == 'WARNING':
176
+ print(f'\033[0;33m{LogFlyMessage}\033[0m')
177
+ elif str.upper(level) == 'ERROR':
178
+ print(f'\033[0;31m{LogFlyMessage}\033[0m')
179
+ else:
180
+ print(f'\033[0;37m{LogFlyMessage}\033[0m')
181
+ else:
182
+ raise ParameterERROR('function write_log Parameter error! color must be "yes" or "no"! ')
183
+ if mode == 'add':
184
+ File = open(LOGFILE, 'a', newline='', encoding='utf-8')
185
+ File.write(get_time('datetime') + ' ' + '[' + str.upper(level) + ']' + ' ' + message + '\r\n')
186
+ File.close()
187
+ if hidden == 'yes':
188
+ LOGFILE2 = logfolder_hidden + LOGFILE_hidden
189
+ File = open(LOGFILE2, 'a', newline='', encoding='utf-8')
190
+ File.write(get_time('datetime') + ' ' + '[' + str.upper(level) + ']' + ' ' + message + '\r\n')
191
+ File.close()
192
+ elif hidden == 'no':
193
+ pass
194
+ else:
195
+ raise ParameterERROR('function write_log Parameter error! hidden must be "no" or "yes"! ')
196
+ elif mode == 'new':
197
+ File = open(LOGFILE, 'w', newline='', encoding='utf-8')
198
+ File.write(get_time('datetime') + ' ' + '[' + str.upper(level) + ']' + ' ' + message + '\r\n')
199
+ File.close()
200
+ if hidden == 'yes':
201
+ LOGFILE2 = logfolder_hidden + LOGFILE_hidden
202
+ File = open(LOGFILE2, 'a', newline='', encoding='utf-8')
203
+ File.write(get_time('datetime') + ' ' + '[' + str.upper(level) + ']' + ' ' + message + '\r\n')
204
+ File.close()
205
+ elif hidden == 'no':
206
+ pass
207
+ else:
208
+ raise ParameterERROR('function write_log Parameter error! mode must be "add" or "new"! ')
209
+ else:
210
+ raise ParameterERROR('function write_log Parameter error! position must be "file" or "fileCLI"! ')
211
+ except Exception as e:
212
+ linenum = e.__traceback__.tb_lineno
213
+ error(e, linenum, 'only print')
214
+
215
+
216
+ def mv_file(original_file_name, new_file_name, folder_name='mv_file'):
217
+ shutil.move(original_file_name, new_file_name)
218
+ message = 'File ' + original_file_name + ' moved to ' + new_file_name
219
+ write_log('logfly-log', 'CLI', 'error', message, folder_name=folder_name)
220
+
221
+
222
+ def error(exp,linenum, mode='logfly'):
223
+ if mode == 'logfly':
224
+ logflyErrorMessage = 'ERROR occurred! at row ' + str(linenum) + '\r\n\r\n' + str(
225
+ exp) + "\r\n\r\nplease re-check it! \r\nAnd you can see the " \
226
+ "manual at " \
227
+ "https://github.com/tinqlo/logfly "
228
+ write_log('logfly-log', 'CLI', 'error', logflyErrorMessage)
229
+ elif mode == 'only print':
230
+ print('ERROR occurred!\r\n\r\n' + str(exp) + "\r\n\r\nplease re-check it! \r\nAnd you can see the "
231
+ "manual at " \
232
+ "https://github.com/tinqlo/logfly ")
233
+
234
+
235
+ class ParameterERROR(Exception):
236
+ def __init__(self, message):
237
+ self.message = message
@@ -0,0 +1,57 @@
1
+ Metadata-Version: 2.1
2
+ Name: logfly
3
+ Version: 2.0
4
+ Summary: A simple log tool by python
5
+ Home-page: https://about.guki.me
6
+ Author: Yuan Sui
7
+ Author-email: orisui@icloud.com
8
+ License: UNKNOWN
9
+ Project-URL: Github, https://github.com/tinqlo/logfly
10
+ Platform: UNKNOWN
11
+ Classifier: Programming Language :: Python :: 3
12
+ Classifier: License :: OSI Approved :: MIT License
13
+ Classifier: Operating System :: OS Independent
14
+ Requires-Python: >=3.6
15
+ Description-Content-Type: text/markdown
16
+ License-File: LICENSE
17
+
18
+ # logfly 2.0
19
+ ### a simple log tool by python.
20
+
21
+ ## position
22
+ log will create in ./logs/[folder_name]/[date] folder.
23
+ if use hidden, log will also appear in user/.1o9f1y folder.
24
+
25
+ ## How to
26
+ ### import
27
+ import logfly
28
+ ### write log
29
+ logfly.write_log('name', 'where', 'info', 'message', mode='add', folder_name='logflys', hidden='no', color='yes', str_message='yes')
30
+
31
+ #### Description
32
+ name: (any str) logfile name, you can use diffrent string to create diffrent logfile.
33
+ where: ('CLI', 'fileCLI', 'file') position where log appear.
34
+ fileCLI means log will appear in command line window and log file.
35
+ CLI means log will only appear in command line window.
36
+ file means log will only appear in logfile.
37
+ info: (any str) custom log level, will upper and wrap with '[]'.
38
+ message: (any str) log message.
39
+ mode: ('add', 'new') default is 'add', means log will add in same day.
40
+ 'new' means logfile will create when program every once.
41
+ folder_name: (any str) custom logfly folder name, default is 'logflys'.
42
+ hidden: ('yes', 'no') default is 'no', means logfile will save a copy in user/.1o9f1y folder
43
+ color: ('yes', 'no') default is 'yes', means log will with color.
44
+ str_message: ('yes', 'no') default is 'yes', means log will print message with str()
45
+
46
+ ### use2
47
+ create_or_check_file(pathorfile, name, warning='yes'):
48
+ create or check file.
49
+ pathorfile: ('file', 'path') choose to create file or path.
50
+ name: (any str) file or path name.
51
+ if warning is 'yes', will print warning message if file or path is exist.
52
+
53
+ #### Description
54
+ pathfile is the file path that you want to create, must fill with '//'
55
+ filenname is the file name that you want to create, must is with '*.*'
56
+
57
+
logfly-1.8/PKG-INFO DELETED
@@ -1,92 +0,0 @@
1
- Metadata-Version: 2.1
2
- Name: logfly
3
- Version: 1.8
4
- Summary: A simple log tool by python
5
- Home-page: https://about.guki.me
6
- Author: Yuan Sui
7
- Author-email: orisui@icloud.com
8
- License: UNKNOWN
9
- Project-URL: Github, https://github.com/tinqlo/logfly
10
- Platform: UNKNOWN
11
- Classifier: Programming Language :: Python :: 3
12
- Classifier: License :: OSI Approved :: MIT License
13
- Classifier: Operating System :: OS Independent
14
- Requires-Python: >=3.6
15
- Description-Content-Type: text/markdown
16
- License-File: LICENSE
17
-
18
- # logfly 1.8
19
- ### a simple log tool by python
20
-
21
- ## position
22
- log will create in ./logs/[folder_name]/[date] folder.
23
- if use hidden, log will also appear in user/.1o9f1y folder
24
-
25
- ## How to
26
- ### import
27
- import logfly
28
- ### use1
29
- logfly.write_log('name', 'where', 'info', 'message', mode='add', folder_name='logflys', hidden='no', color='yes', str_message='yes')
30
-
31
- ## Description
32
- name: (any str) logfile name, you can use diffrent string to create diffrent logfile.
33
- where: ('CLI', 'fileCLI', 'file') position where log appear.
34
- fileCLI means log will appear in command line window and log file.
35
- CLI means log will only appear in command line window.
36
- file means log will only appear in logfile.
37
- info: (any str) custom log level, will upper and wrap with '[]'.
38
- message: (any str) log message.
39
- mode: ('add', 'new') default is 'add', means log will add in same day.
40
- 'new' means logfile will create when program every once.
41
- folder_name: (any str) custom logfly folder name, default is 'logflys'.
42
- hidden: ('yes', 'no') default is 'no', means logfile will save a copy in user/.1o9f1y folder
43
- color: ('yes', 'no') default is 'yes', means log will with color.
44
- str_message: ('yes', 'no') default is 'yes', means log will print message with str()
45
-
46
- ###use2
47
- logfly.create_file(pathfile='', filenname='')
48
-
49
- ##Description
50
- pathfile is the file path that you want to create, must fill with //
51
- filenname is the file name that you want to create, must is with *.*
52
-
53
- ## Example:
54
-
55
- ### both file and CLI code
56
- logfly.write_log('Doctor Who', 'fileCLI', 'info', "this is Doctor's log, in file and CLI.")
57
- #### in CLI
58
- 2021-07-29 20:39:07 [INFO] this is Doctor's log, in file and CLI.
59
- #### in file (logs/logflys/[date]/Doctor Who-2021-07-29.log)
60
- 2021-07-29 20:39:07 [INFO] this is Doctor's log, in file and CLI.
61
-
62
- ### only in CLI code
63
- logfly.write_log('Doctor Who', 'CLI', 'info', "this is Doctor's log, only in CLI.")
64
- #### in CLI
65
- 2021-07-29 20:39:07 [INFO] this is Doctor's log, only in CLI.
66
- #### in file
67
- None
68
-
69
- ### only in file code
70
- logfly.write_log('Doctor Who', 'file', 'info', "this is Doctor's log, only in file.")
71
- #### in CLI
72
- None
73
- #### in file (logs/logflys/[date]/Doctor Who-2021-07-29.log)
74
- 2021-07-29 20:40:03 [INFO] this is Doctor's log, only in file.
75
-
76
- #### mode arg:
77
- logfly.write_log('Doctor Who', 'file', 'info', "this is Doctor's log, only in file.", mode='new')
78
- #### in CLI:
79
- 2021-07-29 20:40:03 [INFO] this is Doctor's log, only in file.
80
- #### infile(logs//logflys[date]/Doctor Who-20210801165807.log):
81
- #### p.s. log will name in date + time
82
-
83
- 2021-07-29 20:40:03 [INFO] this is Doctor's log, only in file.
84
-
85
- #### folder arg:
86
- write_log('Death Stranding', 'fileCLI', 'info', "this is Death Stranding's log, in file and CLI.", mode='add',folder_name='games')
87
- #### in CLI:
88
- 2021-11-10 21:27:55 [INFO] this is Death Stranding's log, in file and CLI.
89
- #### infile(logs/games/[date]/Death Stranding-20210801165807.log):
90
-
91
- 2021-11-10 21:27:55 [INFO] this is Death Stranding's log, in file and CLI.
92
-
logfly-1.8/README.md DELETED
@@ -1,74 +0,0 @@
1
- # logfly 1.8
2
- ### a simple log tool by python
3
-
4
- ## position
5
- log will create in ./logs/[folder_name]/[date] folder.
6
- if use hidden, log will also appear in user/.1o9f1y folder
7
-
8
- ## How to
9
- ### import
10
- import logfly
11
- ### use1
12
- logfly.write_log('name', 'where', 'info', 'message', mode='add', folder_name='logflys', hidden='no', color='yes', str_message='yes')
13
-
14
- ## Description
15
- name: (any str) logfile name, you can use diffrent string to create diffrent logfile.
16
- where: ('CLI', 'fileCLI', 'file') position where log appear.
17
- fileCLI means log will appear in command line window and log file.
18
- CLI means log will only appear in command line window.
19
- file means log will only appear in logfile.
20
- info: (any str) custom log level, will upper and wrap with '[]'.
21
- message: (any str) log message.
22
- mode: ('add', 'new') default is 'add', means log will add in same day.
23
- 'new' means logfile will create when program every once.
24
- folder_name: (any str) custom logfly folder name, default is 'logflys'.
25
- hidden: ('yes', 'no') default is 'no', means logfile will save a copy in user/.1o9f1y folder
26
- color: ('yes', 'no') default is 'yes', means log will with color.
27
- str_message: ('yes', 'no') default is 'yes', means log will print message with str()
28
-
29
- ###use2
30
- logfly.create_file(pathfile='', filenname='')
31
-
32
- ##Description
33
- pathfile is the file path that you want to create, must fill with //
34
- filenname is the file name that you want to create, must is with *.*
35
-
36
- ## Example:
37
-
38
- ### both file and CLI code
39
- logfly.write_log('Doctor Who', 'fileCLI', 'info', "this is Doctor's log, in file and CLI.")
40
- #### in CLI
41
- 2021-07-29 20:39:07 [INFO] this is Doctor's log, in file and CLI.
42
- #### in file (logs/logflys/[date]/Doctor Who-2021-07-29.log)
43
- 2021-07-29 20:39:07 [INFO] this is Doctor's log, in file and CLI.
44
-
45
- ### only in CLI code
46
- logfly.write_log('Doctor Who', 'CLI', 'info', "this is Doctor's log, only in CLI.")
47
- #### in CLI
48
- 2021-07-29 20:39:07 [INFO] this is Doctor's log, only in CLI.
49
- #### in file
50
- None
51
-
52
- ### only in file code
53
- logfly.write_log('Doctor Who', 'file', 'info', "this is Doctor's log, only in file.")
54
- #### in CLI
55
- None
56
- #### in file (logs/logflys/[date]/Doctor Who-2021-07-29.log)
57
- 2021-07-29 20:40:03 [INFO] this is Doctor's log, only in file.
58
-
59
- #### mode arg:
60
- logfly.write_log('Doctor Who', 'file', 'info', "this is Doctor's log, only in file.", mode='new')
61
- #### in CLI:
62
- 2021-07-29 20:40:03 [INFO] this is Doctor's log, only in file.
63
- #### infile(logs//logflys[date]/Doctor Who-20210801165807.log):
64
- #### p.s. log will name in date + time
65
-
66
- 2021-07-29 20:40:03 [INFO] this is Doctor's log, only in file.
67
-
68
- #### folder arg:
69
- write_log('Death Stranding', 'fileCLI', 'info', "this is Death Stranding's log, in file and CLI.", mode='add',folder_name='games')
70
- #### in CLI:
71
- 2021-11-10 21:27:55 [INFO] this is Death Stranding's log, in file and CLI.
72
- #### infile(logs/games/[date]/Death Stranding-20210801165807.log):
73
-
74
- 2021-11-10 21:27:55 [INFO] this is Death Stranding's log, in file and CLI.
@@ -1,178 +0,0 @@
1
- #####################
2
- # Author: Yuki Sui
3
- # Date: 2022-1-30
4
- #####################
5
-
6
- import time
7
- import shutil
8
- import os
9
- from pathlib import Path
10
- from colorama import init
11
-
12
- init(autoreset=True)
13
- __version__ = '1.8'
14
-
15
-
16
- def create_file(pathfile='', filenname=''):
17
- if pathfile is None:
18
- return False
19
- if not os.path.exists(pathfile):
20
- os.makedirs(pathfile)
21
- else:
22
- pass
23
- filepath = pathfile + filenname
24
- if not os.path.isfile(filepath):
25
- with open(filepath, 'w', encoding='utf-8') as filefiletemp:
26
- filefiletemp.write('')
27
- filefiletemp.close()
28
- else:
29
- pass
30
-
31
-
32
- def create_log_folder(folder_name, hidden):
33
- dirs = '.\\logs\\'
34
- dirs2 = '.\\logs\\' + folder_name + '\\' + get_time('date') + '\\'
35
- dirs3 = str(Path.home()) + '\\.1o9f1y\\' + folder_name + '\\' + get_time('date') + '\\'
36
- if not os.path.exists(dirs):
37
- os.makedirs(dirs)
38
- else:
39
- pass
40
- if not os.path.exists(dirs2):
41
- os.makedirs(dirs2)
42
- if hidden == 'yes':
43
- if not os.path.exists(dirs3):
44
- os.makedirs(dirs3)
45
- else:
46
- pass
47
- else:
48
- pass
49
-
50
-
51
- def get_time(flag):
52
- if flag == 'datetime':
53
- return time.strftime("%Y-%m-%d %H:%M:%S", time.localtime())
54
- elif flag == 'date':
55
- return time.strftime("%Y-%m-%d", time.localtime())
56
- elif flag == 'times':
57
- return time.strftime("%H:%M:%S", time.localtime())
58
- elif flag == 'datetimefile':
59
- return time.strftime("%Y%m%d%H%M%S", time.localtime())
60
- elif flag == 'timestamp':
61
- return time.time()
62
-
63
-
64
- # noinspection PyTypeChecker
65
- def write_log(name, position, level, message, mode='add',
66
- folder_name='logflys', hidden='no', color='yes', str_message='yes'):
67
- global LOGFILE, LOGFILE2, logfolder, logfolder_hidden, LOGFILE_hidden
68
- if str_message == 'yes':
69
- message = str(message)
70
- elif str_message == 'no':
71
- pass
72
- else:
73
- error()
74
- if hidden == "no":
75
- logfolder = '.\\logs\\' + folder_name + '\\' + get_time('date') + '\\'
76
- elif hidden == 'yes':
77
- logfolder = '.\\logs\\' + folder_name + '\\' + get_time('date') + '\\'
78
- logfolder_hidden = str(Path.home()) + '\\.1o9f1y\\' + folder_name + '\\' + get_time('date') + '\\'
79
- if mode == 'add':
80
- LOGFILE_hidden = name + '-' + get_time('date') + '.log'
81
- LOGFILE = logfolder + name + '-' + get_time('date') + '.log'
82
- elif mode == 'new':
83
- LOGFILE_hidden = name + '-' + get_time('datetimefile') + '.log'
84
- LOGFILE = logfolder + name + '-' + get_time('datetimefile') + '.log'
85
- else:
86
- error()
87
- create_log_folder(folder_name, hidden)
88
- if position == 'CLI':
89
- if color == 'no':
90
- print(name + ' ' + get_time('datetime') + ' ' + '[' + str.upper(level) + ']' + ' ' + message + '\r\n')
91
- elif color == 'yes':
92
- LogFlyMessage = name + ' ' + get_time('datetime') + ' ' + '[' + str.upper(level) + ']' + ' ' + message + \
93
- '\r\n '
94
- if str.upper(level) == 'INFO':
95
- print(f'\033[0;34m{LogFlyMessage}\033[0m')
96
- elif str.upper(level) == 'WARNING':
97
- print(f'\033[0;33m{LogFlyMessage}\033[0m')
98
- elif str.upper(level) == 'ERROR':
99
- print(f'\033[0;31m{LogFlyMessage}\033[0m')
100
- else:
101
- print(f'\033[0;37m{LogFlyMessage}\033[0m')
102
- else:
103
- error()
104
- elif position == 'file':
105
- if mode == 'add':
106
- File = open(LOGFILE, 'a', newline='', encoding='utf-8')
107
- File.write(get_time('datetime') + ' ' + '[' + str.upper(level) + ']' + ' ' + message + '\r\n')
108
- File.close()
109
- if hidden == 'yes':
110
- LOGFILE2 = logfolder_hidden + LOGFILE_hidden
111
- File = open(LOGFILE2, 'a', newline='', encoding='utf-8')
112
- File.write(get_time('datetime') + ' ' + '[' + str.upper(level) + ']' + ' ' + message + '\r\n')
113
- File.close()
114
- elif mode == 'new':
115
- File = open(LOGFILE, 'w', newline='', encoding='utf-8')
116
- File.write(get_time('datetime') + ' ' + '[' + str.upper(level) + ']' + ' ' + message + '\r\n')
117
- File.close()
118
- if hidden == 'yes':
119
- LOGFILE2 = logfolder_hidden + LOGFILE_hidden
120
- File = open(LOGFILE2, 'a', newline='', encoding='utf-8')
121
- File.write(get_time('datetime') + ' ' + '[' + str.upper(level) + ']' + ' ' + message + '\r\n')
122
- File.close()
123
- else:
124
- error()
125
- elif position == 'fileCLI':
126
- if color == 'no':
127
- print(name + ' ' + get_time('datetime') + ' ' + '[' + str.upper(level) + ']' + ' ' + message + '\r\n')
128
- elif color == 'yes':
129
- LogFlyMessage = name + ' ' + get_time('datetime') + ' ' + '[' + str.upper(level) + ']' + ' ' + message + \
130
- '\r\n '
131
- if str.upper(level) == 'INFO':
132
- print(f'\033[0;34m{LogFlyMessage}\033[0m')
133
- elif str.upper(level) == 'WARNING':
134
- print(f'\033[0;33m{LogFlyMessage}\033[0m')
135
- elif str.upper(level) == 'ERROR':
136
- print(f'\033[0;31m{LogFlyMessage}\033[0m')
137
- else:
138
- print(f'\033[0;37m{LogFlyMessage}\033[0m')
139
- else:
140
- error()
141
- if mode == 'add':
142
- File = open(LOGFILE, 'a', newline='', encoding='utf-8')
143
- File.write(get_time('datetime') + ' ' + '[' + str.upper(level) + ']' + ' ' + message + '\r\n')
144
- File.close()
145
- if hidden == 'yes':
146
- LOGFILE2 = logfolder_hidden + LOGFILE_hidden
147
- File = open(LOGFILE2, 'a', newline='', encoding='utf-8')
148
- File.write(get_time('datetime') + ' ' + '[' + str.upper(level) + ']' + ' ' + message + '\r\n')
149
- File.close()
150
- elif mode == 'new':
151
- File = open(LOGFILE, 'w', newline='', encoding='utf-8')
152
- File.write(get_time('datetime') + ' ' + '[' + str.upper(level) + ']' + ' ' + message + '\r\n')
153
- File.close()
154
- if hidden == 'yes':
155
- LOGFILE2 = logfolder_hidden + LOGFILE_hidden
156
- File = open(LOGFILE2, 'a', newline='', encoding='utf-8')
157
- File.write(get_time('datetime') + ' ' + '[' + str.upper(level) + ']' + ' ' + message + '\r\n')
158
- File.close()
159
- else:
160
- error()
161
- else:
162
- error()
163
-
164
-
165
- def mv_file(original_file_name, new_file_name, folder_name='mv_file'):
166
- shutil.move(original_file_name, new_file_name)
167
- message = 'File ' + original_file_name + ' moved to ' + new_file_name
168
- write_log('logfly-log', 'CLI', 'error', message, folder_name=folder_name)
169
-
170
-
171
- def error():
172
- logflyErrorMessage = 'your parameter is wrong, please re-check it! \r\nAnd you can see the manual at ' \
173
- 'https://github.com/tinqlo/logfly '
174
- write_log('logfly-log', 'CLI', 'error', logflyErrorMessage)
175
-
176
-
177
- if __name__ == '__main__':
178
- write_log('Doctor Who', 'fileCLI', 'info', "this is Doctor's log, only in CLI.")
@@ -1,92 +0,0 @@
1
- Metadata-Version: 2.1
2
- Name: logfly
3
- Version: 1.8
4
- Summary: A simple log tool by python
5
- Home-page: https://about.guki.me
6
- Author: Yuan Sui
7
- Author-email: orisui@icloud.com
8
- License: UNKNOWN
9
- Project-URL: Github, https://github.com/tinqlo/logfly
10
- Platform: UNKNOWN
11
- Classifier: Programming Language :: Python :: 3
12
- Classifier: License :: OSI Approved :: MIT License
13
- Classifier: Operating System :: OS Independent
14
- Requires-Python: >=3.6
15
- Description-Content-Type: text/markdown
16
- License-File: LICENSE
17
-
18
- # logfly 1.8
19
- ### a simple log tool by python
20
-
21
- ## position
22
- log will create in ./logs/[folder_name]/[date] folder.
23
- if use hidden, log will also appear in user/.1o9f1y folder
24
-
25
- ## How to
26
- ### import
27
- import logfly
28
- ### use1
29
- logfly.write_log('name', 'where', 'info', 'message', mode='add', folder_name='logflys', hidden='no', color='yes', str_message='yes')
30
-
31
- ## Description
32
- name: (any str) logfile name, you can use diffrent string to create diffrent logfile.
33
- where: ('CLI', 'fileCLI', 'file') position where log appear.
34
- fileCLI means log will appear in command line window and log file.
35
- CLI means log will only appear in command line window.
36
- file means log will only appear in logfile.
37
- info: (any str) custom log level, will upper and wrap with '[]'.
38
- message: (any str) log message.
39
- mode: ('add', 'new') default is 'add', means log will add in same day.
40
- 'new' means logfile will create when program every once.
41
- folder_name: (any str) custom logfly folder name, default is 'logflys'.
42
- hidden: ('yes', 'no') default is 'no', means logfile will save a copy in user/.1o9f1y folder
43
- color: ('yes', 'no') default is 'yes', means log will with color.
44
- str_message: ('yes', 'no') default is 'yes', means log will print message with str()
45
-
46
- ###use2
47
- logfly.create_file(pathfile='', filenname='')
48
-
49
- ##Description
50
- pathfile is the file path that you want to create, must fill with //
51
- filenname is the file name that you want to create, must is with *.*
52
-
53
- ## Example:
54
-
55
- ### both file and CLI code
56
- logfly.write_log('Doctor Who', 'fileCLI', 'info', "this is Doctor's log, in file and CLI.")
57
- #### in CLI
58
- 2021-07-29 20:39:07 [INFO] this is Doctor's log, in file and CLI.
59
- #### in file (logs/logflys/[date]/Doctor Who-2021-07-29.log)
60
- 2021-07-29 20:39:07 [INFO] this is Doctor's log, in file and CLI.
61
-
62
- ### only in CLI code
63
- logfly.write_log('Doctor Who', 'CLI', 'info', "this is Doctor's log, only in CLI.")
64
- #### in CLI
65
- 2021-07-29 20:39:07 [INFO] this is Doctor's log, only in CLI.
66
- #### in file
67
- None
68
-
69
- ### only in file code
70
- logfly.write_log('Doctor Who', 'file', 'info', "this is Doctor's log, only in file.")
71
- #### in CLI
72
- None
73
- #### in file (logs/logflys/[date]/Doctor Who-2021-07-29.log)
74
- 2021-07-29 20:40:03 [INFO] this is Doctor's log, only in file.
75
-
76
- #### mode arg:
77
- logfly.write_log('Doctor Who', 'file', 'info', "this is Doctor's log, only in file.", mode='new')
78
- #### in CLI:
79
- 2021-07-29 20:40:03 [INFO] this is Doctor's log, only in file.
80
- #### infile(logs//logflys[date]/Doctor Who-20210801165807.log):
81
- #### p.s. log will name in date + time
82
-
83
- 2021-07-29 20:40:03 [INFO] this is Doctor's log, only in file.
84
-
85
- #### folder arg:
86
- write_log('Death Stranding', 'fileCLI', 'info', "this is Death Stranding's log, in file and CLI.", mode='add',folder_name='games')
87
- #### in CLI:
88
- 2021-11-10 21:27:55 [INFO] this is Death Stranding's log, in file and CLI.
89
- #### infile(logs/games/[date]/Death Stranding-20210801165807.log):
90
-
91
- 2021-11-10 21:27:55 [INFO] this is Death Stranding's log, in file and CLI.
92
-
File without changes
File without changes
File without changes