Skip to content

Commit 79e6052

Browse files
authored
Completely remove log4js from the server package (#4)
1 parent d6af39b commit 79e6052

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
@@ -43,7 +43,6 @@
4343
"@types/yargs": "^17.0.8",
4444
"cardinal": "^2.1.1",
4545
"jest": "^26.0.1",
46-
"log4js": "^6.2.1",
4746
"mysql2": "^2.3.0",
4847
"node-ssh-forward": "^0.6.3",
4948
"pg": "^7.4.3",

packages/server/src/SettingStore.ts

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

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

77
export type SSHConfig = {
88
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
@@ -13,6 +13,7 @@ import {
1313
} from '@joe-re/sql-parser'
1414
import { CompletionItem } from 'vscode-languageserver-types'
1515
import { Schema, Table } from '../database_libs/AbstractClient'
16+
import { stubLogger } from '../logger'
1617
import { getRidOfAfterPosString } from './StringUtils'
1718
import { getLastToken } from './utils/getLastToken'
1819
import {
@@ -39,15 +40,7 @@ import { ICONS, toCompletionItemForKeyword } from './CompletionItemUtils'
3940

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

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

5245
function getFromNodesFromClause(sql: string): FromClauseParserResult | null {
5346
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: [] }
@@ -395,5 +390,5 @@ export function createServer(
395390
params: { method?: ConnectionMethod; debug?: boolean } = {}
396391
) {
397392
const connection: Connection = createConnection(params.method ?? 'node-ipc')
398-
return createServerWithConnection(connection, params.debug)
393+
return createServerWithConnection(connection)
399394
}

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
@@ -2954,11 +2954,6 @@ data-urls@^2.0.0:
29542954
whatwg-mimetype "^2.3.0"
29552955
whatwg-url "^8.0.0"
29562956

2957-
date-format@^4.0.3:
2958-
version "4.0.3"
2959-
resolved "https://registry.yarnpkg.com/date-format/-/date-format-4.0.3.tgz#f63de5dc08dc02efd8ef32bf2a6918e486f35873"
2960-
integrity sha512-7P3FyqDcfeznLZp2b+OMitV9Sz2lUnsT87WaTat9nVwqsBkTzPG3lPLNwW3en6F4pHUiWzr6vb8CLhjdK9bcxQ==
2961-
29622957
dateformat@^3.0.0:
29632958
version "3.0.3"
29642959
resolved "https://registry.yarnpkg.com/dateformat/-/dateformat-3.0.3.tgz#a6e37499a4d9a9cf85ef5872044d62901c9889ae"
@@ -4198,11 +4193,6 @@ flatted@^3.1.0:
41984193
resolved "https://registry.yarnpkg.com/flatted/-/flatted-3.2.5.tgz#76c8584f4fc843db64702a6bd04ab7a8bd666da3"
41994194
integrity sha512-WIWGi2L3DyTUvUrwRKgGi9TwxQMUEqPOPQBVi71R96jZXJdFskXEmf54BoZaS1kknGODoIGASGEzBUYdyMCBJg==
42004195

4201-
flatted@^3.2.4:
4202-
version "3.2.4"
4203-
resolved "https://registry.yarnpkg.com/flatted/-/flatted-3.2.4.tgz#28d9969ea90661b5134259f312ab6aa7929ac5e2"
4204-
integrity sha512-8/sOawo8tJ4QOBX8YlQBMxL8+RLZfxMQOif9o0KUKTNTjMYElWPE0r/m5VNFxTRd0NSw8qSy8dajrwX4RYI1Hw==
4205-
42064196
follow-redirects@^1.14.0:
42074197
version "1.14.8"
42084198
resolved "https://registry.yarnpkg.com/follow-redirects/-/follow-redirects-1.14.8.tgz#016996fb9a11a100566398b1c6839337d7bfa8fc"
@@ -4268,15 +4258,6 @@ [email protected], fs-extra@^9.1.0:
42684258
jsonfile "^6.0.1"
42694259
universalify "^2.0.0"
42704260

4271-
fs-extra@^10.0.0:
4272-
version "10.0.0"
4273-
resolved "https://registry.yarnpkg.com/fs-extra/-/fs-extra-10.0.0.tgz#9ff61b655dde53fb34a82df84bb214ce802e17c1"
4274-
integrity sha512-C5owb14u9eJwizKGdchcDUQeFtlSHHthBk8pbX9Vc1PFZrLombudjDnNns88aYslCyF6IY5SUw3Roz6xShcEIQ==
4275-
dependencies:
4276-
graceful-fs "^4.2.0"
4277-
jsonfile "^6.0.1"
4278-
universalify "^2.0.0"
4279-
42804261
fs-extra@^11.1.0:
42814262
version "11.1.0"
42824263
resolved "https://registry.yarnpkg.com/fs-extra/-/fs-extra-11.1.0.tgz#5784b102104433bb0e090f48bfc4a30742c357ed"
@@ -6246,17 +6227,6 @@ log-symbols@^4.1.0:
62466227
chalk "^4.1.0"
62476228
is-unicode-supported "^0.1.0"
62486229

6249-
log4js@^6.2.1:
6250-
version "6.4.0"
6251-
resolved "https://registry.yarnpkg.com/log4js/-/log4js-6.4.0.tgz#3f63ccfc8033c83cd617a4d2d50e48be5944eae9"
6252-
integrity sha512-ysc/XUecZJuN8NoKOssk3V0cQ29xY4fra6fnigZa5VwxFsCsvdqsdnEuAxNN89LlHpbE4KUD3zGcn+kFqonSVQ==
6253-
dependencies:
6254-
date-format "^4.0.3"
6255-
debug "^4.3.3"
6256-
flatted "^3.2.4"
6257-
rfdc "^1.3.0"
6258-
streamroller "^3.0.2"
6259-
62606230
long@^4.0.0:
62616231
version "4.0.0"
62626232
resolved "https://registry.yarnpkg.com/long/-/long-4.0.0.tgz#9a7b71cfb7d361a194ea555241c92f7468d5bf28"
@@ -8275,11 +8245,6 @@ reusify@^1.0.4:
82758245
resolved "https://registry.yarnpkg.com/reusify/-/reusify-1.0.4.tgz#90da382b1e126efc02146e90845a88db12925d76"
82768246
integrity sha512-U9nH88a3fc/ekCF1l0/UP1IosiuIjyTh7hBvXVMHYgVcfGvt897Xguj2UOLDeI5BG2m7/uwyaLVT6fbtCwTyzw==
82778247

8278-
rfdc@^1.3.0:
8279-
version "1.3.0"
8280-
resolved "https://registry.yarnpkg.com/rfdc/-/rfdc-1.3.0.tgz#d0b7c441ab2720d05dc4cf26e01c89631d9da08b"
8281-
integrity sha512-V2hovdzFbOi77/WajaSMXk2OLm+xNIeQdMMuB7icj7bk6zi2F8GGAxigcnDFpJHbNyNcgyJDiP+8nOrY5cZGrA==
8282-
82838248
rimraf@2, rimraf@^2.6.1:
82848249
version "2.7.1"
82858250
resolved "https://registry.yarnpkg.com/rimraf/-/rimraf-2.7.1.tgz#35797f13a7fdadc566142c29d4f07ccad483e3ec"
@@ -8865,15 +8830,6 @@ stream-shift@^1.0.0:
88658830
resolved "https://registry.yarnpkg.com/stream-shift/-/stream-shift-1.0.1.tgz#d7088281559ab2778424279b0877da3c392d5a3d"
88668831
integrity sha512-AiisoFqQ0vbGcZgQPY1cdP2I76glaVA/RauYR4G4thNFgkTqr90yXTo4LYX60Jl+sIlPNHHdGSwo01AvbKUSVQ==
88678832

8868-
streamroller@^3.0.2:
8869-
version "3.0.2"
8870-
resolved "https://registry.yarnpkg.com/streamroller/-/streamroller-3.0.2.tgz#30418d0eee3d6c93ec897f892ed098e3a81e68b7"
8871-
integrity sha512-ur6y5S5dopOaRXBuRIZ1u6GC5bcEXHRZKgfBjfCglMhmIf+roVCECjvkEYzNQOXIN2/JPnkMPW/8B3CZoKaEPA==
8872-
dependencies:
8873-
date-format "^4.0.3"
8874-
debug "^4.1.1"
8875-
fs-extra "^10.0.0"
8876-
88778833
streamsearch@~0.1.2:
88788834
version "0.1.2"
88798835
resolved "https://registry.yarnpkg.com/streamsearch/-/streamsearch-0.1.2.tgz#808b9d0e56fc273d809ba57338e929919a1a9f1a"

0 commit comments

Comments
 (0)