forked from apache/daffodil-vscode
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Serverheartbeat now sent through session to UI
- Loading branch information
1 parent
621c3dd
commit 89f7ba5
Showing
14 changed files
with
247 additions
and
215 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
import { FilePath } from '..' | ||
import { IConfig } from '../../config' | ||
|
||
export class Connection { | ||
constructor( | ||
readonly host: string, | ||
readonly port: number | ||
) {} | ||
} | ||
|
||
export type GetServerConfigStrategy = () => Promise<ServerConfig> | ||
export class ServerConfig { | ||
readonly conn: Connection | ||
readonly logFile: FilePath | ||
readonly logLevel: string | ||
readonly checkpointPath: string | ||
|
||
constructor(config: () => IConfig) { | ||
const { checkpointPath, logFile, logLevel, port } = config() | ||
this.conn = new Connection('127.0.0.1', port) | ||
this.logFile = new FilePath(logFile) | ||
this.logLevel = logLevel | ||
this.checkpointPath = checkpointPath | ||
} | ||
} |
File renamed without changes.
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,83 @@ | ||
import { createSimpleFileLogger, setLogger } from '@omega-edit/client' | ||
import { ServerConfig } from './config' | ||
|
||
import * as fs from 'fs' | ||
import path from 'path' | ||
import XDGAppPaths from 'xdg-app-paths' | ||
export const APP_DATA_PATH: string = XDGAppPaths({ name: 'omega_edit' }).data() | ||
|
||
const MAX_LOG_FILES = 5 | ||
function rotateLogFiles(logFile: string): void { | ||
interface LogFile { | ||
path: string | ||
ctime: Date | ||
} | ||
|
||
// assert( | ||
// MAX_LOG_FILES > 0, | ||
// 'Maximum number of log files must be greater than 0' | ||
// ) | ||
|
||
if (fs.existsSync(logFile)) { | ||
const logDir = path.dirname(logFile) | ||
const logFileName = path.basename(logFile) | ||
|
||
// Get list of existing log files | ||
const logFiles: LogFile[] = fs | ||
.readdirSync(logDir) | ||
.filter((file) => file.startsWith(logFileName) && file !== logFileName) | ||
.map((file) => ({ | ||
path: path.join(logDir, file), | ||
ctime: fs.statSync(path.join(logDir, file)).ctime, | ||
})) | ||
.sort((a, b) => b.ctime.getTime() - a.ctime.getTime()) | ||
|
||
// Delete oldest log files if maximum number of log files is exceeded | ||
while (logFiles.length >= MAX_LOG_FILES) { | ||
const fileToDelete = logFiles.pop() as LogFile | ||
fs.unlinkSync(fileToDelete.path) | ||
} | ||
|
||
// Rename current log file with timestamp and create a new empty file | ||
const timestamp = new Date().toISOString().replace(/:/g, '-') | ||
fs.renameSync(logFile, path.join(logDir, `${logFileName}.${timestamp}`)) | ||
} | ||
} | ||
|
||
export function setupLogging(config: ServerConfig): Promise<void> { | ||
return new Promise((res, rej) => { | ||
const filePath = config.logFile.fullPath() | ||
const level = config.logLevel | ||
rotateLogFiles(filePath) | ||
setLogger(createSimpleFileLogger(filePath, level)) | ||
res() | ||
}) | ||
} | ||
|
||
export function generateLogbackConfigFile(server: ServerConfig): string { | ||
const serverLogFile = path.join(APP_DATA_PATH, `serv-${server.conn.port}.log`) | ||
const dirname = path.dirname(server.logFile.fullPath()) | ||
if (!fs.existsSync(dirname)) { | ||
fs.mkdirSync(dirname, { recursive: true }) | ||
} | ||
const logbackConfig = `<?xml version="1.0" encoding="UTF-8"?>\n | ||
<configuration> | ||
<appender name="FILE" class="ch.qos.logback.core.FileAppender"> | ||
<file>${serverLogFile}</file> | ||
<encoder> | ||
<pattern>[%date{ISO8601}] [%level] [%logger] [%marker] [%thread] - %msg MDC: {%mdc}%n</pattern> | ||
</encoder> | ||
</appender> | ||
<root level="${server.logLevel.toUpperCase()}"> | ||
<appender-ref ref="FILE" /> | ||
</root> | ||
</configuration> | ||
` | ||
const logbackConfigFile = path.join( | ||
APP_DATA_PATH, | ||
`serv-${server.conn.port}.logconf.xml` | ||
) | ||
rotateLogFiles(server.logFile.fullPath()) | ||
fs.writeFileSync(logbackConfigFile, logbackConfig) | ||
return logbackConfigFile // Return the path to the logback config file | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.