LogFly 1.8__tar.gz → 1.9__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-1.8/src/logfly.egg-info → logfly-1.9}/PKG-INFO +7 -42
- logfly-1.9/README.md +38 -0
- {logfly-1.8 → logfly-1.9}/setup.py +1 -1
- logfly-1.9/src/logfly/__init__.py +216 -0
- {logfly-1.8 → logfly-1.9/src/logfly.egg-info}/PKG-INFO +7 -42
- logfly-1.8/README.md +0 -74
- logfly-1.8/src/logfly/__init__.py +0 -178
- {logfly-1.8 → logfly-1.9}/LICENSE +0 -0
- {logfly-1.8 → logfly-1.9}/pyproject.toml +0 -0
- {logfly-1.8 → logfly-1.9}/setup.cfg +0 -0
- {logfly-1.8 → logfly-1.9}/src/logfly.egg-info/SOURCES.txt +0 -0
- {logfly-1.8 → logfly-1.9}/src/logfly.egg-info/dependency_links.txt +0 -0
- {logfly-1.8 → logfly-1.9}/src/logfly.egg-info/requires.txt +0 -0
- {logfly-1.8 → logfly-1.9}/src/logfly.egg-info/top_level.txt +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.1
|
|
2
2
|
Name: logfly
|
|
3
|
-
Version: 1.
|
|
3
|
+
Version: 1.9
|
|
4
4
|
Summary: A simple log tool by python
|
|
5
5
|
Home-page: https://about.guki.me
|
|
6
6
|
Author: Yuan Sui
|
|
@@ -15,7 +15,7 @@ Requires-Python: >=3.6
|
|
|
15
15
|
Description-Content-Type: text/markdown
|
|
16
16
|
License-File: LICENSE
|
|
17
17
|
|
|
18
|
-
# logfly 1.
|
|
18
|
+
# logfly 1.9
|
|
19
19
|
### a simple log tool by python
|
|
20
20
|
|
|
21
21
|
## position
|
|
@@ -44,49 +44,14 @@ if use hidden, log will also appear in user/.1o9f1y folder
|
|
|
44
44
|
str_message: ('yes', 'no') default is 'yes', means log will print message with str()
|
|
45
45
|
|
|
46
46
|
###use2
|
|
47
|
-
|
|
47
|
+
lcreate_or_check_file(pathorfile, name, warning='Yes'):
|
|
48
|
+
create or check file.
|
|
49
|
+
pathorfile: (any str) path or file name.
|
|
50
|
+
name: (any str) file or path name.
|
|
51
|
+
if warning is 'Yes', will print warning message if file is exist.
|
|
48
52
|
|
|
49
53
|
##Description
|
|
50
54
|
pathfile is the file path that you want to create, must fill with //
|
|
51
55
|
filenname is the file name that you want to create, must is with *.*
|
|
52
56
|
|
|
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
57
|
|
logfly-1.9/README.md
ADDED
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
# logfly 1.9
|
|
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
|
+
lcreate_or_check_file(pathorfile, name, warning='Yes'):
|
|
31
|
+
create or check file.
|
|
32
|
+
pathorfile: (any str) path or file name.
|
|
33
|
+
name: (any str) file or path name.
|
|
34
|
+
if warning is 'Yes', will print warning message if file 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 *.*
|
|
@@ -0,0 +1,216 @@
|
|
|
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.9'
|
|
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
|
+
error(e)
|
|
38
|
+
|
|
39
|
+
|
|
40
|
+
def create_log_folder(folder_name, hidden):
|
|
41
|
+
dirs = '.\\logs\\'
|
|
42
|
+
dirs2 = '.\\logs\\' + folder_name + '\\' + get_time('date') + '\\'
|
|
43
|
+
dirs3 = str(Path.home()) + '\\.1o9f1y\\' + folder_name + '\\' + get_time('date') + '\\'
|
|
44
|
+
if not os.path.exists(dirs):
|
|
45
|
+
os.makedirs(dirs)
|
|
46
|
+
else:
|
|
47
|
+
pass
|
|
48
|
+
if not os.path.exists(dirs2):
|
|
49
|
+
os.makedirs(dirs2)
|
|
50
|
+
if hidden == 'yes':
|
|
51
|
+
if not os.path.exists(dirs3):
|
|
52
|
+
os.makedirs(dirs3)
|
|
53
|
+
else:
|
|
54
|
+
pass
|
|
55
|
+
else:
|
|
56
|
+
pass
|
|
57
|
+
|
|
58
|
+
|
|
59
|
+
def get_time(flag):
|
|
60
|
+
try:
|
|
61
|
+
if flag == 'datetime':
|
|
62
|
+
return time.strftime("%Y-%m-%d %H:%M:%S", time.localtime())
|
|
63
|
+
elif flag == 'date':
|
|
64
|
+
return time.strftime("%Y-%m-%d", time.localtime())
|
|
65
|
+
elif flag == 'times':
|
|
66
|
+
return time.strftime("%H:%M:%S", time.localtime())
|
|
67
|
+
elif flag == 'datetimefile':
|
|
68
|
+
return time.strftime("%Y%m%d%H%M%S", time.localtime())
|
|
69
|
+
elif flag == 'timestamp':
|
|
70
|
+
return time.time()
|
|
71
|
+
else:
|
|
72
|
+
raise ParameterERROR('function get_time Parameter error! flag must be "datetime", "date", "times", '
|
|
73
|
+
'"datetimefile","timestamp"! ')
|
|
74
|
+
except Exception as e:
|
|
75
|
+
error(e)
|
|
76
|
+
|
|
77
|
+
|
|
78
|
+
# noinspection PyTypeChecker
|
|
79
|
+
def write_log(name, position, level, message, mode='add',
|
|
80
|
+
folder_name='logflys', hidden='no', color='yes', str_message='yes'):
|
|
81
|
+
global LOGFILE, LOGFILE2, logfolder, logfolder_hidden, LOGFILE_hidden
|
|
82
|
+
try:
|
|
83
|
+
if str_message == 'yes':
|
|
84
|
+
message = str(message)
|
|
85
|
+
elif str_message == 'no':
|
|
86
|
+
pass
|
|
87
|
+
else:
|
|
88
|
+
raise ParameterERROR('function write_log Parameter error! str_message must be "yes" or "no"! ')
|
|
89
|
+
if hidden == "no":
|
|
90
|
+
logfolder = '.\\logs\\' + folder_name + '\\' + get_time('date') + '\\'
|
|
91
|
+
elif hidden == 'yes':
|
|
92
|
+
logfolder = '.\\logs\\' + folder_name + '\\' + get_time('date') + '\\'
|
|
93
|
+
logfolder_hidden = str(Path.home()) + '\\.1o9f1y\\' + folder_name + '\\' + get_time('date') + '\\'
|
|
94
|
+
create_log_folder(folder_name, hidden)
|
|
95
|
+
else:
|
|
96
|
+
raise ParameterERROR('function write_log Parameter error! hidden must be "no" or "yes"! ')
|
|
97
|
+
if mode == 'add':
|
|
98
|
+
LOGFILE_hidden = name + '-' + get_time('date') + '.log'
|
|
99
|
+
LOGFILE = logfolder + name + '-' + get_time('date') + '.log'
|
|
100
|
+
elif mode == 'new':
|
|
101
|
+
LOGFILE_hidden = name + '-' + get_time('datetimefile') + '.log'
|
|
102
|
+
LOGFILE = logfolder + name + '-' + get_time('datetimefile') + '.log'
|
|
103
|
+
else:
|
|
104
|
+
raise ParameterERROR('function write_log Parameter error! mode must be "add" or "new"! ')
|
|
105
|
+
if position == 'CLI':
|
|
106
|
+
if color == 'no':
|
|
107
|
+
print(name + ' ' + get_time('datetime') + ' ' + '[' + str.upper(level) + ']' + ' ' + message + '\r\n')
|
|
108
|
+
elif color == 'yes':
|
|
109
|
+
LogFlyMessage = name + ' ' + get_time('datetime') + ' ' + '[' + str.upper(level) + ']' + ' ' + message + \
|
|
110
|
+
'\r\n '
|
|
111
|
+
if str.upper(level) == 'INFO':
|
|
112
|
+
print(f'\033[0;34m{LogFlyMessage}\033[0m')
|
|
113
|
+
elif str.upper(level) == 'WARNING':
|
|
114
|
+
print(f'\033[0;33m{LogFlyMessage}\033[0m')
|
|
115
|
+
elif str.upper(level) == 'ERROR':
|
|
116
|
+
print(f'\033[0;31m{LogFlyMessage}\033[0m')
|
|
117
|
+
else:
|
|
118
|
+
print(f'\033[0;37m{LogFlyMessage}\033[0m')
|
|
119
|
+
else:
|
|
120
|
+
raise ParameterERROR('function write_log Parameter error! color must be "yes" or "no"! ')
|
|
121
|
+
elif position == 'file':
|
|
122
|
+
if mode == 'add':
|
|
123
|
+
File = open(LOGFILE, 'a', newline='', encoding='utf-8')
|
|
124
|
+
File.write(get_time('datetime') + ' ' + '[' + str.upper(level) + ']' + ' ' + message + '\r\n')
|
|
125
|
+
File.close()
|
|
126
|
+
if hidden == 'yes':
|
|
127
|
+
LOGFILE2 = logfolder_hidden + LOGFILE_hidden
|
|
128
|
+
File = open(LOGFILE2, 'a', newline='', encoding='utf-8')
|
|
129
|
+
File.write(get_time('datetime') + ' ' + '[' + str.upper(level) + ']' + ' ' + message + '\r\n')
|
|
130
|
+
File.close()
|
|
131
|
+
else:
|
|
132
|
+
raise ParameterERROR('function write_log Parameter error! hidden must be "no" or "yes"! ')
|
|
133
|
+
elif mode == 'new':
|
|
134
|
+
File = open(LOGFILE, 'w', newline='', encoding='utf-8')
|
|
135
|
+
File.write(get_time('datetime') + ' ' + '[' + str.upper(level) + ']' + ' ' + message + '\r\n')
|
|
136
|
+
File.close()
|
|
137
|
+
if hidden == 'yes':
|
|
138
|
+
LOGFILE2 = logfolder_hidden + LOGFILE_hidden
|
|
139
|
+
File = open(LOGFILE2, 'a', newline='', encoding='utf-8')
|
|
140
|
+
File.write(get_time('datetime') + ' ' + '[' + str.upper(level) + ']' + ' ' + message + '\r\n')
|
|
141
|
+
File.close()
|
|
142
|
+
elif hidden == 'no':
|
|
143
|
+
pass
|
|
144
|
+
else:
|
|
145
|
+
raise ParameterERROR('function write_log Parameter error! hidden must be "no" or "yes"! ')
|
|
146
|
+
elif position == 'fileCLI':
|
|
147
|
+
if color == 'no':
|
|
148
|
+
print(name + ' ' + get_time('datetime') + ' ' + '[' + str.upper(level) + ']' + ' ' + message + '\r\n')
|
|
149
|
+
elif color == 'yes':
|
|
150
|
+
LogFlyMessage = name + ' ' + get_time('datetime') + ' ' + '[' + str.upper(level) + ']' + ' ' + message + \
|
|
151
|
+
'\r\n '
|
|
152
|
+
if str.upper(level) == 'INFO':
|
|
153
|
+
print(f'\033[0;34m{LogFlyMessage}\033[0m')
|
|
154
|
+
elif str.upper(level) == 'WARNING':
|
|
155
|
+
print(f'\033[0;33m{LogFlyMessage}\033[0m')
|
|
156
|
+
elif str.upper(level) == 'ERROR':
|
|
157
|
+
print(f'\033[0;31m{LogFlyMessage}\033[0m')
|
|
158
|
+
else:
|
|
159
|
+
print(f'\033[0;37m{LogFlyMessage}\033[0m')
|
|
160
|
+
else:
|
|
161
|
+
raise ParameterERROR('function write_log Parameter error! color must be "yes" or "no"! ')
|
|
162
|
+
if mode == 'add':
|
|
163
|
+
File = open(LOGFILE, 'a', newline='', encoding='utf-8')
|
|
164
|
+
File.write(get_time('datetime') + ' ' + '[' + str.upper(level) + ']' + ' ' + message + '\r\n')
|
|
165
|
+
File.close()
|
|
166
|
+
if hidden == 'yes':
|
|
167
|
+
LOGFILE2 = logfolder_hidden + LOGFILE_hidden
|
|
168
|
+
File = open(LOGFILE2, 'a', newline='', encoding='utf-8')
|
|
169
|
+
File.write(get_time('datetime') + ' ' + '[' + str.upper(level) + ']' + ' ' + message + '\r\n')
|
|
170
|
+
File.close()
|
|
171
|
+
elif hidden == 'no':
|
|
172
|
+
pass
|
|
173
|
+
else:
|
|
174
|
+
raise ParameterERROR('function write_log Parameter error! hidden must be "no" or "yes"! ')
|
|
175
|
+
elif mode == 'new':
|
|
176
|
+
File = open(LOGFILE, 'w', newline='', encoding='utf-8')
|
|
177
|
+
File.write(get_time('datetime') + ' ' + '[' + str.upper(level) + ']' + ' ' + message + '\r\n')
|
|
178
|
+
File.close()
|
|
179
|
+
if hidden == 'yes':
|
|
180
|
+
LOGFILE2 = logfolder_hidden + LOGFILE_hidden
|
|
181
|
+
File = open(LOGFILE2, 'a', newline='', encoding='utf-8')
|
|
182
|
+
File.write(get_time('datetime') + ' ' + '[' + str.upper(level) + ']' + ' ' + message + '\r\n')
|
|
183
|
+
File.close()
|
|
184
|
+
elif hidden == 'no':
|
|
185
|
+
pass
|
|
186
|
+
else:
|
|
187
|
+
raise ParameterERROR('function write_log Parameter error! mode must be "add" or "new"! ')
|
|
188
|
+
else:
|
|
189
|
+
raise ParameterERROR('function write_log Parameter error! position must be "file" or "fileCLI"! ')
|
|
190
|
+
except Exception as e:
|
|
191
|
+
error(e, 'only print')
|
|
192
|
+
|
|
193
|
+
|
|
194
|
+
def mv_file(original_file_name, new_file_name, folder_name='mv_file'):
|
|
195
|
+
shutil.move(original_file_name, new_file_name)
|
|
196
|
+
message = 'File ' + original_file_name + ' moved to ' + new_file_name
|
|
197
|
+
write_log('logfly-log', 'CLI', 'error', message, folder_name=folder_name)
|
|
198
|
+
|
|
199
|
+
|
|
200
|
+
def error(exp, mode='logfly'):
|
|
201
|
+
if mode == 'logfly':
|
|
202
|
+
logflyErrorMessage = 'ERROR occurred!\r\n\r\n' + str(
|
|
203
|
+
exp) + "\r\n\r\nplease re-check it! \r\nAnd you can see the " \
|
|
204
|
+
"manual at " \
|
|
205
|
+
"https://github.com/tinqlo/logfly "
|
|
206
|
+
write_log('logfly-log', 'CLI', 'error', logflyErrorMessage)
|
|
207
|
+
elif mode == 'only print':
|
|
208
|
+
print('ERROR occurred!\r\n\r\n' + str(exp) + "\r\n\r\nplease re-check it! \r\nAnd you can see the "
|
|
209
|
+
"manual at " \
|
|
210
|
+
"https://github.com/tinqlo/logfly ")
|
|
211
|
+
|
|
212
|
+
|
|
213
|
+
class ParameterERROR(Exception):
|
|
214
|
+
def __init__(self, message):
|
|
215
|
+
self.message = message
|
|
216
|
+
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.1
|
|
2
2
|
Name: logfly
|
|
3
|
-
Version: 1.
|
|
3
|
+
Version: 1.9
|
|
4
4
|
Summary: A simple log tool by python
|
|
5
5
|
Home-page: https://about.guki.me
|
|
6
6
|
Author: Yuan Sui
|
|
@@ -15,7 +15,7 @@ Requires-Python: >=3.6
|
|
|
15
15
|
Description-Content-Type: text/markdown
|
|
16
16
|
License-File: LICENSE
|
|
17
17
|
|
|
18
|
-
# logfly 1.
|
|
18
|
+
# logfly 1.9
|
|
19
19
|
### a simple log tool by python
|
|
20
20
|
|
|
21
21
|
## position
|
|
@@ -44,49 +44,14 @@ if use hidden, log will also appear in user/.1o9f1y folder
|
|
|
44
44
|
str_message: ('yes', 'no') default is 'yes', means log will print message with str()
|
|
45
45
|
|
|
46
46
|
###use2
|
|
47
|
-
|
|
47
|
+
lcreate_or_check_file(pathorfile, name, warning='Yes'):
|
|
48
|
+
create or check file.
|
|
49
|
+
pathorfile: (any str) path or file name.
|
|
50
|
+
name: (any str) file or path name.
|
|
51
|
+
if warning is 'Yes', will print warning message if file is exist.
|
|
48
52
|
|
|
49
53
|
##Description
|
|
50
54
|
pathfile is the file path that you want to create, must fill with //
|
|
51
55
|
filenname is the file name that you want to create, must is with *.*
|
|
52
56
|
|
|
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
57
|
|
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.")
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|