Skip to content

Completely remove log4js from the server package #4

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Mar 23, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion packages/server/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,6 @@
"@types/yargs": "^17.0.8",
"cardinal": "^2.1.1",
"jest": "^26.0.1",
"log4js": "^6.2.1",
"mysql2": "^2.3.0",
"node-ssh-forward": "^0.6.3",
"pg": "^7.4.3",
Expand Down
4 changes: 2 additions & 2 deletions packages/server/src/SettingStore.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import * as fs from 'fs'
import EventEmitter from 'events'
import log4js from 'log4js'
import { stubLogger } from './logger'

const logger = log4js.getLogger()
const logger = stubLogger()

export type SSHConfig = {
remoteHost: string
Expand Down
4 changes: 2 additions & 2 deletions packages/server/src/cache.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { Diagnostic as SQLintDiagnostic } from 'sqlint'
import log4js from 'log4js'
import { Diagnostic, Range } from 'vscode-languageserver'
import { stubLogger } from './logger'

const logger = log4js.getLogger()
const logger = stubLogger()

export type LintCache = { lint: SQLintDiagnostic; diagnostic: Diagnostic }
class Cache {
Expand Down
4 changes: 2 additions & 2 deletions packages/server/src/complete/AstUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,11 @@ import {
SelectStatement,
NodeRange,
} from '@joe-re/sql-parser'
import log4js from 'log4js'
import { Table } from '../database_libs/AbstractClient'
import { stubLogger } from '../logger'
import { Pos } from './complete'

const logger = log4js.getLogger()
const logger = stubLogger()

function isNotEmpty<T>(value: T | null | undefined): value is T {
return value === null || value === undefined ? false : true
Expand Down
11 changes: 2 additions & 9 deletions packages/server/src/complete/complete.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import {
} from '@joe-re/sql-parser'
import { CompletionItem } from 'vscode-languageserver-types'
import { Schema, Table } from '../database_libs/AbstractClient'
import { stubLogger } from '../logger'
import { getRidOfAfterPosString } from './StringUtils'
import { getLastToken } from './utils/getLastToken'
import {
Expand All @@ -39,15 +40,7 @@ import { ICONS, toCompletionItemForKeyword } from './CompletionItemUtils'

export type Pos = { line: number; column: number }

// stubbing logger to make the lib work in browser
const logger = {
isDebugEnabled: function () {
return false
},
debug: function (_: unknown) {
return undefined
},
}
const logger = stubLogger()

function getFromNodesFromClause(sql: string): FromClauseParserResult | null {
try {
Expand Down
5 changes: 3 additions & 2 deletions packages/server/src/createConnection.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,10 @@ import {
IPCMessageReader,
IPCMessageWriter,
} from 'vscode-jsonrpc/lib/node/main'
import log4js from 'log4js'
import { ConnectionMethod } from './createServer'
const logger = log4js.getLogger()
import { stubLogger } from './logger'

const logger = stubLogger()

export default function createConnection(method: ConnectionMethod): Connection {
logger.debug(`createConnection: method {${method}}`)
Expand Down
4 changes: 2 additions & 2 deletions packages/server/src/createDiagnostics.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import { parse, ParseError } from '@joe-re/sql-parser'
import log4js from 'log4js'
import { PublishDiagnosticsParams, Diagnostic } from 'vscode-languageserver'
import { DiagnosticSeverity } from 'vscode-languageserver-types'
import { lint, ErrorLevel, LintResult, RawConfig } from 'sqlint'
import cache, { LintCache } from './cache'
import { stubLogger } from './logger'

const logger = log4js.getLogger()
const logger = stubLogger()

function doLint(
uri: string,
Expand Down
13 changes: 4 additions & 9 deletions packages/server/src/createServer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ import {
CodeActionKind,
} from 'vscode-languageserver-types'
import { lint, LintResult } from 'sqlint'
import log4js from 'log4js'
import { RawConfig } from 'sqlint'
import cache from './cache'
import { complete } from './complete'
Expand All @@ -27,19 +26,15 @@ import createConnection from './createConnection'
import SettingStore, { Connection as SettingConnection } from './SettingStore'
import { Schema } from './database_libs/AbstractClient'
import getDatabaseClient from './database_libs/getDatabaseClient'
import initializeLogging from './initializeLogging'
import { RequireSqlite3Error } from './database_libs/Sqlite3Client'
import { stubLogger } from './logger'

export type ConnectionMethod = 'node-ipc' | 'stdio'

const TRIGGER_CHARATER = '.'

export function createServerWithConnection(
connection: Connection,
debug = false
) {
initializeLogging(debug)
const logger = log4js.getLogger()
export function createServerWithConnection(connection: Connection) {
const logger = stubLogger()
const documents = new TextDocuments(TextDocument)
documents.listen(connection)
let schema: Schema = { tables: [], functions: [] }
Expand Down Expand Up @@ -395,5 +390,5 @@ export function createServer(
params: { method?: ConnectionMethod; debug?: boolean } = {}
) {
const connection: Connection = createConnection(params.method ?? 'node-ipc')
return createServerWithConnection(connection, params.debug)
return createServerWithConnection(connection)
}
4 changes: 2 additions & 2 deletions packages/server/src/database_libs/AbstractClient.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import { readFileSync } from 'fs'
import log4js from 'log4js'
import { SSHConnection } from 'node-ssh-forward'
import { Connection } from '../SettingStore'
import { stubLogger } from '../logger'

const logger = log4js.getLogger()
const logger = stubLogger()

export type RawField = {
field: string
Expand Down
4 changes: 2 additions & 2 deletions packages/server/src/database_libs/Sqlite3Client.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import { sqlite3 as SQLite3, Database } from 'sqlite3'
import log4js from 'log4js'
import { Connection } from '../SettingStore'
import { stubLogger } from '../logger'
import AbstractClient, { RawField } from './AbstractClient'

const logger = log4js.getLogger()
const logger = stubLogger()

export class RequireSqlite3Error extends Error {
constructor(message: string) {
Expand Down
29 changes: 0 additions & 29 deletions packages/server/src/initializeLogging.ts

This file was deleted.

17 changes: 17 additions & 0 deletions packages/server/src/logger.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
/* stubbing logger to make the lib work in browser */
export function stubLogger() {
return {
isDebugEnabled: function () {
return false
},
debug: function (..._args: unknown[]) {
return undefined
},
info: function (..._args: unknown[]) {
return undefined
},
error: function (..._args: unknown[]) {
return undefined
},
}
}
44 changes: 0 additions & 44 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -2954,11 +2954,6 @@ data-urls@^2.0.0:
whatwg-mimetype "^2.3.0"
whatwg-url "^8.0.0"

date-format@^4.0.3:
version "4.0.3"
resolved "https://registry.yarnpkg.com/date-format/-/date-format-4.0.3.tgz#f63de5dc08dc02efd8ef32bf2a6918e486f35873"
integrity sha512-7P3FyqDcfeznLZp2b+OMitV9Sz2lUnsT87WaTat9nVwqsBkTzPG3lPLNwW3en6F4pHUiWzr6vb8CLhjdK9bcxQ==

dateformat@^3.0.0:
version "3.0.3"
resolved "https://registry.yarnpkg.com/dateformat/-/dateformat-3.0.3.tgz#a6e37499a4d9a9cf85ef5872044d62901c9889ae"
Expand Down Expand Up @@ -4198,11 +4193,6 @@ flatted@^3.1.0:
resolved "https://registry.yarnpkg.com/flatted/-/flatted-3.2.5.tgz#76c8584f4fc843db64702a6bd04ab7a8bd666da3"
integrity sha512-WIWGi2L3DyTUvUrwRKgGi9TwxQMUEqPOPQBVi71R96jZXJdFskXEmf54BoZaS1kknGODoIGASGEzBUYdyMCBJg==

flatted@^3.2.4:
version "3.2.4"
resolved "https://registry.yarnpkg.com/flatted/-/flatted-3.2.4.tgz#28d9969ea90661b5134259f312ab6aa7929ac5e2"
integrity sha512-8/sOawo8tJ4QOBX8YlQBMxL8+RLZfxMQOif9o0KUKTNTjMYElWPE0r/m5VNFxTRd0NSw8qSy8dajrwX4RYI1Hw==

follow-redirects@^1.14.0:
version "1.14.8"
resolved "https://registry.yarnpkg.com/follow-redirects/-/follow-redirects-1.14.8.tgz#016996fb9a11a100566398b1c6839337d7bfa8fc"
Expand Down Expand Up @@ -4268,15 +4258,6 @@ [email protected], fs-extra@^9.1.0:
jsonfile "^6.0.1"
universalify "^2.0.0"

fs-extra@^10.0.0:
version "10.0.0"
resolved "https://registry.yarnpkg.com/fs-extra/-/fs-extra-10.0.0.tgz#9ff61b655dde53fb34a82df84bb214ce802e17c1"
integrity sha512-C5owb14u9eJwizKGdchcDUQeFtlSHHthBk8pbX9Vc1PFZrLombudjDnNns88aYslCyF6IY5SUw3Roz6xShcEIQ==
dependencies:
graceful-fs "^4.2.0"
jsonfile "^6.0.1"
universalify "^2.0.0"

fs-extra@^11.1.0:
version "11.1.0"
resolved "https://registry.yarnpkg.com/fs-extra/-/fs-extra-11.1.0.tgz#5784b102104433bb0e090f48bfc4a30742c357ed"
Expand Down Expand Up @@ -6246,17 +6227,6 @@ log-symbols@^4.1.0:
chalk "^4.1.0"
is-unicode-supported "^0.1.0"

log4js@^6.2.1:
version "6.4.0"
resolved "https://registry.yarnpkg.com/log4js/-/log4js-6.4.0.tgz#3f63ccfc8033c83cd617a4d2d50e48be5944eae9"
integrity sha512-ysc/XUecZJuN8NoKOssk3V0cQ29xY4fra6fnigZa5VwxFsCsvdqsdnEuAxNN89LlHpbE4KUD3zGcn+kFqonSVQ==
dependencies:
date-format "^4.0.3"
debug "^4.3.3"
flatted "^3.2.4"
rfdc "^1.3.0"
streamroller "^3.0.2"

long@^4.0.0:
version "4.0.0"
resolved "https://registry.yarnpkg.com/long/-/long-4.0.0.tgz#9a7b71cfb7d361a194ea555241c92f7468d5bf28"
Expand Down Expand Up @@ -8275,11 +8245,6 @@ reusify@^1.0.4:
resolved "https://registry.yarnpkg.com/reusify/-/reusify-1.0.4.tgz#90da382b1e126efc02146e90845a88db12925d76"
integrity sha512-U9nH88a3fc/ekCF1l0/UP1IosiuIjyTh7hBvXVMHYgVcfGvt897Xguj2UOLDeI5BG2m7/uwyaLVT6fbtCwTyzw==

rfdc@^1.3.0:
version "1.3.0"
resolved "https://registry.yarnpkg.com/rfdc/-/rfdc-1.3.0.tgz#d0b7c441ab2720d05dc4cf26e01c89631d9da08b"
integrity sha512-V2hovdzFbOi77/WajaSMXk2OLm+xNIeQdMMuB7icj7bk6zi2F8GGAxigcnDFpJHbNyNcgyJDiP+8nOrY5cZGrA==

rimraf@2, rimraf@^2.6.1:
version "2.7.1"
resolved "https://registry.yarnpkg.com/rimraf/-/rimraf-2.7.1.tgz#35797f13a7fdadc566142c29d4f07ccad483e3ec"
Expand Down Expand Up @@ -8865,15 +8830,6 @@ stream-shift@^1.0.0:
resolved "https://registry.yarnpkg.com/stream-shift/-/stream-shift-1.0.1.tgz#d7088281559ab2778424279b0877da3c392d5a3d"
integrity sha512-AiisoFqQ0vbGcZgQPY1cdP2I76glaVA/RauYR4G4thNFgkTqr90yXTo4LYX60Jl+sIlPNHHdGSwo01AvbKUSVQ==

streamroller@^3.0.2:
version "3.0.2"
resolved "https://registry.yarnpkg.com/streamroller/-/streamroller-3.0.2.tgz#30418d0eee3d6c93ec897f892ed098e3a81e68b7"
integrity sha512-ur6y5S5dopOaRXBuRIZ1u6GC5bcEXHRZKgfBjfCglMhmIf+roVCECjvkEYzNQOXIN2/JPnkMPW/8B3CZoKaEPA==
dependencies:
date-format "^4.0.3"
debug "^4.1.1"
fs-extra "^10.0.0"

streamsearch@~0.1.2:
version "0.1.2"
resolved "https://registry.yarnpkg.com/streamsearch/-/streamsearch-0.1.2.tgz#808b9d0e56fc273d809ba57338e929919a1a9f1a"
Expand Down