mirror of
https://github.com/EvolutionAPI/evolution-api.git
synced 2025-07-27 02:48:39 -06:00
Add log
This commit is contained in:
parent
45e03d87c7
commit
b73e260e35
13
.vscode/settings.json
vendored
13
.vscode/settings.json
vendored
@ -1,13 +0,0 @@
|
|||||||
{
|
|
||||||
"editor.fontSize": 13,
|
|
||||||
"editor.fontLigatures": true,
|
|
||||||
"editor.letterSpacing": 0.5,
|
|
||||||
"editor.smoothScrolling": true,
|
|
||||||
"editor.tabSize": 2,
|
|
||||||
"editor.codeActionsOnSave": {
|
|
||||||
"source.fixAll.eslint": "explicit",
|
|
||||||
"source.fixAll": "explicit"
|
|
||||||
},
|
|
||||||
"prisma-smart-formatter.typescript.defaultFormatter": "esbenp.prettier-vscode",
|
|
||||||
"prisma-smart-formatter.prisma.defaultFormatter": "Prisma.prisma"
|
|
||||||
}
|
|
@ -1,29 +0,0 @@
|
|||||||
version: '3.3'
|
|
||||||
|
|
||||||
services:
|
|
||||||
api:
|
|
||||||
container_name: evolution_api
|
|
||||||
image: evolution/api:local
|
|
||||||
build: .
|
|
||||||
restart: always
|
|
||||||
ports:
|
|
||||||
- 8080:8080
|
|
||||||
volumes:
|
|
||||||
- evolution_instances:/evolution/instances
|
|
||||||
- evolution_store:/evolution/store
|
|
||||||
networks:
|
|
||||||
- evolution-net
|
|
||||||
env_file:
|
|
||||||
- ./Docker/.env
|
|
||||||
command: ['node', './dist/src/main.js']
|
|
||||||
expose:
|
|
||||||
- 8080
|
|
||||||
|
|
||||||
volumes:
|
|
||||||
evolution_instances:
|
|
||||||
evolution_store:
|
|
||||||
|
|
||||||
networks:
|
|
||||||
evolution-net:
|
|
||||||
name: evolution-net
|
|
||||||
driver: bridge
|
|
@ -1,80 +0,0 @@
|
|||||||
version: '3.3'
|
|
||||||
|
|
||||||
services:
|
|
||||||
api:
|
|
||||||
container_name: evolution_api
|
|
||||||
image: evolution/api:local
|
|
||||||
build: .
|
|
||||||
restart: always
|
|
||||||
ports:
|
|
||||||
- 8080:8080
|
|
||||||
volumes:
|
|
||||||
- evolution_instances:/evolution/instances
|
|
||||||
- evolution_store:/evolution/store
|
|
||||||
networks:
|
|
||||||
- evolution-net
|
|
||||||
env_file:
|
|
||||||
- ./Docker/.env
|
|
||||||
command: ['node', './dist/src/main.js']
|
|
||||||
expose:
|
|
||||||
- 8080
|
|
||||||
|
|
||||||
mongodb:
|
|
||||||
container_name: mongodb
|
|
||||||
image: mongo
|
|
||||||
restart: always
|
|
||||||
ports:
|
|
||||||
- 27017:27017
|
|
||||||
environment:
|
|
||||||
- MONGO_INITDB_ROOT_USERNAME=root
|
|
||||||
- MONGO_INITDB_ROOT_PASSWORD=root
|
|
||||||
- PUID=1000
|
|
||||||
- PGID=1000
|
|
||||||
volumes:
|
|
||||||
- evolution_mongodb_data:/data/db
|
|
||||||
- evolution_mongodb_configdb:/data/configdb
|
|
||||||
networks:
|
|
||||||
- evolution-net
|
|
||||||
expose:
|
|
||||||
- 27017
|
|
||||||
|
|
||||||
mongo-express:
|
|
||||||
image: mongo-express
|
|
||||||
networks:
|
|
||||||
- evolution-net
|
|
||||||
environment:
|
|
||||||
ME_CONFIG_BASICAUTH_USERNAME: root
|
|
||||||
ME_CONFIG_BASICAUTH_PASSWORD: root
|
|
||||||
ME_CONFIG_MONGODB_SERVER: mongodb
|
|
||||||
ME_CONFIG_MONGODB_ADMINUSERNAME: root
|
|
||||||
ME_CONFIG_MONGODB_ADMINPASSWORD: root
|
|
||||||
ports:
|
|
||||||
- 8081:8081
|
|
||||||
links:
|
|
||||||
- mongodb
|
|
||||||
|
|
||||||
redis:
|
|
||||||
image: redis:latest
|
|
||||||
container_name: redis
|
|
||||||
command: >
|
|
||||||
redis-server
|
|
||||||
--port 6379
|
|
||||||
--appendonly yes
|
|
||||||
volumes:
|
|
||||||
- evolution_redis:/data
|
|
||||||
networks:
|
|
||||||
- evolution-net
|
|
||||||
ports:
|
|
||||||
- 6379:6379
|
|
||||||
|
|
||||||
volumes:
|
|
||||||
evolution_instances:
|
|
||||||
evolution_store:
|
|
||||||
evolution_mongodb_data:
|
|
||||||
evolution_mongodb_configdb:
|
|
||||||
evolution_redis:
|
|
||||||
|
|
||||||
networks:
|
|
||||||
evolution-net:
|
|
||||||
name: evolution-net
|
|
||||||
driver: bridge
|
|
@ -1,28 +0,0 @@
|
|||||||
version: '3.3'
|
|
||||||
|
|
||||||
services:
|
|
||||||
api:
|
|
||||||
container_name: evolution_api
|
|
||||||
image: atendai/evolution-api:latest
|
|
||||||
restart: always
|
|
||||||
ports:
|
|
||||||
- 8080:8080
|
|
||||||
volumes:
|
|
||||||
- evolution_instances:/evolution/instances
|
|
||||||
- evolution_store:/evolution/store
|
|
||||||
networks:
|
|
||||||
- evolution-net
|
|
||||||
env_file:
|
|
||||||
- ./Docker/.env
|
|
||||||
command: ['node', './dist/src/main.js']
|
|
||||||
expose:
|
|
||||||
- 8080
|
|
||||||
|
|
||||||
volumes:
|
|
||||||
evolution_instances:
|
|
||||||
evolution_store:
|
|
||||||
|
|
||||||
networks:
|
|
||||||
evolution-net:
|
|
||||||
name: evolution-net
|
|
||||||
driver: bridge
|
|
@ -26,6 +26,8 @@ export type Log = {
|
|||||||
LEVEL: LogLevel[];
|
LEVEL: LogLevel[];
|
||||||
COLOR: boolean;
|
COLOR: boolean;
|
||||||
BAILEYS: LogBaileys;
|
BAILEYS: LogBaileys;
|
||||||
|
LOG_PATH: string;
|
||||||
|
LOG_EXPIRATION_DAYS: number;
|
||||||
};
|
};
|
||||||
|
|
||||||
export type SaveData = {
|
export type SaveData = {
|
||||||
@ -265,6 +267,8 @@ export class ConfigService {
|
|||||||
],
|
],
|
||||||
COLOR: process.env?.LOG_COLOR === 'true',
|
COLOR: process.env?.LOG_COLOR === 'true',
|
||||||
BAILEYS: (process.env?.LOG_BAILEYS as LogBaileys) || 'error',
|
BAILEYS: (process.env?.LOG_BAILEYS as LogBaileys) || 'error',
|
||||||
|
LOG_PATH: join(__dirname, '../../') + process.env?.LOG_PATH || join(__dirname, '../../')+'log',
|
||||||
|
LOG_EXPIRATION_DAYS: Number.parseInt(process.env?.LOG_EXPIRATION_DAYS),
|
||||||
},
|
},
|
||||||
DEL_INSTANCE: isBooleanString(process.env?.DEL_INSTANCE)
|
DEL_INSTANCE: isBooleanString(process.env?.DEL_INSTANCE)
|
||||||
? process.env.DEL_INSTANCE === 'true'
|
? process.env.DEL_INSTANCE === 'true'
|
||||||
|
@ -1,5 +1,6 @@
|
|||||||
import dayjs from 'dayjs';
|
import dayjs from 'dayjs';
|
||||||
import fs from 'fs';
|
import fs, { mkdir } from 'fs';
|
||||||
|
import util from 'util';
|
||||||
|
|
||||||
import { configService, Log } from './env.config';
|
import { configService, Log } from './env.config';
|
||||||
const packageJson = JSON.parse(fs.readFileSync('./package.json', 'utf8'));
|
const packageJson = JSON.parse(fs.readFileSync('./package.json', 'utf8'));
|
||||||
@ -70,6 +71,18 @@ export class Logger {
|
|||||||
this.configService.get<Log>('LOG').LEVEL.forEach((level) => types.push(Type[level]));
|
this.configService.get<Log>('LOG').LEVEL.forEach((level) => types.push(Type[level]));
|
||||||
|
|
||||||
const typeValue = typeof value;
|
const typeValue = typeof value;
|
||||||
|
|
||||||
|
salvarLog(this.configService.get<Log>('LOG'),
|
||||||
|
'[Evolution API]'+
|
||||||
|
process.pid.toString()+
|
||||||
|
'-'+
|
||||||
|
`${formatDateLog(Date.now())} `+
|
||||||
|
`${type} `+
|
||||||
|
`[${this.context}]`+
|
||||||
|
`[${typeValue}]`+
|
||||||
|
value
|
||||||
|
);
|
||||||
|
|
||||||
if (types.includes(type)) {
|
if (types.includes(type)) {
|
||||||
if (configService.get<Log>('LOG').COLOR) {
|
if (configService.get<Log>('LOG').COLOR) {
|
||||||
console.log(
|
console.log(
|
||||||
@ -139,3 +152,34 @@ export class Logger {
|
|||||||
this.console(value, Type.DARK);
|
this.console(value, Type.DARK);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function salvarLog(env: any, log: string): void {
|
||||||
|
mkdir(env.LOG_PATH, { recursive: true }, (err) => { if (err) throw err; });
|
||||||
|
let file = new Date().toLocaleDateString().replaceAll('/', '');
|
||||||
|
file = env.LOG_PATH + '/' + file + '.txt';
|
||||||
|
try {
|
||||||
|
if (fs.existsSync(file)) {
|
||||||
|
fs.appendFileSync(file, log, "utf8");
|
||||||
|
} else {
|
||||||
|
fs.writeFileSync(file, log);
|
||||||
|
}
|
||||||
|
excluirArquivosAntigos(env.LOG_PATH, 5);
|
||||||
|
} catch (accessError) {
|
||||||
|
console.error('Erro ao salvar o log:', accessError);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
function excluirArquivosAntigos(path: string, diasLimite: number): void {
|
||||||
|
const data = new Date();
|
||||||
|
data.setDate(data.getDate() - diasLimite);
|
||||||
|
let limite = Number.parseInt(data.toLocaleDateString().replaceAll('/', ''));
|
||||||
|
fs.readdirSync(path).forEach((nomeArquivo) => {
|
||||||
|
let file = Number.parseInt(nomeArquivo.replace(/^.*[\\\/]/, '').replace(/\.[^/.]+$/, ''));
|
||||||
|
if (file < limite) {
|
||||||
|
fs.unlinkSync(path + '/' + nomeArquivo);
|
||||||
|
console.log(`Arquivo ${nomeArquivo} excluído.`);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
@ -16,7 +16,8 @@
|
|||||||
"skipLibCheck": true,
|
"skipLibCheck": true,
|
||||||
"strictNullChecks": false,
|
"strictNullChecks": false,
|
||||||
"incremental": true,
|
"incremental": true,
|
||||||
"noImplicitAny": false
|
"noImplicitAny": false,
|
||||||
|
"lib": ["ES2021.String"]
|
||||||
},
|
},
|
||||||
"exclude": ["node_modules", "./test", "./dist", "./prisma"]
|
"exclude": ["node_modules", "./test", "./dist", "./prisma"]
|
||||||
}
|
}
|
Loading…
Reference in New Issue
Block a user