Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: BaseContextClass add logger #816

Merged
merged 8 commits into from
Apr 28, 2017
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions docs/source/zh-cn/basics/controller.md
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ module.exports = app => {
- `this.app`: 当前应用 [Application](./extend.md#application) 对象的实例,通过它我们可以拿到框架提供的全局对象和方法。
- `this.service`:应用定义的 [Service](./service.md),通过它我们可以访问到抽象出的业务层,等价于 `this.ctx.service` 。
- `this.config`:应用运行时的[配置项](./config.md)。
- `this.logger`:logger 对象,上面有四个方法(DEBUG,INFO,WARN,ERROR),分别代表打印四个不同级别的日志,使用方法和效果与[context logger](../core/logger.md#context-logger)中介绍的一样,但是通过这个 logger 对象记录的日志,在日志前面会加上打印该日志的文件路径,以便快速定位日志打印位置。
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

方法不是大写的吧

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[context logger] 前后空格


#### 自定义 Controller 基类

Expand Down
10 changes: 10 additions & 0 deletions docs/source/zh-cn/basics/service.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,16 @@ title: Service
};
```

### 属性

项目中的 Service 需要继承于 `app.Service`,它拥有下列属性方便我们进行开发:

- `this.ctx`: 当前请求的上下文 [Context](./extend.md#context) 对象的实例,通过它我们可以拿到框架封装好的处理当前请求的各种便捷属性和方法。
- `this.app`: 当前应用 [Application](./extend.md#application) 对象的实例,通过它我们可以拿到框架提供的全局对象和方法。
- `this.service`:应用定义的 [Service](./service.md),通过它我们可以访问到抽象出的业务层,等价于 `this.ctx.service` 。
- `this.config`:应用运行时的[配置项](./config.md)。
- `this.logger`:logger 对象,上面有四个方法(DEBUG,INFO,WARN,ERROR),分别代表打印四个不同级别的日志,使用方法和效果与[context logger](../core/logger.md#context-logger)中介绍的一样,但是通过这个 logger 对象记录的日志,在日志前面会加上打印该日志的文件路径,以便快速定位日志打印位置。

### 注意事项

- Service 文件必须放在 `app/service` 目录,可以支持多级目录,访问的时候可以通过目录名级联访问。
Expand Down
7 changes: 1 addition & 6 deletions test/lib/plugins/schedule.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
const path = require('path');
const fs = require('fs');
const utils = require('../../utils');
const sleep = require('mz-modules/sleep');

describe('test/lib/plugins/schedule.test.js', () => {
it('should schedule work', function* () {
Expand All @@ -17,12 +18,6 @@ describe('test/lib/plugins/schedule.test.js', () => {
});
});

function sleep(time) {
return new Promise(resolve => {
setTimeout(resolve, time);
});
}

function getLogContent(name) {
const logPath = path.join(__dirname, '../../fixtures/apps', name, 'logs', name, `${name}-web.log`);
return fs.readFileSync(logPath, 'utf8');
Expand Down