forked from labring/laf
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor(server): add log module (labring#539)
- Loading branch information
Showing
7 changed files
with
106 additions
and
38 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
docker.io/lafyun/runtime-node-init:latest | ||
docker.io/lafyun/runtime-node:latest |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,87 @@ | ||
import { | ||
Controller, | ||
Get, | ||
Logger, | ||
Param, | ||
Query, | ||
UseGuards, | ||
} from '@nestjs/common' | ||
import { | ||
ApiBearerAuth, | ||
ApiOperation, | ||
ApiQuery, | ||
ApiResponse, | ||
ApiTags, | ||
} from '@nestjs/swagger' | ||
import { ApplicationAuthGuard } from '../auth/application.auth.guard' | ||
import { JwtAuthGuard } from '../auth/jwt.auth.guard' | ||
import { FunctionService } from '../function/function.service' | ||
import { ResponseUtil } from '../utils/response' | ||
|
||
@ApiBearerAuth('Authorization') | ||
@Controller('apps/:appid/logs') | ||
export class LogController { | ||
private readonly logger = new Logger(LogController.name) | ||
|
||
constructor(private readonly funcService: FunctionService) {} | ||
|
||
/** | ||
* Get function logs | ||
* @param appid | ||
* @param name | ||
* @returns | ||
*/ | ||
@ApiTags('Function') | ||
@ApiResponse({ type: ResponseUtil }) | ||
@ApiOperation({ summary: 'Get function logs' }) | ||
@UseGuards(JwtAuthGuard, ApplicationAuthGuard) | ||
@ApiQuery({ | ||
name: 'functionName', | ||
type: String, | ||
description: 'The function name. Optional', | ||
required: false, | ||
}) | ||
@ApiQuery({ | ||
name: 'requestId', | ||
type: String, | ||
description: 'The request id. Optional', | ||
required: false, | ||
}) | ||
@ApiQuery({ | ||
name: 'page', | ||
type: String, | ||
description: 'The page number, default is 1', | ||
required: false, | ||
}) | ||
@ApiQuery({ | ||
name: 'limit', | ||
type: String, | ||
description: 'The limit number, default is 10', | ||
required: false, | ||
}) | ||
@Get('functions') | ||
async getLogs( | ||
@Param('appid') appid: string, | ||
@Query('requestId') requestId?: string, | ||
@Query('functionName') functionName?: string, | ||
@Query('limit') limit?: number, | ||
@Query('page') page?: number, | ||
) { | ||
page = page || 1 | ||
limit = limit || 10 | ||
|
||
const res = await this.funcService.findLogs(appid, { | ||
requestId, | ||
functionName, | ||
limit, | ||
page, | ||
}) | ||
|
||
return ResponseUtil.ok({ | ||
list: res.data, | ||
total: res.total, | ||
page, | ||
limit, | ||
}) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
import { Module } from '@nestjs/common' | ||
import { JwtService } from '@nestjs/jwt' | ||
import { ApplicationModule } from '../application/application.module' | ||
import { FunctionService } from '../function/function.service' | ||
import { PrismaService } from '../prisma.service' | ||
import { LogController } from './log.controller' | ||
|
||
@Module({ | ||
imports: [ApplicationModule], | ||
controllers: [LogController], | ||
providers: [FunctionService, PrismaService, JwtService], | ||
}) | ||
export class LogModule {} |