Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in
Toggle navigation
C
coco
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
ops
coco
Commits
491ef181
Commit
491ef181
authored
Jan 22, 2018
by
ibuler
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
[Logging] 修改logger
parent
3c7b0d56
Hide whitespace changes
Inline
Side-by-side
Showing
12 changed files
with
70 additions
and
60 deletions
+70
-60
app.py
coco/app.py
+2
-2
httpd.py
coco/httpd.py
+2
-2
interactive.py
coco/interactive.py
+3
-4
interface.py
coco/interface.py
+2
-2
logger.py
coco/logger.py
+43
-31
models.py
coco/models.py
+1
-2
proxy.py
coco/proxy.py
+2
-3
recorder.py
coco/recorder.py
+2
-2
session.py
coco/session.py
+3
-2
sshd.py
coco/sshd.py
+2
-8
tasks.py
coco/tasks.py
+3
-2
utils.py
coco/utils.py
+5
-0
No files found.
coco/app.py
View file @
491ef181
...
...
@@ -6,7 +6,6 @@ import datetime
import
os
import
time
import
threading
import
logging
import
socket
import
json
...
...
@@ -18,12 +17,13 @@ from .httpd import HttpServer
from
.logger
import
create_logger
from
.tasks
import
TaskHandler
from
.recorder
import
get_command_recorder_class
,
get_replay_recorder_class
from
.utils
import
get_logger
__version__
=
'0.5.0'
BASE_DIR
=
os
.
path
.
dirname
(
os
.
path
.
dirname
(
__file__
))
logger
=
logging
.
getL
ogger
(
__file__
)
logger
=
get_l
ogger
(
__file__
)
class
Coco
:
...
...
coco/httpd.py
View file @
491ef181
...
...
@@ -2,7 +2,6 @@
# -*- coding: utf-8 -*-
#
import
os
import
logging
import
socket
from
flask_socketio
import
SocketIO
,
Namespace
,
emit
,
join_room
,
leave_room
from
flask
import
Flask
,
send_from_directory
,
render_template
,
request
,
jsonify
...
...
@@ -12,11 +11,12 @@ import uuid
from
jms.models
import
User
from
.models
import
Request
,
Client
,
WSProxy
from
.proxy
import
ProxyServer
from
.utils
import
get_logger
__version__
=
'0.4.0'
BASE_DIR
=
os
.
path
.
dirname
(
os
.
path
.
dirname
(
__file__
))
logger
=
logging
.
getL
ogger
(
__file__
)
logger
=
get_l
ogger
(
__file__
)
class
BaseWebSocketHandler
:
...
...
coco/interactive.py
View file @
491ef181
...
...
@@ -2,22 +2,21 @@
# -*- coding: utf-8 -*-
#
import
logging
import
socket
import
threading
import
weakref
import
os
from
jms.models
import
Asset
,
AssetGroup
from
.
import
char
from
.utils
import
wrap_with_line_feed
as
wr
,
wrap_with_title
as
title
,
\
wrap_with_primary
as
primary
,
wrap_with_warning
as
warning
,
\
is_obj_attr_has
,
is_obj_attr_eq
,
sort_assets
,
TtyIOParser
,
\
ugettext
as
_
ugettext
as
_
,
get_logger
from
.proxy
import
ProxyServer
logger
=
logging
.
getL
ogger
(
__file__
)
logger
=
get_l
ogger
(
__file__
)
class
InteractiveServer
:
...
...
coco/interface.py
View file @
491ef181
...
...
@@ -2,13 +2,13 @@
# -*- coding: utf-8 -*-
#
import
logging
import
paramiko
import
threading
import
weakref
from
.utils
import
get_logger
logger
=
logging
.
getL
ogger
(
__file__
)
logger
=
get_l
ogger
(
__file__
)
class
SSHInterface
(
paramiko
.
ServerInterface
):
...
...
coco/logger.py
View file @
491ef181
...
...
@@ -4,43 +4,55 @@
import
os
import
logging
from
logging
import
StreamHandler
from
logging.handlers
import
TimedRotatingFileHandler
LOG_LEVELS
=
{
'DEBUG'
:
logging
.
DEBUG
,
'INFO'
:
logging
.
INFO
,
'WARN'
:
logging
.
WARNING
,
'WARNING'
:
logging
.
WARNING
,
'ERROR'
:
logging
.
ERROR
,
'FATAL'
:
logging
.
FATAL
,
'CRITICAL'
:
logging
.
CRITICAL
,
}
from
logging.config
import
dictConfig
def
create_logger
(
app
):
level
=
app
.
config
[
'LOG_LEVEL'
]
level
=
LOG_LEVELS
.
get
(
level
,
logging
.
INFO
)
log_dir
=
app
.
config
.
get
(
'LOG_DIR'
)
log_path
=
os
.
path
.
join
(
log_dir
,
'coco.log'
)
main_setting
=
{
'handlers'
:
[
'console'
,
'file'
],
'level'
:
level
,
'propagate'
:
False
,
}
config
=
dict
(
version
=
1
,
formatters
=
{
"main"
:
{
'format'
:
'
%(asctime)
s [
%(module)
s
%(levelname)
s]
%(message)
s'
,
'datefmt'
:
'
%
Y-
%
m-
%
d
%
H:
%
M:
%
S'
,
},
'simple'
:
{
'format'
:
'
%(asctime)
s [
%(levelname)-8
s]
%(message)
s'
,
'datefmt'
:
'
%
Y-
%
m-
%
d
%
H:
%
M:
%
S'
,
}
},
handlers
=
{
'null'
:
{
'level'
:
'DEBUG'
,
'class'
:
'logging.NullHandler'
,
},
'console'
:
{
'level'
:
'DEBUG'
,
'class'
:
'logging.StreamHandler'
,
'formatter'
:
'main'
},
'file'
:
{
'level'
:
'DEBUG'
,
'class'
:
'logging.FileHandler'
,
'formatter'
:
'main'
,
'filename'
:
log_path
,
},
},
loggers
=
{
'coco'
:
main_setting
,
'paramiko'
:
main_setting
,
}
)
dictConfig
(
config
)
logger
=
logging
.
getLogger
()
return
logger
main_formatter
=
logging
.
Formatter
(
fmt
=
'
%(asctime)
s [
%(module)
s
%(levelname)
s]
%(message)
s'
,
datefmt
=
'
%
Y-
%
m-
%
d
%
H:
%
M:
%
S'
)
# main_formatter = logging.Formatter(
# fmt='%(asctime)s [%(levelname)s] %(message)s',
# datefmt='%Y-%m-%d %H:%M:%S'
# )
console_handler
=
StreamHandler
()
file_handler
=
TimedRotatingFileHandler
(
filename
=
log_path
,
when
=
'D'
,
backupCount
=
10
)
for
handler
in
[
console_handler
,
file_handler
]:
handler
.
setFormatter
(
main_formatter
)
logger
.
addHandler
(
handler
)
logger
.
setLevel
(
level
)
logging
.
getLogger
(
"requests"
)
.
setLevel
(
logging
.
WARNING
)
coco/models.py
View file @
491ef181
...
...
@@ -2,14 +2,13 @@
# -*- coding: utf-8 -*-
import
threading
import
datetime
import
logging
import
weakref
from
.
import
char
from
.
import
utils
BUF_SIZE
=
4096
logger
=
logging
.
getL
ogger
(
__file__
)
logger
=
utils
.
get_l
ogger
(
__file__
)
class
Request
:
...
...
coco/proxy.py
View file @
491ef181
...
...
@@ -4,7 +4,6 @@
import
socket
import
threading
import
logging
import
time
import
weakref
import
paramiko
...
...
@@ -13,10 +12,10 @@ from paramiko.ssh_exception import SSHException
from
.session
import
Session
from
.models
import
Server
from
.utils
import
wrap_with_line_feed
as
wr
,
wrap_with_warning
as
warning
,
\
get_private_key_fingerprint
get_private_key_fingerprint
,
get_logger
logger
=
logging
.
getL
ogger
(
__file__
)
logger
=
get_l
ogger
(
__file__
)
TIMEOUT
=
8
BUF_SIZE
=
4096
...
...
coco/recorder.py
View file @
491ef181
...
...
@@ -3,7 +3,6 @@
#
import
abc
import
logging
import
threading
import
time
import
os
...
...
@@ -13,9 +12,10 @@ import shutil
from
jms_es_sdk
import
ESStore
from
.utils
import
get_logger
from
.alignment
import
MemoryQueue
logger
=
logging
.
getL
ogger
(
__file__
)
logger
=
get_l
ogger
(
__file__
)
BUF_SIZE
=
1024
...
...
coco/session.py
View file @
491ef181
...
...
@@ -3,13 +3,14 @@
#
import
threading
import
uuid
import
logging
import
datetime
import
selectors
import
time
from
.utils
import
get_logger
BUF_SIZE
=
1024
logger
=
logging
.
getL
ogger
(
__file__
)
logger
=
get_l
ogger
(
__file__
)
class
Session
:
...
...
coco/sshd.py
View file @
491ef181
...
...
@@ -3,20 +3,16 @@
#
import
os
import
logging
import
socket
import
threading
import
paramiko
import
sys
import
time
from
.utils
import
ssh_key_gen
from
.utils
import
ssh_key_gen
,
get_logger
from
.interface
import
SSHInterface
from
.interactive
import
InteractiveServer
from
.models
import
Client
,
Request
logger
=
logging
.
getL
ogger
(
__file__
)
logger
=
get_l
ogger
(
__file__
)
BACKLOG
=
5
...
...
@@ -90,8 +86,6 @@ class SSHServer:
def
handle_chan
(
self
,
chan
,
request
):
client
=
Client
(
chan
,
request
)
print
(
chan
)
print
(
request
)
self
.
app
.
add_client
(
client
)
self
.
dispatch
(
client
)
...
...
coco/tasks.py
View file @
491ef181
...
...
@@ -2,9 +2,10 @@
# -*- coding: utf-8 -*-
#
import
weakref
import
logging
logger
=
logging
.
getLogger
(
__file__
)
from
.utils
import
get_logger
logger
=
get_logger
(
__file__
)
class
TaskHandler
:
...
...
coco/utils.py
View file @
491ef181
...
...
@@ -5,6 +5,7 @@
from
__future__
import
unicode_literals
import
hashlib
import
logging
import
re
import
os
import
threading
...
...
@@ -371,4 +372,8 @@ def compile_message():
pass
def
get_logger
(
file_name
):
return
logging
.
getLogger
(
'coco.'
+
file_name
)
ugettext
=
_gettext
()
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment