Skip to content
Toggle navigation
P
Projects
G
Groups
S
Snippets
Help
马玮
/
carspider
This project
Loading...
Sign in
Toggle navigation
Go to a project
Project
Repository
Issues
0
Merge Requests
0
Pipelines
Wiki
Members
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Commit
7ae3c13f
authored
Sep 04, 2017
by
马玮
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add log marks
parent
0e83aa86
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
42 additions
and
9 deletions
+42
-9
boot.js
+1
-3
lib/DI.js
+16
-2
lib/spider/Base.js
+2
-1
lib/spider/dealer/Autohome.js
+2
-0
test.js
+21
-3
No files found.
boot.js
View file @
7ae3c13f
...
...
@@ -64,9 +64,7 @@ if (commandError.length > 0) {
output
:
process
.
stdout
});
DI
.
shutdownLogger
(()
=>
{
// do nothing
});
DI
.
shutdownLogger
(()
=>
{});
rl
.
write
(
'正在释放资源...\n预计3秒后退出: '
);
for
(
let
i
=
3
;
i
>
0
;
i
-=
1
)
{
...
...
lib/DI.js
View file @
7ae3c13f
...
...
@@ -13,6 +13,9 @@ class DI {
this
.
params
=
params
;
}
static
init
()
{
}
static
dir
()
{
console
.
log
(
App
.
root
);
console
.
log
(
path
.
parse
(
process
.
mainModule
.
filename
).
dir
);
...
...
@@ -23,12 +26,23 @@ class DI {
console
.
log
(
process
.
cwd
());
}
static
getLogger
()
{
static
setLogMark
(
category
,
context
)
{
this
.
LOG_MARK
=
this
.
LOG_MARK
||
{};
this
.
LOG_MARK
[
category
]
=
context
;
}
static
getLogger
(
category
=
'SPIDER'
)
{
this
.
LOG_MARK
=
this
.
LOG_MARK
||
{};
const
level
=
process
.
env
.
LOG_LEVEL
||
'info'
;
const
appenders
=
(
process
.
env
.
LOG_TYPE
?
process
.
env
.
LOG_TYPE
.
split
(
','
)
:
null
)
||
[
'console'
,
'carspider'
];
const
layout
=
{
type
:
'pattern'
,
pattern
:
'%[[%d] [%p] [PID:%z] %X{user}%] %m'
,
pattern
:
'%[[%d] [%p] [PID:%z] [%x{mark}%]] %m'
,
tokens
:
{
mark
:
(
logEvent
)
=>
{
return
this
.
LOG_MARK
[
category
]
||
'Master'
;
}
},
};
// 按文件大小回滚配置,待以后备用
// { type: 'file', filename: `${__basedir}/logs/dealer/carspider.log`, maxLogSize: 10485760, backups: 3, compress: false }
...
...
lib/spider/Base.js
View file @
7ae3c13f
...
...
@@ -16,7 +16,8 @@ class Base {
this
.
params
=
params
;
this
.
loginTimes
=
0
;
this
.
maxLoginTimes
=
3
;
logger
.
addContext
(
'user'
,
'mawei'
);
logger
.
addContext
(
'user'
,
'accountID: 1'
);
this
.
logger
=
logger
;
}
async
execute
()
{
...
...
lib/spider/dealer/Autohome.js
View file @
7ae3c13f
...
...
@@ -22,6 +22,8 @@ axios.defaults.withCredentials = true;
class
Autohome
extends
Base
{
constructor
(
params
)
{
super
(
params
);
this
.
logger
.
error
(
'欢迎来到王者荣耀'
);
return
;
}
async
tryLogin
()
{
...
...
test.js
View file @
7ae3c13f
const
Promise
=
require
(
'bluebird'
);
const
utils
=
require
(
'./lib/utils'
);
const
_
=
require
(
'./lib/utils/lodash'
);
process
.
env
.
NODE_ENV
=
process
.
env
.
NODE_ENV
||
'production'
;
process
.
env
.
NODE_CONFIG_DIR
=
__dirname
+
'/config'
;
global
.
__basedir
=
__dirname
;
global
.
__libdir
=
__basedir
+
'/lib'
;
const
DI
=
require
(
'./lib/DI'
);
const
logger
=
DI
.
getLogger
();
DI
.
name
=
'mawei'
;
DI
.
setLogMark
(
'SPIDER'
,
'accountID:1'
);
console
.
log
(
DI
.
entrance
);
logger
.
addContext
(
'user'
,
'Main'
);
logger
.
trace
(
'Entering cheese testing'
);
logger
.
debug
(
'Got cheese.'
);
logger
.
info
(
'Cheese is Gouda.'
);
logger
.
warn
(
'Cheese is quite smelly.'
);
logger
.
error
(
'Cheese is too ripe!'
);
logger
.
fatal
(
'Cheese was breeding ground for listeria.'
);
return
;
console
.
log
(
_
.
random
(
1
,
5
));
console
.
log
(
_
.
random
(
1
,
5
));
console
.
log
(
_
.
random
(
1
,
5
));
console
.
log
(
utils
.
md5
(
'欢迎来到王者荣耀'
));
return
;
// const DI = require('./lib/DI');
// process.env.NODE_ENV = process.env.NODE_ENV || 'production';
// process.env.NODE_CONFIG_DIR = __dirname + '/config';
//
// const _ = require('lodash/core');
...
...
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