Skip to content

Commit

Permalink
Linting
Browse files Browse the repository at this point in the history
  • Loading branch information
islathehut committed Mar 18, 2024
1 parent d5c31a4 commit 72be94a
Show file tree
Hide file tree
Showing 17 changed files with 91 additions and 60 deletions.
9 changes: 3 additions & 6 deletions packages/logger/src/const.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,7 @@
import { LogLevel, LogTransportType } from "./enums";
import { LogLevel, LogTransportType } from './enums'

export const DEFAULT_LOG_LEVEL: LogLevel = LogLevel.INFO

export const DEFAULT_LOG_TRANSPORTS: LogTransportType[] = [
LogTransportType.CONSOLE_ELECTRON,
LogTransportType.FILE
]
export const DEFAULT_LOG_TRANSPORTS: LogTransportType[] = [LogTransportType.CONSOLE_ELECTRON, LogTransportType.FILE]

export const DEFAULT_LOG_FILE = 'dist/logs/stdout'
export const DEFAULT_LOG_FILE = 'dist/logs/stdout'
16 changes: 8 additions & 8 deletions packages/logger/src/enums.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
export enum LogLevel {
DEBUG = 'debug',
INFO = 'info',
WARN = 'warn',
ERROR = 'error'
DEBUG = 'debug',
INFO = 'info',
WARN = 'warn',
ERROR = 'error',
}

export enum LogTransportType {
CONSOLE = 'CONSOLE',
CONSOLE_ELECTRON = 'CONSOLE_ELECTRON',
FILE = 'FILE'
}
CONSOLE = 'CONSOLE',
CONSOLE_ELECTRON = 'CONSOLE_ELECTRON',
FILE = 'FILE',
}
38 changes: 20 additions & 18 deletions packages/logger/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,11 +47,11 @@ export class LoggingHandler {
let config: GenerateLoggerConfig
if (typeof moduleNameOrConfig === 'string') {
config = {
moduleNames: [moduleNameOrConfig]
moduleNames: [moduleNameOrConfig],
} as GenerateLoggerConfig
} else if (moduleNameOrConfig instanceof Array) {
config = {
moduleNames: moduleNameOrConfig
moduleNames: moduleNameOrConfig,
} as GenerateLoggerConfig
} else {
config = moduleNameOrConfig
Expand All @@ -62,12 +62,12 @@ export class LoggingHandler {

return winston.createLogger({
defaultMeta: {
label: name
label: name,
},
level: config.logLevel,
format: this.getFormats(),
transports: this.getTransports(config, name)
});
transports: this.getTransports(config, name),
})
}

private buildModuleLoggerConfig(config: GenerateLoggerConfig, name: string): GenerateLoggerConfig {
Expand All @@ -78,7 +78,7 @@ export class LoggingHandler {
moduleNames: config.moduleNames,
logLevel,
transports,
logFile
logFile,
}
}

Expand All @@ -90,12 +90,12 @@ export class LoggingHandler {
return winston.format.combine(
winston.format(info => {
info.level = info.level.toUpperCase()
return info;
return info
})(),
winston.format.colorize(),
winston.format.printf((info) => {
return `${DateTime.utc().toISO()} ${info.level} ${info.label} ${info.message}`;
}),
winston.format.printf(info => {
return `${DateTime.utc().toISO()} ${info.level} ${info.label} ${info.message}`
})
)
}

Expand All @@ -119,9 +119,11 @@ export class LoggingHandler {
transports.push(new winston.transports.Console())
break
case LogTransportType.CONSOLE_ELECTRON:
transports.push(new ConsoleForElectron({
prefix: ''
}))
transports.push(
new ConsoleForElectron({
prefix: '',
})
)
break
case LogTransportType.FILE:
transports.push(new winston.transports.File({ filename: config.logFile }))
Expand All @@ -139,11 +141,11 @@ export class LoggingHandler {
const tailableFileName = fileName || DEFAULT_LOG_FILE
if (process.env.NODE_ENV === 'development') {
consoleFunction(`${DateTime.utc().toISO()} DEVELOPMENT: tailing log file ${tailableFileName}`)
const tail = new Tail(tailableFileName);
tail.on("line", function(data: any) {
consoleFunction(data);
});
const tail = new Tail(tailableFileName)

tail.on('line', function (data: any) {
consoleFunction(data)
})
} else {
consoleFunction(`${DateTime.utc().toISO()} Not running in development, not tailing log file ${tailableFileName}`)
}
Expand Down
20 changes: 10 additions & 10 deletions packages/logger/src/types.ts
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
import { LogLevel, LogTransportType } from "./enums"
import { LogLevel, LogTransportType } from './enums'

export interface LoggingHandlerConfig {
packageName: string
defaultLogTransportTypes?: LogTransportType[]
defaultLogLevel?: LogLevel
defaultLogFile?: string
packageName: string
defaultLogTransportTypes?: LogTransportType[]
defaultLogLevel?: LogLevel
defaultLogFile?: string
}

export interface GenerateLoggerConfig {
moduleNames: string[]
logLevel?: LogLevel
transports?: LogTransportType[]
logFile?: string
moduleNames: string[]
logLevel?: LogLevel
transports?: LogTransportType[]
logFile?: string
}

export type TailLoggerFunction = (...args: any[]) => void
export type TailLoggerFunction = (...args: any[]) => void
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,9 @@ export const isJoiningCompleted = createSelector(
areChannelsLoaded,
areCertificatesLoaded,
(isCommunity, areMessages, areChannels, areCertificates) => {
LOGGER.debug(`Checking if joining is complete with info: ${JSON.stringify({ isCommunity, areMessages, areChannels, areCertificates })}`)
LOGGER.debug(
`Checking if joining is complete with info: ${JSON.stringify({ isCommunity, areMessages, areChannels, areCertificates })}`
)
return isCommunity && areMessages && areChannels && areCertificates
}
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,11 @@ import { communitiesActions } from '../communities.slice'
import { identitySelectors } from '../../identity/identity.selectors'
import { LoggerModuleName, loggingHandler } from 'packages/state-manager/src/utils/logger'

const LOGGER = loggingHandler.initLogger([LoggerModuleName.COMMUNITIES, LoggerModuleName.SAGA, 'updateCommunityMetadata'])
const LOGGER = loggingHandler.initLogger([
LoggerModuleName.COMMUNITIES,
LoggerModuleName.SAGA,
'updateCommunityMetadata',
])

export function* sendCommunityMetadataSaga(
socket: Socket,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ export function* autoDownloadFilesSaga(
): Generator {
const identity = yield* select(identitySelectors.currentIdentity)
if (!identity) {
LOGGER .error('Could not autodownload files, no identity')
LOGGER.error('Could not autodownload files, no identity')
return
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,9 @@ export function* checkForMissingFilesSaga(
const community = yield* select(communitiesSelectors.currentCommunity)

if (community?.id !== action.payload) {
LOGGER.warn(`Community ID on payload (${action.payload}) was not that same as the current community (${community?.id})`)
LOGGER.warn(
`Community ID on payload (${action.payload}) was not that same as the current community (${community?.id})`
)
return
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,9 @@ export function* addMessagesSaga(
// Proceed only for messages from current channel
const currentChannelId = yield* select(publicChannelsSelectors.currentChannelId)
if (incomingMessage.channelId !== currentChannelId) {
LOGGER.warn(`Channel ID on message (${incomingMessage.channelId}) did not match current channel ID (${currentChannelId})`)
LOGGER.warn(
`Channel ID on message (${incomingMessage.channelId}) did not match current channel ID (${currentChannelId})`
)
return
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,11 @@ import { communitiesSelectors } from '../../communities/communities.selectors'
import { publicChannelsSelectors } from '../publicChannels.selectors'
import { type PublicChannelStorage } from '@quiet/types'

const LOGGER = loggingHandler.initLogger([LoggerModuleName.PUBLIC_CHANNELS, LoggerModuleName.SAGA, 'channelDeletionResponse'])
const LOGGER = loggingHandler.initLogger([
LoggerModuleName.PUBLIC_CHANNELS,
LoggerModuleName.SAGA,
'channelDeletionResponse',
])

export function* channelDeletionResponseSaga(
action: PayloadAction<ReturnType<typeof publicChannelsActions.channelDeletionResponse>['payload']>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,11 @@ import { communitiesSelectors } from '../../communities/communities.selectors'
import { LoggerModuleName, loggingHandler } from 'packages/state-manager/src/utils/logger'
import { type PublicChannel } from '@quiet/types'

const LOGGER = loggingHandler.initLogger([LoggerModuleName.PUBLIC_CHANNELS, LoggerModuleName.SAGA, 'channelsReplicated'])
const LOGGER = loggingHandler.initLogger([
LoggerModuleName.PUBLIC_CHANNELS,
LoggerModuleName.SAGA,
'channelsReplicated',
])

export function* channelsReplicatedSaga(
action: PayloadAction<ReturnType<typeof publicChannelsActions.channelsReplicated>['payload']>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,11 @@ import { LoggerModuleName, loggingHandler } from 'packages/state-manager/src/uti
import { generateChannelId } from '@quiet/common'
import { type PublicChannel } from '@quiet/types'

const LOGGER = loggingHandler.initLogger([LoggerModuleName.PUBLIC_CHANNELS, LoggerModuleName.SAGA, 'createGeneralChannel'])
const LOGGER = loggingHandler.initLogger([
LoggerModuleName.PUBLIC_CHANNELS,
LoggerModuleName.SAGA,
'createGeneralChannel',
])

export function* createGeneralChannelSaga(): Generator {
const identity = yield* select(identitySelectors.currentIdentity)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,11 @@ import { identitySelectors } from '../../identity/identity.selectors'
import { generalChannelDeletionMessage, createdChannelMessage } from '@quiet/common'
import { loggingHandler, LoggerModuleName } from '../../../utils/logger'

const LOGGER = loggingHandler.initLogger([LoggerModuleName.PUBLIC_CHANNELS, LoggerModuleName.SAGA, 'sendInitialChannelMessage'])
const LOGGER = loggingHandler.initLogger([
LoggerModuleName.PUBLIC_CHANNELS,
LoggerModuleName.SAGA,
'sendInitialChannelMessage',
])

export function* sendInitialChannelMessageSaga(
action: PayloadAction<ReturnType<typeof publicChannelsActions.sendInitialChannelMessage>['payload']>
Expand All @@ -20,7 +24,7 @@ export function* sendInitialChannelMessageSaga(
LOGGER.warn(`No general channel found, skipping sending initial channel message`)
return
}

const isGeneral = channelId === generalChannel.id

const pendingGeneralChannelRecreation = yield* select(publicChannelsSelectors.pendingGeneralChannelRecreation)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,11 @@ import { identityActions } from '../../identity/identity.slice'
import { userJoinedMessage } from '@quiet/common'
import { loggingHandler, LoggerModuleName } from '../../../utils/logger'

const LOGGER = loggingHandler.initLogger([LoggerModuleName.PUBLIC_CHANNELS, LoggerModuleName.SAGA, 'sendIntroductionMessage'])
const LOGGER = loggingHandler.initLogger([
LoggerModuleName.PUBLIC_CHANNELS,
LoggerModuleName.SAGA,
'sendIntroductionMessage',
])

export function* sendIntroductionMessageSaga(): Generator {
LOGGER.info(`Sending introduction message`)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,12 @@ import { LoggerModuleName, loggingHandler } from 'packages/state-manager/src/uti
import { usersActions } from '../users.slice'
import { type Socket, applyEmitParams } from '../../../types'

const LOGGER = loggingHandler.initLogger([LoggerModuleName.USERS, LoggerModuleName.USER_PROFILES, LoggerModuleName.SAGA, 'saveUserProfile'])
const LOGGER = loggingHandler.initLogger([
LoggerModuleName.USERS,
LoggerModuleName.USER_PROFILES,
LoggerModuleName.SAGA,
'saveUserProfile',
])

export function* saveUserProfileSaga(socket: Socket, action: PayloadAction<{ photo?: File }>): Generator {
const identity = yield* select(identitySelectors.currentIdentity)
Expand Down
8 changes: 3 additions & 5 deletions packages/state-manager/src/utils/logger.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,12 @@ export enum LoggerModuleName {
ADAPTER = 'adapter',
SLICE = 'slice',
TRANSFORM = 'transform',
MASTER = 'master'
MASTER = 'master',
}

const PACKAGE_NAME = 'state-manager'
export const loggingHandler = new LoggingHandler({
packageName: PACKAGE_NAME,
defaultLogLevel: LogLevel.INFO,
defaultLogTransportTypes: [
LogTransportType.FILE
]
})
defaultLogTransportTypes: [LogTransportType.FILE],
})
1 change: 0 additions & 1 deletion packages/state-manager/src/utils/tests/helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import { arrayBufferToString } from 'pvutils'
import { config } from '../../sagas/users/const/certFieldTypes'
import { type PeerId } from '@quiet/types'


const notBeforeDate = new Date(Date.UTC(2010, 11, 28, 10, 10, 10))
const notAfterDate = new Date(Date.UTC(2030, 11, 28, 10, 10, 10))

Expand Down

0 comments on commit 72be94a

Please sign in to comment.