Skip to content

Commit

Permalink
Remove all references to the old logger
Browse files Browse the repository at this point in the history
  • Loading branch information
islathehut committed May 15, 2024
1 parent 7e08edb commit cd54893
Show file tree
Hide file tree
Showing 23 changed files with 244 additions and 247 deletions.
16 changes: 8 additions & 8 deletions packages/backend/src/nest/websocketOverTor/listener.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// import os from 'os'
// import { createServer } from 'it-ws/server'
// import logger from '../../logger'
// import { createLogger } from '../../logger'
// import { socketToMaConn } from './socket-to-conn.js'
// import { EventEmitter, CustomEvent } from './events'
// import type { Listener, ListenerEvents, CreateListenerOptions } from '@libp2p/interface-transport'
Expand All @@ -10,7 +10,7 @@
// import type { Connection } from '@libp2p/interface-connection'
// import type { Multiaddr } from '@multiformats/multiaddr'

// const log = logger('libp2p:websockets:listener')
// const logger = createLogger('libp2p:websockets:listener')

// // @ts-ignore
// class WebSocketListener extends EventEmitter<ListenerEvents> implements Listener {
Expand All @@ -33,7 +33,7 @@
// ...init,
// onConnection: (stream: DuplexWebSocket) => {
// const maConn = socketToMaConn(stream, this.toMultiaddr(stream.remoteAddress ?? '', stream.remotePort ?? 0))
// log('new inbound connection %s', maConn.remoteAddr)
// logger.info('new inbound connection %s', maConn.remoteAddr)

// this.connections.add(stream)

Expand All @@ -44,7 +44,7 @@
// try {
// void init.upgrader.upgradeInbound(maConn)
// .then((conn) => {
// log('inbound connection %s upgraded', maConn.remoteAddr)
// logger.info('inbound connection %s upgraded', maConn.remoteAddr)

// if (init?.handler != null) {
// init?.handler(conn)
Expand All @@ -55,16 +55,16 @@
// }))
// })
// .catch(async err => {
// log.error('inbound connection failed to upgrade', err)
// logger.error('inbound connection failed to upgrade', err)

// await maConn.close().catch(err => {
// log.error('inbound connection failed to close after upgrade failed', err)
// logger.error('inbound connection failed to close after upgrade failed', err)
// })
// })
// } catch (err) {
// log.error('inbound connection failed to upgrade', err)
// logger.error('inbound connection failed to upgrade', err)
// maConn.close().catch(err => {
// log.error('inbound connection failed to close after upgrade failed', err)
// logger.error('inbound connection failed to close after upgrade failed', err)
// })
// }
// }
Expand Down
22 changes: 11 additions & 11 deletions packages/common/src/invitationCode.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ import { InvitationData, InvitationDataV1, InvitationDataV2, InvitationDataVersi
import { QUIET_JOIN_PAGE } from './const'
import { createLibp2pAddress, isPSKcodeValid } from './libp2p'
// import { CID } from 'multiformats/cid' // Fixme: dependency issue
import Logger from './logger'
const logger = Logger('invite')
import { createLogger } from './logger'
const logger = createLogger('invite')

// V1 invitation code format (p2p without relay)
export const PSK_PARAM_KEY = 'k'
Expand Down Expand Up @@ -108,7 +108,7 @@ const parseDeepUrl = ({ url, expectedProtocol = `${DEEP_URL_SCHEME}:` }: ParseDe

if (!data) throw new Error(`Could not parse invitation code from deep url '${url}'`)

logger(`Invitation data '${data}' parsed`)
logger.info(`Invitation data '${data}' parsed`)
return data
}

Expand Down Expand Up @@ -138,18 +138,18 @@ export const p2pAddressesToPairs = (addresses: string[]): InvitationPair[] => {
try {
peerId = peerAddress.split('/p2p/')[1]
} catch (e) {
console.info(`Could not add peer address '${peerAddress}' to invitation url. Reason: ${e.message}`)
logger.error(`Could not add peer address '${peerAddress}' to invitation url.`, e)
continue
}
try {
onionAddress = peerAddress.split('/tcp/')[0].split('/dns4/')[1]
} catch (e) {
console.info(`Could not add peer address '${peerAddress}' to invitation url. Reason: ${e.message}`)
logger.error(`Could not add peer address '${peerAddress}' to invitation url.`, e)
continue
}

if (!peerId || !onionAddress) {
console.error(`No peerId or address in ${peerAddress}`)
logger.error(`No peerId or address in ${peerAddress}`)
continue
}
const rawAddress = onionAddress.endsWith('.onion') ? onionAddress.split('.')[0] : onionAddress
Expand Down Expand Up @@ -210,10 +210,10 @@ export const argvInvitationCode = (argv: string[]): InvitationData | null => {
let invitationData: InvitationData | null = null
for (const arg of argv) {
if (!arg.startsWith(DEEP_URL_SCHEME_WITH_SEPARATOR)) {
console.log('Not a deep url, not parsing', arg)
logger.warn('Not a deep url, not parsing', arg)
continue
}
logger('Parsing deep url', arg)
logger.info('Parsing deep url', arg)
invitationData = parseInvitationCodeDeepUrl(arg)
switch (invitationData.version) {
case InvitationDataVersion.v1:
Expand All @@ -230,11 +230,11 @@ export const argvInvitationCode = (argv: string[]): InvitationData | null => {
const peerDataValid = ({ peerId, onionAddress }: { peerId: string; onionAddress: string }): boolean => {
if (!peerId.match(PEER_ID_REGEX)) {
// TODO: test it more properly e.g with PeerId.createFromB58String(peerId.trim())
logger(`PeerId ${peerId} is not valid`)
logger.warn(`PeerId ${peerId} is not valid`)
return false
}
if (!onionAddress.trim().match(ONION_ADDRESS_REGEX)) {
logger(`Onion address ${onionAddress} is not valid`)
logger.warn(`Onion address ${onionAddress} is not valid`)
return false
}
return true
Expand All @@ -258,7 +258,7 @@ const validateUrlParams = (params: URLSearchParams, requiredParams: string[]) =>
}

const isParamValid = (param: string, value: string) => {
logger(`Validating param ${param} with value ${value}`)
logger.info(`Validating param ${param} with value ${value}`)
switch (param) {
case CID_PARAM_KEY:
// try {
Expand Down
8 changes: 2 additions & 6 deletions packages/common/src/logger.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,3 @@
import { logger } from '@quiet/logger'
import { createQuietLogger } from '@quiet/logger'

const createLogger = (name: string) => {
return logger('utils')(name)
}

export default createLogger
export const createLogger = createQuietLogger('utils')
4 changes: 2 additions & 2 deletions packages/e2e-tests/src/logger.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
import logger from '@quiet/logger'
import { createQuietLogger } from '@quiet/logger'

export default logger('e2e')
export const createLogger = createQuietLogger('e2e')
53 changes: 28 additions & 25 deletions packages/e2e-tests/src/selectors.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@ import { By, Key, type ThenableWebDriver, type WebElement, until } from 'seleniu
import { BuildSetup, sleep, type BuildSetupInit } from './utils'
import path from 'path'
import { BACK_ARROW_DATA_TESTID } from './enums'
import { createLogger } from './logger'

const logger = createLogger('selectors')

export class App {
thenableWebDriver?: ThenableWebDriver
Expand All @@ -24,7 +27,7 @@ export class App {
}

async open() {
console.log('opening the app', this.buildSetup.dataDir)
logger.info('opening the app', this.buildSetup.dataDir)
this.buildSetup.resetDriver()
await this.buildSetup.createChromeDriver()
this.isOpened = true
Expand All @@ -36,7 +39,7 @@ export class App {

async close(options?: { forceSaveState?: boolean }) {
if (!this.isOpened) return
console.log('Closing the app', this.buildSetup.dataDir)
logger.info('Closing the app', this.buildSetup.dataDir)
if (options?.forceSaveState) {
await this.saveState() // Selenium creates community and closes app so fast that redux state may not be saved properly
await this.waitForSavedState()
Expand All @@ -48,11 +51,11 @@ export class App {
await new Promise<void>(resolve => setTimeout(() => resolve(), 2000))
}
this.isOpened = false
console.log('App closed', this.buildSetup.dataDir)
logger.info('App closed', this.buildSetup.dataDir)
}

async cleanup(force: boolean = false) {
console.log(`Performing app cleanup`, this.buildSetup.dataDir)
logger.info(`Performing app cleanup`, this.buildSetup.dataDir)
if (this.isOpened) {
throw new Error(`App with dataDir ${this.buildSetup.dataDir} is still open, close before cleaning up!`)
}
Expand Down Expand Up @@ -171,7 +174,7 @@ export class UserProfileContextMenu {
500
)

console.log('clicking back button')
logger.info('clicking back button')
// await this.driver.executeScript('arguments[0].click();', button)
await button.click()
}
Expand Down Expand Up @@ -338,12 +341,12 @@ export class Channel {
}

async waitForUserMessage(username: string, messageContent: string) {
console.log(`Waiting for user "${username}" message "${messageContent}"`)
logger.info(`Waiting for user "${username}" message "${messageContent}"`)
return this.driver.wait(async () => {
const messages = await this.getUserMessages(username)
const hasMessage = messages.find(async msg => {
const messageText = await msg.getText()
console.log(`got message "${messageText}"`)
logger.info(`got message "${messageText}"`)
return messageText.includes(messageContent)
})
return hasMessage
Expand Down Expand Up @@ -393,7 +396,7 @@ export class Channel {
}

async waitForLabel(username: string, label: string) {
console.log(`Waiting for user's "${username}" label "${label}" label`)
logger.info(`Waiting for user's "${username}" label "${label}" label`)
await this.driver.wait(async () => {
const labels = await this.driver.findElements(By.xpath(`//*[contains(@data-testid, "userLabel-${username}")]`))
const properLabels = labels.filter(async labelElement => {
Expand All @@ -405,7 +408,7 @@ export class Channel {
}

async waitForLabelsNotPresent(username: string) {
console.log(`Waiting for user's "${username}" label to not be present`)
logger.info(`Waiting for user's "${username}" label to not be present`)
await this.driver.wait(async () => {
const labels = await this.driver.findElements(By.xpath(`//*[contains(@data-testid, "userLabel-${username}")]`))
return labels.length === 0
Expand Down Expand Up @@ -441,7 +444,7 @@ export class Sidebar {
}

async waitForChannelsNum(num: number) {
console.log(`Waiting for ${num} channels`)
logger.info(`Waiting for ${num} channels`)
return this.driver.wait(async () => {
const channels = await this.getChannelList()
return channels.length === num
Expand Down Expand Up @@ -483,32 +486,32 @@ export class UpdateModal {
}

get element() {
console.log('Waiting for update modal root element')
logger.info('Waiting for update modal root element')
return this.driver.wait(
until.elementLocated(By.xpath("//h3[text()='Software update']/ancestor::div[contains(@class,'MuiModal-root')]"))
)
}

async close() {
const updateModalRootElement = await this.element
console.log('Found update modal root element')
logger.info('Found update modal root element')
const closeButton = await updateModalRootElement.findElement(
By.xpath("//*[self::div[@data-testid='ModalActions']]/button")
)

try {
console.log('Before clicking update modal close button')
logger.info('Before clicking update modal close button')
await closeButton.click()
return
} catch (e) {
console.error('Error while clicking close button on update modal', e.message)
logger.error('Error while clicking close button on update modal', e)
}

try {
const log = await this.driver.executeScript('arguments[0].click();', closeButton)
console.log('executeScript', log)
logger.info('executeScript', log)
} catch (e) {
console.log('Probably clicked hidden close button on update modal')
logger.warn('Probably clicked hidden close button on update modal')
}
}
}
Expand Down Expand Up @@ -574,7 +577,7 @@ export class DebugModeModal {
private readonly driver: ThenableWebDriver
constructor(driver: ThenableWebDriver) {
this.driver = driver
console.log('Debug modal')
logger.info('Debug modal')
}

get element() {
Expand All @@ -589,25 +592,25 @@ export class DebugModeModal {
if (!process.env.TEST_MODE) return
let button
try {
console.log('Closing debug modal')
logger.info('Closing debug modal')
await this.element.isDisplayed()
console.log('Debug modal title is displayed')
logger.info('Debug modal title is displayed')
button = await this.button
console.log('Debug modal button is displayed')
logger.info('Debug modal button is displayed')
} catch (e) {
console.log('Debug modal might have been covered by "join community" modal', e.message)
logger.error('Debug modal might have been covered by "join community" modal', e)
return
}

await button.isDisplayed()
console.log('Button is displayed')
logger.info('Button is displayed')
await button.click()
console.log('Button click')
logger.info('Button click')
try {
const log = await this.driver.executeScript('arguments[0].click();', button)
console.log('executeScript', log)
logger.info('executeScript', log)
} catch (e) {
console.log('Probably clicked hidden close button on debug modal')
logger.warn('Probably clicked hidden close button on debug modal')
}
await new Promise<void>(resolve => setTimeout(() => resolve(), 2000))
}
Expand Down
17 changes: 10 additions & 7 deletions packages/e2e-tests/src/tests/backwardsCompatibility.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@ import {
Sidebar,
} from '../selectors'
import { BACKWARD_COMPATIBILITY_BASE_VERSION, BuildSetup, copyInstallerFile, downloadInstaller } from '../utils'
import { createLogger } from '../logger'

const logger = createLogger('backwardsCompatibility')

jest.setTimeout(1200000)
describe('Backwards Compatibility', () => {
Expand Down Expand Up @@ -55,10 +58,10 @@ describe('Backwards Compatibility', () => {
ownerAppOldVersion
.closeUpdateModalIfPresent()
.then(async () => {
console.log('Closed update modal')
logger.info('Closed update modal')
})
.catch(err => {
console.log('Could not close update modal', err)
logger.error('Could not close update modal', err)
})
})

Expand Down Expand Up @@ -142,21 +145,21 @@ describe('Backwards Compatibility', () => {
// ________________________________

it('Owner opens the app in new version', async () => {
console.log('New version', 1)
logger.info('New version', 1)
ownerAppNewVersion = new App({ dataDir })
await ownerAppNewVersion.open()
})

if (isAlpha) {
it('Owner closes debug modal if opened', async () => {
console.log('New version', 2)
logger.info('New version', 2)
const debugModal = new DebugModeModal(ownerAppNewVersion.driver)
await debugModal.close()
})
}

it('Owener sees general channel', async () => {
console.log('New version', 3)
logger.info('New version', 3)
generalChannel = new Channel(ownerAppNewVersion.driver, 'general')
const isGeneralChannel = await generalChannel.element.isDisplayed()
const generalChannelText = await generalChannel.element.getText()
Expand All @@ -165,7 +168,7 @@ describe('Backwards Compatibility', () => {
})

it('Confirm that the opened app is the latest version', async () => {
console.log('New version', 4)
logger.info('New version', 4)
await new Promise<void>(resolve => setTimeout(() => resolve(), 10000))
const settingsModal = await new Sidebar(ownerAppNewVersion.driver).openSettings()
const isSettingsModal = await settingsModal.element.isDisplayed()
Expand All @@ -177,7 +180,7 @@ describe('Backwards Compatibility', () => {
})

it('Check number of messages on second channel', async () => {
console.log('New version', 5)
logger.info('New version', 5)
await new Promise<void>(resolve => setTimeout(() => resolve(), 2000))
sidebar = new Sidebar(ownerAppNewVersion.driver)
await sidebar.switchChannel(newChannelName)
Expand Down
Loading

0 comments on commit cd54893

Please sign in to comment.