Skip to content

Commit 1dac4c3

Browse files
committed
Completely remove log4js from the server package (#4)
1 parent 8a95c09 commit 1dac4c3

File tree

13 files changed

+38
-106
lines changed

13 files changed

+38
-106
lines changed

packages/server/package.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,6 @@
4545
"@types/yargs": "^17.0.8",
4646
"cardinal": "^2.1.1",
4747
"jest": "^26.0.1",
48-
"log4js": "^6.2.1",
4948
"mysql2": "^2.3.0",
5049
"node-ssh-forward": "^0.6.3",
5150
"pg": "^8.9.0",

packages/server/src/SettingStore.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
import * as fs from 'fs'
22
import * as path from 'path'
33
import EventEmitter from 'events'
4-
import log4js from 'log4js'
4+
import { stubLogger } from './logger'
55

6-
const logger = log4js.getLogger()
6+
const logger = stubLogger()
77

88
export type SSHConfig = {
99
remoteHost: string

packages/server/src/cache.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
import { Diagnostic as SQLintDiagnostic } from 'sqlint'
2-
import log4js from 'log4js'
32
import { Diagnostic, Range } from 'vscode-languageserver'
3+
import { stubLogger } from './logger'
44

5-
const logger = log4js.getLogger()
5+
const logger = stubLogger()
66

77
export type LintCache = { lint: SQLintDiagnostic; diagnostic: Diagnostic }
88
class Cache {

packages/server/src/complete/AstUtils.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,11 @@ import {
44
SelectStatement,
55
NodeRange,
66
} from '@joe-re/sql-parser'
7-
import log4js from 'log4js'
87
import { Table } from '../database_libs/AbstractClient'
8+
import { stubLogger } from '../logger'
99
import { Pos } from './complete'
1010

11-
const logger = log4js.getLogger()
11+
const logger = stubLogger()
1212

1313
function isNotEmpty<T>(value: T | null | undefined): value is T {
1414
return value === null || value === undefined ? false : true

packages/server/src/complete/complete.ts

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ import {
1414
} from '@joe-re/sql-parser'
1515
import { CompletionItem } from 'vscode-languageserver-types'
1616
import { Schema, Table } from '../database_libs/AbstractClient'
17+
import { stubLogger } from '../logger'
1718
import { getRidOfAfterPosString } from './StringUtils'
1819
import { getLastToken } from './utils/getLastToken'
1920
import {
@@ -40,15 +41,7 @@ import { ICONS, toCompletionItemForKeyword } from './CompletionItemUtils'
4041

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

43-
// stubbing logger to make the lib work in browser
44-
const logger = {
45-
isDebugEnabled: function () {
46-
return false
47-
},
48-
debug: function (_: unknown) {
49-
return undefined
50-
},
51-
}
44+
const logger = stubLogger()
5245

5346
function getFromNodesFromClause(sql: string): FromClauseParserResult | null {
5447
try {

packages/server/src/createConnection.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,10 @@ import {
66
IPCMessageReader,
77
IPCMessageWriter,
88
} from 'vscode-jsonrpc/lib/node/main'
9-
import log4js from 'log4js'
109
import { ConnectionMethod } from './createServer'
11-
const logger = log4js.getLogger()
10+
import { stubLogger } from './logger'
11+
12+
const logger = stubLogger()
1213

1314
export default function createConnection(method: ConnectionMethod): Connection {
1415
logger.debug(`createConnection: method {${method}}`)

packages/server/src/createDiagnostics.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
import { parse, ParseError } from '@joe-re/sql-parser'
2-
import log4js from 'log4js'
32
import { PublishDiagnosticsParams, Diagnostic } from 'vscode-languageserver'
43
import { DiagnosticSeverity } from 'vscode-languageserver-types'
54
import { lint, ErrorLevel, LintResult, RawConfig } from 'sqlint'
65
import cache, { LintCache } from './cache'
6+
import { stubLogger } from './logger'
77

8-
const logger = log4js.getLogger()
8+
const logger = stubLogger()
99

1010
function doLint(
1111
uri: string,

packages/server/src/createServer.ts

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@ import {
1818
CodeActionKind,
1919
} from 'vscode-languageserver-types'
2020
import { lint, LintResult } from 'sqlint'
21-
import log4js from 'log4js'
2221
import { RawConfig } from 'sqlint'
2322
import cache from './cache'
2423
import { complete } from './complete'
@@ -27,19 +26,15 @@ import createConnection from './createConnection'
2726
import SettingStore, { Connection as SettingConnection } from './SettingStore'
2827
import { Schema } from './database_libs/AbstractClient'
2928
import getDatabaseClient from './database_libs/getDatabaseClient'
30-
import initializeLogging from './initializeLogging'
3129
import { RequireSqlite3Error } from './database_libs/Sqlite3Client'
30+
import { stubLogger } from './logger'
3231

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

3534
const TRIGGER_CHARATER = '.'
3635

37-
export function createServerWithConnection(
38-
connection: Connection,
39-
debug = false
40-
) {
41-
initializeLogging(debug)
42-
const logger = log4js.getLogger()
36+
export function createServerWithConnection(connection: Connection) {
37+
const logger = stubLogger()
4338
const documents = new TextDocuments(TextDocument)
4439
documents.listen(connection)
4540
let schema: Schema = { tables: [], functions: [] }
@@ -396,5 +391,5 @@ export function createServer(
396391
params: { method?: ConnectionMethod; debug?: boolean } = {}
397392
) {
398393
const connection: Connection = createConnection(params.method ?? 'node-ipc')
399-
return createServerWithConnection(connection, params.debug)
394+
return createServerWithConnection(connection)
400395
}

packages/server/src/database_libs/AbstractClient.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
import { readFileSync } from 'fs'
2-
import log4js from 'log4js'
32
import { SSHConnection } from 'node-ssh-forward'
43
import { Connection } from '../SettingStore'
4+
import { stubLogger } from '../logger'
55

6-
const logger = log4js.getLogger()
6+
const logger = stubLogger()
77

88
export type RawField = {
99
field: string

packages/server/src/database_libs/Sqlite3Client.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
import { sqlite3 as SQLite3, Database } from 'sqlite3'
2-
import log4js from 'log4js'
32
import { Connection } from '../SettingStore'
3+
import { stubLogger } from '../logger'
44
import AbstractClient, { RawField } from './AbstractClient'
55

6-
const logger = log4js.getLogger()
6+
const logger = stubLogger()
77

88
export class RequireSqlite3Error extends Error {
99
constructor(message: string) {

packages/server/src/initializeLogging.ts

Lines changed: 0 additions & 29 deletions
This file was deleted.

packages/server/src/logger.ts

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
/* stubbing logger to make the lib work in browser */
2+
export function stubLogger() {
3+
return {
4+
isDebugEnabled: function () {
5+
return false
6+
},
7+
debug: function (..._args: unknown[]) {
8+
return undefined
9+
},
10+
info: function (..._args: unknown[]) {
11+
return undefined
12+
},
13+
error: function (..._args: unknown[]) {
14+
return undefined
15+
},
16+
}
17+
}

yarn.lock

Lines changed: 0 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -2973,11 +2973,6 @@ data-urls@^2.0.0:
29732973
whatwg-mimetype "^2.3.0"
29742974
whatwg-url "^8.0.0"
29752975

2976-
date-format@^4.0.3:
2977-
version "4.0.3"
2978-
resolved "https://registry.yarnpkg.com/date-format/-/date-format-4.0.3.tgz#f63de5dc08dc02efd8ef32bf2a6918e486f35873"
2979-
integrity sha512-7P3FyqDcfeznLZp2b+OMitV9Sz2lUnsT87WaTat9nVwqsBkTzPG3lPLNwW3en6F4pHUiWzr6vb8CLhjdK9bcxQ==
2980-
29812976
dateformat@^3.0.0:
29822977
version "3.0.3"
29832978
resolved "https://registry.yarnpkg.com/dateformat/-/dateformat-3.0.3.tgz#a6e37499a4d9a9cf85ef5872044d62901c9889ae"
@@ -4188,11 +4183,6 @@ flatted@^3.1.0:
41884183
resolved "https://registry.yarnpkg.com/flatted/-/flatted-3.2.5.tgz#76c8584f4fc843db64702a6bd04ab7a8bd666da3"
41894184
integrity sha512-WIWGi2L3DyTUvUrwRKgGi9TwxQMUEqPOPQBVi71R96jZXJdFskXEmf54BoZaS1kknGODoIGASGEzBUYdyMCBJg==
41904185

4191-
flatted@^3.2.4:
4192-
version "3.2.4"
4193-
resolved "https://registry.yarnpkg.com/flatted/-/flatted-3.2.4.tgz#28d9969ea90661b5134259f312ab6aa7929ac5e2"
4194-
integrity sha512-8/sOawo8tJ4QOBX8YlQBMxL8+RLZfxMQOif9o0KUKTNTjMYElWPE0r/m5VNFxTRd0NSw8qSy8dajrwX4RYI1Hw==
4195-
41964186
follow-redirects@^1.14.0:
41974187
version "1.14.8"
41984188
resolved "https://registry.yarnpkg.com/follow-redirects/-/follow-redirects-1.14.8.tgz#016996fb9a11a100566398b1c6839337d7bfa8fc"
@@ -4258,15 +4248,6 @@ [email protected], fs-extra@^9.1.0:
42584248
jsonfile "^6.0.1"
42594249
universalify "^2.0.0"
42604250

4261-
fs-extra@^10.0.0:
4262-
version "10.0.0"
4263-
resolved "https://registry.yarnpkg.com/fs-extra/-/fs-extra-10.0.0.tgz#9ff61b655dde53fb34a82df84bb214ce802e17c1"
4264-
integrity sha512-C5owb14u9eJwizKGdchcDUQeFtlSHHthBk8pbX9Vc1PFZrLombudjDnNns88aYslCyF6IY5SUw3Roz6xShcEIQ==
4265-
dependencies:
4266-
graceful-fs "^4.2.0"
4267-
jsonfile "^6.0.1"
4268-
universalify "^2.0.0"
4269-
42704251
fs-extra@^11.1.0:
42714252
version "11.1.0"
42724253
resolved "https://registry.yarnpkg.com/fs-extra/-/fs-extra-11.1.0.tgz#5784b102104433bb0e090f48bfc4a30742c357ed"
@@ -6165,17 +6146,6 @@ log-symbols@^4.1.0:
61656146
chalk "^4.1.0"
61666147
is-unicode-supported "^0.1.0"
61676148

6168-
log4js@^6.2.1:
6169-
version "6.4.0"
6170-
resolved "https://registry.yarnpkg.com/log4js/-/log4js-6.4.0.tgz#3f63ccfc8033c83cd617a4d2d50e48be5944eae9"
6171-
integrity sha512-ysc/XUecZJuN8NoKOssk3V0cQ29xY4fra6fnigZa5VwxFsCsvdqsdnEuAxNN89LlHpbE4KUD3zGcn+kFqonSVQ==
6172-
dependencies:
6173-
date-format "^4.0.3"
6174-
debug "^4.3.3"
6175-
flatted "^3.2.4"
6176-
rfdc "^1.3.0"
6177-
streamroller "^3.0.2"
6178-
61796149
long@^4.0.0:
61806150
version "4.0.0"
61816151
resolved "https://registry.yarnpkg.com/long/-/long-4.0.0.tgz#9a7b71cfb7d361a194ea555241c92f7468d5bf28"
@@ -8143,11 +8113,6 @@ reusify@^1.0.4:
81438113
resolved "https://registry.yarnpkg.com/reusify/-/reusify-1.0.4.tgz#90da382b1e126efc02146e90845a88db12925d76"
81448114
integrity sha512-U9nH88a3fc/ekCF1l0/UP1IosiuIjyTh7hBvXVMHYgVcfGvt897Xguj2UOLDeI5BG2m7/uwyaLVT6fbtCwTyzw==
81458115

8146-
rfdc@^1.3.0:
8147-
version "1.3.0"
8148-
resolved "https://registry.yarnpkg.com/rfdc/-/rfdc-1.3.0.tgz#d0b7c441ab2720d05dc4cf26e01c89631d9da08b"
8149-
integrity sha512-V2hovdzFbOi77/WajaSMXk2OLm+xNIeQdMMuB7icj7bk6zi2F8GGAxigcnDFpJHbNyNcgyJDiP+8nOrY5cZGrA==
8150-
81518116
rimraf@2, rimraf@^2.6.1:
81528117
version "2.7.1"
81538118
resolved "https://registry.yarnpkg.com/rimraf/-/rimraf-2.7.1.tgz#35797f13a7fdadc566142c29d4f07ccad483e3ec"
@@ -8729,15 +8694,6 @@ stream-shift@^1.0.0:
87298694
resolved "https://registry.yarnpkg.com/stream-shift/-/stream-shift-1.0.1.tgz#d7088281559ab2778424279b0877da3c392d5a3d"
87308695
integrity sha512-AiisoFqQ0vbGcZgQPY1cdP2I76glaVA/RauYR4G4thNFgkTqr90yXTo4LYX60Jl+sIlPNHHdGSwo01AvbKUSVQ==
87318696

8732-
streamroller@^3.0.2:
8733-
version "3.0.2"
8734-
resolved "https://registry.yarnpkg.com/streamroller/-/streamroller-3.0.2.tgz#30418d0eee3d6c93ec897f892ed098e3a81e68b7"
8735-
integrity sha512-ur6y5S5dopOaRXBuRIZ1u6GC5bcEXHRZKgfBjfCglMhmIf+roVCECjvkEYzNQOXIN2/JPnkMPW/8B3CZoKaEPA==
8736-
dependencies:
8737-
date-format "^4.0.3"
8738-
debug "^4.1.1"
8739-
fs-extra "^10.0.0"
8740-
87418697
streamsearch@~0.1.2:
87428698
version "0.1.2"
87438699
resolved "https://registry.yarnpkg.com/streamsearch/-/streamsearch-0.1.2.tgz#808b9d0e56fc273d809ba57338e929919a1a9f1a"

0 commit comments

Comments
 (0)