Skip to content

Commit

Permalink
add log level
Browse files Browse the repository at this point in the history
  • Loading branch information
clairton committed Jul 26, 2023
1 parent d84a46d commit 1a652d3
Show file tree
Hide file tree
Showing 6 changed files with 13 additions and 8 deletions.
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -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",
Expand Down
5 changes: 3 additions & 2 deletions src/services/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<GroupMetadata | undefined>
Expand Down Expand Up @@ -55,7 +56,7 @@ export type Config = {
getStore: getStore
baseStore: string
webhooks: Webhook[]
logLevel: string
logLevel: Level | undefined
getGroupMetadata: GetGroupMetadata
ignoreDataStore: boolean
}
Expand All @@ -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,
Expand Down
3 changes: 2 additions & 1 deletion src/services/config_by_env.ts
Original file line number Diff line number Diff line change
@@ -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,
Expand Down Expand Up @@ -29,7 +30,7 @@ export const getConfigByEnv: getConfig = async (phone: string): Promise<Config>
// 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'
Expand Down
4 changes: 2 additions & 2 deletions src/services/logger.ts
Original file line number Diff line number Diff line change
@@ -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
5 changes: 3 additions & 2 deletions src/services/socket.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<void>
export type OnStatus = (text: string, important: boolean) => Promise<void>
Expand Down Expand Up @@ -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,
},
Expand Down Expand Up @@ -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({
Expand Down

0 comments on commit 1a652d3

Please sign in to comment.