diff --git a/README.md b/README.md index 20106a15..9d71d9a4 100644 --- a/README.md +++ b/README.md @@ -202,6 +202,8 @@ REJECT_CALLS_WEBHOOK=message to send webook when receive a call, default is empt SEND_CONNECTION_STATUS=true to send all connection status to webhook, false to send only important messages, default is true UNOAPI_BASE_STORE=dir where save sessions, medias and stores. Defaul is ./data IGNORE_DATA_STORE=ignore save/retrieve data(message, contacts, groups...) +LOG_LEVEL=log level, default warn +UNO_LOG_LEVEL=uno log level. default LOG_LEVEL ``` ## Examples diff --git a/package.json b/package.json index 8889ad6f..cdc0b77c 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "unoapi-cloud", - "version": "0.30.1", + "version": "0.30.2", "description": "Unoapi Cloud", "main": "./dist/index.js", "types": "./dist/index.d.ts", diff --git a/src/services/config.ts b/src/services/config.ts index 70aabc6d..12b9b4a2 100644 --- a/src/services/config.ts +++ b/src/services/config.ts @@ -3,6 +3,7 @@ import { getStoreFile } from './store_file' import { GroupMetadata, WAMessage, WAMessageKey } from '@whiskeysockets/baileys' import { isIndividualJid } from './transformer' import logger from './logger' +import { Level } from 'pino' export interface GetGroupMetadata { (message: WAMessage, store: Store): Promise @@ -55,7 +56,7 @@ export type Config = { getStore: getStore baseStore: string webhooks: Webhook[] - logLevel: string + logLevel: Level | undefined getGroupMetadata: GetGroupMetadata ignoreDataStore: boolean } @@ -71,7 +72,7 @@ export const defaultConfig: Config = { composingMessage: false, rejectCalls: '', rejectCallsWebhook: '', - logLevel: '', + logLevel: undefined, autoRestart: false, // eslint-disable-next-line @typescript-eslint/no-unused-vars shouldIgnoreJid: (_jid: string) => false, diff --git a/src/services/config_by_env.ts b/src/services/config_by_env.ts index 9f8226dc..f371d560 100644 --- a/src/services/config_by_env.ts +++ b/src/services/config_by_env.ts @@ -1,6 +1,7 @@ import { MessageFilter } from './message_filter' import { getConfig, defaultConfig, Config, ignoreGetGroupMetadata, getGroupMetadata } from './config' import logger from './logger' +import { Level } from 'pino' const { IGNORE_GROUP_MESSAGES, @@ -29,7 +30,7 @@ export const getConfigByEnv: getConfig = async (phone: string): Promise // eslint-disable-next-line @typescript-eslint/no-explicit-any const _undefined: any = undefined config = defaultConfig - config.logLevel || process.env.LOG_LEVEL + config.logLevel = (process.env.LOG_LEVEL || config.logLevel || (process.env.NODE_ENV == 'development' ? 'debug' : 'error')) as Level config.ignoreGroupMessages = IGNORE_GROUP_MESSAGES == _undefined ? true : IGNORE_GROUP_MESSAGES == 'true' config.ignoreBroadcastStatuses = IGNORE_BROADCAST_STATUSES === _undefined ? true : IGNORE_BROADCAST_STATUSES == 'true' config.ignoreBroadcastMessages = IGNORE_BROADCAST_MESSAGES === _undefined ? false : IGNORE_OWN_MESSAGES == 'true' diff --git a/src/services/logger.ts b/src/services/logger.ts index 684258b4..05b7d668 100644 --- a/src/services/logger.ts +++ b/src/services/logger.ts @@ -1,6 +1,6 @@ -import P from 'pino' +import P, { Level } from 'pino' const logger = P({ timestamp: () => `,"time":"${new Date().toJSON()}"` }) -logger.level = process.env.LOG_LEVEL || (process.env.NODE_ENV == 'development' ? 'debug' : 'error') +logger.level = (process.env.UNO_LOG_LEVEL || process.env.LOG_LEVEL || (process.env.NODE_ENV == 'development' ? 'debug' : 'error')) as Level export default logger diff --git a/src/services/socket.ts b/src/services/socket.ts index 613eee67..06121e2e 100644 --- a/src/services/socket.ts +++ b/src/services/socket.ts @@ -17,6 +17,7 @@ import { Store } from './store' import NodeCache from 'node-cache' import { isValidPhoneNumber } from './transformer' import logger from './logger' +import { Level } from 'pino' export type OnQrCode = (qrCode: string, time: number, limit: number) => Promise export type OnStatus = (text: string, important: boolean) => Promise @@ -69,7 +70,7 @@ export const connect = async ({ config = { ignoreHistoryMessages: true, autoRestart: false, - logLevel: '', + logLevel: undefined, // eslint-disable-next-line @typescript-eslint/no-unused-vars shouldIgnoreJid: (_jid: string) => false, }, @@ -179,7 +180,7 @@ export const connect = async ({ const browser: WABrowserDescription = ['Unoapi', 'Chrome', release()] const loggerBaileys = MAIN_LOGGER.child({}) - logger.level = config.logLevel || (process.env.NODE_ENV == 'development' ? 'debug' : 'error') + logger.level = config.logLevel as Level try { sock = makeWASocket({