web-log-viewer 0.0.3 → 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +16 -14
- package/build/public/build/bundle.css +1 -1
- package/build/public/build/bundle.js +1 -1
- package/build/public/build/bundle.js.map +1 -1
- package/build/public/index.html +1 -0
- package/build/server.js +68 -29
- package/package.json +15 -3
- package/.prettierrc +0 -9
- package/app-console.js +0 -28
- package/nginx.log +0 -51462
- package/produce-log.sh +0 -3
- package/src/config.ts +0 -28
- package/src/defaultMessageParser.ts +0 -16
- package/src/log-index.ts +0 -44
- package/src/server.ts +0 -135
- package/src/stream-utils.ts +0 -28
- package/src/types.ts +0 -51
- package/svelte/.vscode/extensions.json +0 -3
- package/svelte/package-lock.json +0 -998
- package/svelte/package.json +0 -33
- package/svelte/public/favicon.png +0 -0
- package/svelte/public/global.css +0 -104
- package/svelte/public/index.html +0 -18
- package/svelte/rollup.config.js +0 -88
- package/svelte/src/App.svelte +0 -285
- package/svelte/src/LogMessageDetails.svelte +0 -166
- package/svelte/src/log-formatter.ts +0 -21
- package/svelte/src/log-store.ts +0 -209
- package/svelte/src/main.ts +0 -8
- package/svelte/src/types.ts +0 -51
- package/svelte/tsconfig.json +0 -6
- package/tsconfig.json +0 -71
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
const FORMATTER = 'jsl.formatter'
|
|
2
|
-
|
|
3
|
-
const DEFAULT_LOG_FORMATTER = `
|
|
4
|
-
({
|
|
5
|
-
'#': (l, seq) => seq,
|
|
6
|
-
message: l => JSON.stringify(l),
|
|
7
|
-
})`
|
|
8
|
-
|
|
9
|
-
const formatter = {
|
|
10
|
-
updateFormatter: (newFormatter: string) => {
|
|
11
|
-
localStorage.setItem(FORMATTER, newFormatter)
|
|
12
|
-
},
|
|
13
|
-
getFormatter: () => {
|
|
14
|
-
return localStorage.getItem(FORMATTER) || DEFAULT_LOG_FORMATTER
|
|
15
|
-
},
|
|
16
|
-
resetFormatter: () => {
|
|
17
|
-
localStorage.removeItem(FORMATTER)
|
|
18
|
-
},
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
export { formatter }
|
package/svelte/src/log-store.ts
DELETED
|
@@ -1,209 +0,0 @@
|
|
|
1
|
-
import memoizeOne from 'memoize-one'
|
|
2
|
-
import { writable } from 'svelte/store'
|
|
3
|
-
import { formatter } from './log-formatter'
|
|
4
|
-
import type {
|
|
5
|
-
ClientMessage,
|
|
6
|
-
FormattedMessage,
|
|
7
|
-
LogColumnFormatter,
|
|
8
|
-
LogFormatter,
|
|
9
|
-
LogMessage,
|
|
10
|
-
ServerMessage,
|
|
11
|
-
} from './types'
|
|
12
|
-
|
|
13
|
-
interface TailLogStore {
|
|
14
|
-
mode: 'tail'
|
|
15
|
-
count: number
|
|
16
|
-
filter: string
|
|
17
|
-
formatter: string
|
|
18
|
-
columns: string[]
|
|
19
|
-
window: FormattedMessage[]
|
|
20
|
-
latest: FormattedMessage[]
|
|
21
|
-
}
|
|
22
|
-
interface StaticLogStore {
|
|
23
|
-
mode: 'static'
|
|
24
|
-
offsetSeq: number
|
|
25
|
-
count: number
|
|
26
|
-
filter: string
|
|
27
|
-
formatter: string
|
|
28
|
-
columns: string[]
|
|
29
|
-
window: FormattedMessage[]
|
|
30
|
-
latest: FormattedMessage[]
|
|
31
|
-
}
|
|
32
|
-
/**
|
|
33
|
-
* A `LogStore` object contains all the state of the application.
|
|
34
|
-
* It can be saved (e.g., to **localStorage**) and later used to restore the app to a known state) */
|
|
35
|
-
type LogStore = TailLogStore | StaticLogStore
|
|
36
|
-
|
|
37
|
-
const LOG_WINDOW_SIZE = 100
|
|
38
|
-
const LATEST_LOG_WINDOW_SIZE = 2
|
|
39
|
-
|
|
40
|
-
function createLogStore(initialValue?: LogStore) {
|
|
41
|
-
// use default values, if needed
|
|
42
|
-
if (!initialValue) {
|
|
43
|
-
initialValue = {
|
|
44
|
-
mode: 'tail',
|
|
45
|
-
count: 0,
|
|
46
|
-
filter: '',
|
|
47
|
-
formatter: formatter.getFormatter(),
|
|
48
|
-
columns: [],
|
|
49
|
-
window: [],
|
|
50
|
-
latest: [],
|
|
51
|
-
}
|
|
52
|
-
}
|
|
53
|
-
const { subscribe, update } = writable<LogStore>(initialValue)
|
|
54
|
-
|
|
55
|
-
// @ts-ignore JSL_ENVIRONMENT is being replaced by @rollup/plugin-replace
|
|
56
|
-
const serverAddress = JSL_ENVIRONMENT == 'production' ? window.location.host : 'localhost:8000'
|
|
57
|
-
const ws = new WebSocket(`ws://${serverAddress}/`)
|
|
58
|
-
ws.onopen = function () {
|
|
59
|
-
console.log('WebSocket Client Connected')
|
|
60
|
-
}
|
|
61
|
-
ws.onmessage = function (e) {
|
|
62
|
-
const msg = decode(e.data) as ServerMessage
|
|
63
|
-
update(currentValue => {
|
|
64
|
-
const columns = Object.keys(parseFormatter(currentValue.formatter))
|
|
65
|
-
const logFormatter = formatLogMessage(currentValue.formatter)
|
|
66
|
-
if (msg.type === 'init') {
|
|
67
|
-
if (msg.mode === 'tail') {
|
|
68
|
-
return {
|
|
69
|
-
mode: msg.mode,
|
|
70
|
-
count: msg.size,
|
|
71
|
-
filter: currentValue.filter,
|
|
72
|
-
formatter: currentValue.formatter,
|
|
73
|
-
columns,
|
|
74
|
-
window: msg.window.map(logFormatter),
|
|
75
|
-
latest: [],
|
|
76
|
-
}
|
|
77
|
-
} else if (msg.mode === 'static') {
|
|
78
|
-
return {
|
|
79
|
-
mode: msg.mode,
|
|
80
|
-
count: msg.size,
|
|
81
|
-
filter: currentValue.filter,
|
|
82
|
-
formatter: currentValue.formatter,
|
|
83
|
-
columns,
|
|
84
|
-
window: msg.window.map(logFormatter),
|
|
85
|
-
offsetSeq: msg.offsetSeq,
|
|
86
|
-
latest: [],
|
|
87
|
-
}
|
|
88
|
-
}
|
|
89
|
-
} else if (msg.type === 'update') {
|
|
90
|
-
if (currentValue.mode === 'tail') {
|
|
91
|
-
return {
|
|
92
|
-
...currentValue,
|
|
93
|
-
count: msg.size,
|
|
94
|
-
window: [...currentValue.window.slice(-LOG_WINDOW_SIZE), logFormatter(msg.message)],
|
|
95
|
-
}
|
|
96
|
-
} else if (currentValue.mode === 'static') {
|
|
97
|
-
return {
|
|
98
|
-
...currentValue,
|
|
99
|
-
count: msg.size,
|
|
100
|
-
latest: [
|
|
101
|
-
...currentValue.latest.slice(-LATEST_LOG_WINDOW_SIZE),
|
|
102
|
-
logFormatter(msg.message),
|
|
103
|
-
],
|
|
104
|
-
}
|
|
105
|
-
}
|
|
106
|
-
}
|
|
107
|
-
})
|
|
108
|
-
}
|
|
109
|
-
|
|
110
|
-
const sendToServer = (msg: ClientMessage) => ws.send(encode(msg))
|
|
111
|
-
|
|
112
|
-
return {
|
|
113
|
-
subscribe,
|
|
114
|
-
changeFilter: (newFilter: string) => {
|
|
115
|
-
update(state => {
|
|
116
|
-
if (state.mode == 'tail') {
|
|
117
|
-
sendToServer({ mode: state.mode, filter: newFilter })
|
|
118
|
-
} else if (state.mode == 'static') {
|
|
119
|
-
sendToServer({ mode: state.mode, offsetSeq: state.offsetSeq, filter: newFilter })
|
|
120
|
-
}
|
|
121
|
-
return {
|
|
122
|
-
...state,
|
|
123
|
-
filter: newFilter,
|
|
124
|
-
}
|
|
125
|
-
})
|
|
126
|
-
},
|
|
127
|
-
changeToTail: () => {
|
|
128
|
-
update(state => {
|
|
129
|
-
sendToServer({ mode: 'tail', filter: state.filter })
|
|
130
|
-
return {
|
|
131
|
-
...state,
|
|
132
|
-
mode: 'tail',
|
|
133
|
-
offsetSeq: undefined,
|
|
134
|
-
}
|
|
135
|
-
})
|
|
136
|
-
},
|
|
137
|
-
changeToStatic: (offsetSeq: number) => {
|
|
138
|
-
update(state => {
|
|
139
|
-
sendToServer({ mode: 'static', offsetSeq, filter: state.filter })
|
|
140
|
-
return {
|
|
141
|
-
...state,
|
|
142
|
-
mode: 'static',
|
|
143
|
-
offsetSeq,
|
|
144
|
-
}
|
|
145
|
-
})
|
|
146
|
-
},
|
|
147
|
-
changeFormatter: (newFormatter: string) => {
|
|
148
|
-
update(state => {
|
|
149
|
-
// re-fetch data from the server so it can be formatted with the new formatter
|
|
150
|
-
sendToServer({
|
|
151
|
-
mode: state.mode,
|
|
152
|
-
offsetSeq: state.mode == 'static' ? state.offsetSeq : undefined,
|
|
153
|
-
filter: state.filter,
|
|
154
|
-
})
|
|
155
|
-
|
|
156
|
-
// save the new formatter
|
|
157
|
-
formatter.updateFormatter(newFormatter)
|
|
158
|
-
return {
|
|
159
|
-
...state,
|
|
160
|
-
formatter: newFormatter,
|
|
161
|
-
}
|
|
162
|
-
})
|
|
163
|
-
},
|
|
164
|
-
}
|
|
165
|
-
}
|
|
166
|
-
|
|
167
|
-
const encode = (data: any) => JSON.stringify(data)
|
|
168
|
-
const decode = (data: string) => JSON.parse(data)
|
|
169
|
-
const formatLogMessage = (formatterStr: string) => {
|
|
170
|
-
const formatter = parseFormatter(formatterStr)
|
|
171
|
-
return (msg: LogMessage): FormattedMessage => ({
|
|
172
|
-
seq: msg.seq,
|
|
173
|
-
rawMessage: msg.data,
|
|
174
|
-
formattedMessage: Object.keys(formatter).reduce(
|
|
175
|
-
(acc, key) => ({
|
|
176
|
-
...acc,
|
|
177
|
-
[key]: execFn(formatter[key], msg),
|
|
178
|
-
}),
|
|
179
|
-
{},
|
|
180
|
-
),
|
|
181
|
-
})
|
|
182
|
-
}
|
|
183
|
-
|
|
184
|
-
const execFn = (fn: LogColumnFormatter, msg: LogMessage) => {
|
|
185
|
-
try {
|
|
186
|
-
const res = fn(msg.data, msg.seq)
|
|
187
|
-
return res == undefined ? '' : res
|
|
188
|
-
} catch (err) {
|
|
189
|
-
return ''
|
|
190
|
-
}
|
|
191
|
-
}
|
|
192
|
-
|
|
193
|
-
const parseFormatter = memoizeOne(
|
|
194
|
-
(formatter: string): LogFormatter => {
|
|
195
|
-
let result
|
|
196
|
-
try {
|
|
197
|
-
result = eval(formatter)
|
|
198
|
-
} catch (err) {
|
|
199
|
-
throw err
|
|
200
|
-
// console.error('Invalid formatter object. Reverting to default format')
|
|
201
|
-
// console.log(err)
|
|
202
|
-
// result = eval(DEFAULT_LOG_FORMATTER)
|
|
203
|
-
}
|
|
204
|
-
return result
|
|
205
|
-
},
|
|
206
|
-
)
|
|
207
|
-
|
|
208
|
-
const logStore = createLogStore()
|
|
209
|
-
export { logStore, formatLogMessage, parseFormatter }
|
package/svelte/src/main.ts
DELETED
package/svelte/src/types.ts
DELETED
|
@@ -1,51 +0,0 @@
|
|
|
1
|
-
type OperationMode = 'static' | 'tail'
|
|
2
|
-
|
|
3
|
-
/**A log message has sent by the server to the clients */
|
|
4
|
-
type LogMessage = {
|
|
5
|
-
seq: number
|
|
6
|
-
data: Record<string, any>
|
|
7
|
-
index: string[]
|
|
8
|
-
}
|
|
9
|
-
|
|
10
|
-
/**A log message that's already been formatted and ready to be displayed */
|
|
11
|
-
type FormattedMessage = {
|
|
12
|
-
seq: number
|
|
13
|
-
rawMessage: Record<string, any>
|
|
14
|
-
formattedMessage: Record<string, any>
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
/**A function that formats a log message */
|
|
18
|
-
type LogFormatter = Record<string, LogColumnFormatter>
|
|
19
|
-
type LogColumnFormatter = (message: LogMessage['data'], seq: number) => any
|
|
20
|
-
|
|
21
|
-
// ***
|
|
22
|
-
// SERVER MESSAGES
|
|
23
|
-
// ***
|
|
24
|
-
|
|
25
|
-
// the message sent to clients that either just connected or changed operation model (tail <-> static)
|
|
26
|
-
type InitMessage = {
|
|
27
|
-
type: 'init'
|
|
28
|
-
mode: OperationMode
|
|
29
|
-
size: number
|
|
30
|
-
offsetSeq: number
|
|
31
|
-
window: LogMessage[]
|
|
32
|
-
}
|
|
33
|
-
// the message sent to all clients once a new message comes in from stdin
|
|
34
|
-
type UpdateMessage = { type: 'update'; size: number; message: LogMessage }
|
|
35
|
-
// all messages in the direction Server -> Client
|
|
36
|
-
type ServerMessage = InitMessage | UpdateMessage
|
|
37
|
-
|
|
38
|
-
// CLIENT MESSAGES
|
|
39
|
-
type StaticClientMessage = { mode: 'static'; filter: string; offsetSeq: number }
|
|
40
|
-
type TailClientMessage = { mode: 'tail'; filter: string }
|
|
41
|
-
/**Messages sent from the client to the server, basically to signal it want to swith operation mode */
|
|
42
|
-
type ClientMessage = StaticClientMessage | TailClientMessage
|
|
43
|
-
|
|
44
|
-
export type {
|
|
45
|
-
LogMessage,
|
|
46
|
-
FormattedMessage,
|
|
47
|
-
LogFormatter,
|
|
48
|
-
LogColumnFormatter,
|
|
49
|
-
ServerMessage,
|
|
50
|
-
ClientMessage,
|
|
51
|
-
}
|
package/svelte/tsconfig.json
DELETED
package/tsconfig.json
DELETED
|
@@ -1,71 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"include": ["src/**/*"],
|
|
3
|
-
"exclude": ["node_modules/*", "__sapper__/*", "public/*"],
|
|
4
|
-
"compilerOptions": {
|
|
5
|
-
/* Visit https://aka.ms/tsconfig.json to read more about this file */
|
|
6
|
-
/* Basic Options */
|
|
7
|
-
// "incremental": true, /* Enable incremental compilation */
|
|
8
|
-
"target": "ES5", /* Specify ECMAScript target version: 'ES3' (default), 'ES5', 'ES2015', 'ES2016', 'ES2017', 'ES2018', 'ES2019', 'ES2020', or 'ESNEXT'. */
|
|
9
|
-
"module": "commonjs", /* Specify module code generation: 'none', 'commonjs', 'amd', 'system', 'umd', 'es2015', 'es2020', or 'ESNext'. */
|
|
10
|
-
// "lib": [], /* Specify library files to be included in the compilation. */
|
|
11
|
-
// "allowJs": true, /* Allow javascript files to be compiled. */
|
|
12
|
-
// "checkJs": true, /* Report errors in .js files. */
|
|
13
|
-
// "jsx": "preserve", /* Specify JSX code generation: 'preserve', 'react-native', or 'react'. */
|
|
14
|
-
// "declaration": true, /* Generates corresponding '.d.ts' file. */
|
|
15
|
-
// "declarationMap": true, /* Generates a sourcemap for each corresponding '.d.ts' file. */
|
|
16
|
-
// "sourceMap": true, /* Generates corresponding '.map' file. */
|
|
17
|
-
// "outFile": "./", /* Concatenate and emit output to single file. */
|
|
18
|
-
// "outDir": "./", /* Redirect output structure to the directory. */
|
|
19
|
-
// "rootDir": "./", /* Specify the root directory of input files. Use to control the output directory structure with --outDir. */
|
|
20
|
-
// "composite": true, /* Enable project compilation */
|
|
21
|
-
// "tsBuildInfoFile": "./", /* Specify file to store incremental compilation information */
|
|
22
|
-
// "removeComments": true, /* Do not emit comments to output. */
|
|
23
|
-
// "noEmit": true, /* Do not emit outputs. */
|
|
24
|
-
// "importHelpers": true, /* Import emit helpers from 'tslib'. */
|
|
25
|
-
// "downlevelIteration": true, /* Provide full support for iterables in 'for-of', spread, and destructuring when targeting 'ES5' or 'ES3'. */
|
|
26
|
-
// "isolatedModules": true, /* Transpile each file as a separate module (similar to 'ts.transpileModule'). */
|
|
27
|
-
|
|
28
|
-
/* Strict Type-Checking Options */
|
|
29
|
-
"strict": true, /* Enable all strict type-checking options. */
|
|
30
|
-
// "noImplicitAny": true, /* Raise error on expressions and declarations with an implied 'any' type. */
|
|
31
|
-
// "strictNullChecks": true, /* Enable strict null checks. */
|
|
32
|
-
// "strictFunctionTypes": true, /* Enable strict checking of function types. */
|
|
33
|
-
// "strictBindCallApply": true, /* Enable strict 'bind', 'call', and 'apply' methods on functions. */
|
|
34
|
-
// "strictPropertyInitialization": true, /* Enable strict checking of property initialization in classes. */
|
|
35
|
-
// "noImplicitThis": true, /* Raise error on 'this' expressions with an implied 'any' type. */
|
|
36
|
-
// "alwaysStrict": true, /* Parse in strict mode and emit "use strict" for each source file. */
|
|
37
|
-
|
|
38
|
-
/* Additional Checks */
|
|
39
|
-
// "noUnusedLocals": true, /* Report errors on unused locals. */
|
|
40
|
-
// "noUnusedParameters": true, /* Report errors on unused parameters. */
|
|
41
|
-
// "noImplicitReturns": true, /* Report error when not all code paths in function return a value. */
|
|
42
|
-
// "noFallthroughCasesInSwitch": true, /* Report errors for fallthrough cases in switch statement. */
|
|
43
|
-
// "noUncheckedIndexedAccess": true, /* Include 'undefined' in index signature results */
|
|
44
|
-
|
|
45
|
-
/* Module Resolution Options */
|
|
46
|
-
// "moduleResolution": "node", /* Specify module resolution strategy: 'node' (Node.js) or 'classic' (TypeScript pre-1.6). */
|
|
47
|
-
// "baseUrl": "./", /* Base directory to resolve non-absolute module names. */
|
|
48
|
-
// "paths": {}, /* A series of entries which re-map imports to lookup locations relative to the 'baseUrl'. */
|
|
49
|
-
// "rootDirs": [], /* List of root folders whose combined content represents the structure of the project at runtime. */
|
|
50
|
-
// "typeRoots": [], /* List of folders to include type definitions from. */
|
|
51
|
-
// "types": [], /* Type declaration files to be included in compilation. */
|
|
52
|
-
// "allowSyntheticDefaultImports": true, /* Allow default imports from modules with no default export. This does not affect code emit, just typechecking. */
|
|
53
|
-
"esModuleInterop": true, /* Enables emit interoperability between CommonJS and ES Modules via creation of namespace objects for all imports. Implies 'allowSyntheticDefaultImports'. */
|
|
54
|
-
// "preserveSymlinks": true, /* Do not resolve the real path of symlinks. */
|
|
55
|
-
// "allowUmdGlobalAccess": true, /* Allow accessing UMD globals from modules. */
|
|
56
|
-
|
|
57
|
-
/* Source Map Options */
|
|
58
|
-
// "sourceRoot": "", /* Specify the location where debugger should locate TypeScript files instead of source locations. */
|
|
59
|
-
// "mapRoot": "", /* Specify the location where debugger should locate map files instead of generated locations. */
|
|
60
|
-
// "inlineSourceMap": true, /* Emit a single file with source maps instead of having a separate file. */
|
|
61
|
-
// "inlineSources": true, /* Emit the source alongside the sourcemaps within a single file; requires '--inlineSourceMap' or '--sourceMap' to be set. */
|
|
62
|
-
|
|
63
|
-
/* Experimental Options */
|
|
64
|
-
// "experimentalDecorators": true, /* Enables experimental support for ES7 decorators. */
|
|
65
|
-
// "emitDecoratorMetadata": true, /* Enables experimental support for emitting type metadata for decorators. */
|
|
66
|
-
|
|
67
|
-
/* Advanced Options */
|
|
68
|
-
"skipLibCheck": true, /* Skip type checking of declaration files. */
|
|
69
|
-
"forceConsistentCasingInFileNames": true /* Disallow inconsistently-cased references to the same file. */
|
|
70
|
-
}
|
|
71
|
-
}
|