Compare commits

...

9 Commits

21 changed files with 163 additions and 79 deletions

View File

@@ -3,6 +3,12 @@
All notable changes to this project will be documented in this file.
See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
## [1.64.2](https://github.com/standardnotes/api-gateway/compare/@standardnotes/api-gateway@1.64.1...@standardnotes/api-gateway@1.64.2) (2023-06-22)
### Bug Fixes
* **home-server:** add debug logs about container initalizations ([0df4715](https://github.com/standardnotes/api-gateway/commit/0df471585fd5b4626ec2972f3b9a3e33b2830e65))
## [1.64.1](https://github.com/standardnotes/api-gateway/compare/@standardnotes/api-gateway@1.64.0...@standardnotes/api-gateway@1.64.1) (2023-06-09)
### Bug Fixes

View File

@@ -1,6 +1,6 @@
{
"name": "@standardnotes/api-gateway",
"version": "1.64.1",
"version": "1.64.2",
"engines": {
"node": ">=18.0.0 <21.0.0"
},

View File

@@ -46,17 +46,18 @@ export class ContainerConfigLoader {
winstonFormatters.push(newrelicWinstonFormatter())
}
let logger: winston.Logger
if (configuration?.logger) {
container.bind<winston.Logger>(TYPES.Logger).toConstantValue(configuration.logger as winston.Logger)
logger = configuration.logger as winston.Logger
} else {
const logger = winston.createLogger({
logger = winston.createLogger({
level: env.get('LOG_LEVEL', true) || 'info',
format: winston.format.combine(...winstonFormatters),
transports: [new winston.transports.Console({ level: env.get('LOG_LEVEL', true) || 'info' })],
defaultMeta: { service: 'api-gateway' },
})
container.bind<winston.Logger>(TYPES.Logger).toConstantValue(logger)
}
container.bind<winston.Logger>(TYPES.Logger).toConstantValue(logger)
if (!isConfiguredForInMemoryCache) {
const redisUrl = env.get('REDIS_URL')
@@ -125,6 +126,8 @@ export class ContainerConfigLoader {
.bind<EndpointResolverInterface>(TYPES.EndpointResolver)
.toConstantValue(new EndpointResolver(isConfiguredForHomeServer))
logger.debug('Configuration complete')
return container
}
}

View File

@@ -3,6 +3,12 @@
All notable changes to this project will be documented in this file.
See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
## [1.119.3](https://github.com/standardnotes/server/compare/@standardnotes/auth-server@1.119.2...@standardnotes/auth-server@1.119.3) (2023-06-22)
### Bug Fixes
* **home-server:** add debug logs about container initalizations ([0df4715](https://github.com/standardnotes/server/commit/0df471585fd5b4626ec2972f3b9a3e33b2830e65))
## [1.119.2](https://github.com/standardnotes/server/compare/@standardnotes/auth-server@1.119.1...@standardnotes/auth-server@1.119.2) (2023-06-14)
### Bug Fixes

View File

@@ -1,6 +1,6 @@
{
"name": "@standardnotes/auth-server",
"version": "1.119.2",
"version": "1.119.3",
"engines": {
"node": ">=18.0.0 <21.0.0"
},

View File

@@ -268,9 +268,33 @@ export class ContainerConfigLoader {
const container = new Container()
const winstonFormatters = [winston.format.splat(), winston.format.json()]
if (env.get('NEW_RELIC_ENABLED', true) === 'true') {
await import('newrelic')
// eslint-disable-next-line @typescript-eslint/no-var-requires
const newrelicFormatter = require('@newrelic/winston-enricher')
const newrelicWinstonFormatter = newrelicFormatter(winston)
winstonFormatters.push(newrelicWinstonFormatter())
}
let logger: winston.Logger
if (configuration?.logger) {
logger = configuration.logger as winston.Logger
} else {
logger = winston.createLogger({
level: env.get('LOG_LEVEL', true) || 'info',
format: winston.format.combine(...winstonFormatters),
transports: [new winston.transports.Console({ level: env.get('LOG_LEVEL', true) || 'info' })],
defaultMeta: { service: 'auth' },
})
}
container.bind<winston.Logger>(TYPES.Auth_Logger).toConstantValue(logger)
const appDataSource = new AppDataSource(env)
await appDataSource.initialize()
logger.debug('Database initialized')
const isConfiguredForHomeServer = env.get('MODE', true) === 'home-server'
const isConfiguredForInMemoryCache = env.get('CACHE_TYPE', true) === 'memory'
@@ -287,27 +311,6 @@ export class ContainerConfigLoader {
container.bind(TYPES.Auth_Redis).toConstantValue(redis)
}
const winstonFormatters = [winston.format.splat(), winston.format.json()]
if (env.get('NEW_RELIC_ENABLED', true) === 'true') {
await import('newrelic')
// eslint-disable-next-line @typescript-eslint/no-var-requires
const newrelicFormatter = require('@newrelic/winston-enricher')
const newrelicWinstonFormatter = newrelicFormatter(winston)
winstonFormatters.push(newrelicWinstonFormatter())
}
if (configuration?.logger) {
container.bind<winston.Logger>(TYPES.Auth_Logger).toConstantValue(configuration.logger as winston.Logger)
} else {
const logger = winston.createLogger({
level: env.get('LOG_LEVEL', true) || 'info',
format: winston.format.combine(...winstonFormatters),
transports: [new winston.transports.Console({ level: env.get('LOG_LEVEL', true) || 'info' })],
defaultMeta: { service: 'auth' },
})
container.bind<winston.Logger>(TYPES.Auth_Logger).toConstantValue(logger)
}
container.bind<TimerInterface>(TYPES.Auth_Timer).toConstantValue(new Timer())
if (!isConfiguredForHomeServer) {
@@ -1201,6 +1204,8 @@ export class ContainerConfigLoader {
)
}
logger.debug('Configuration complete')
return container
}
}

View File

@@ -3,6 +3,12 @@
All notable changes to this project will be documented in this file.
See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
## [1.18.3](https://github.com/standardnotes/files/compare/@standardnotes/files-server@1.18.2...@standardnotes/files-server@1.18.3) (2023-06-22)
### Bug Fixes
* **home-server:** add debug logs about container initalizations ([0df4715](https://github.com/standardnotes/files/commit/0df471585fd5b4626ec2972f3b9a3e33b2830e65))
## [1.18.2](https://github.com/standardnotes/files/compare/@standardnotes/files-server@1.18.1...@standardnotes/files-server@1.18.2) (2023-06-12)
### Bug Fixes

View File

@@ -1,6 +1,6 @@
{
"name": "@standardnotes/files-server",
"version": "1.18.2",
"version": "1.18.3",
"engines": {
"node": ">=18.0.0 <21.0.0"
},

View File

@@ -70,11 +70,13 @@ export class ContainerConfigLoader {
const isConfiguredForHomeServer = env.get('MODE', true) === 'home-server'
const isConfiguredForInMemoryCache = env.get('CACHE_TYPE', true) === 'memory'
let logger: winston.Logger
if (configuration?.logger) {
container.bind<winston.Logger>(TYPES.Files_Logger).toConstantValue(configuration.logger as winston.Logger)
logger = configuration.logger as winston.Logger
} else {
container.bind<winston.Logger>(TYPES.Files_Logger).toConstantValue(this.createLogger({ env }))
logger = this.createLogger({ env })
}
container.bind<winston.Logger>(TYPES.Files_Logger).toConstantValue(logger)
container.bind<TimerInterface>(TYPES.Files_Timer).toConstantValue(new Timer())
@@ -249,6 +251,8 @@ export class ContainerConfigLoader {
)
}
logger.debug('Configuration complete')
return container
}

View File

@@ -3,6 +3,31 @@
All notable changes to this project will be documented in this file.
See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
## [1.11.11](https://github.com/standardnotes/server/compare/@standardnotes/home-server@1.11.10...@standardnotes/home-server@1.11.11) (2023-06-22)
### Bug Fixes
* **home-server:** destroy winston loggers upon server shutdown ([c7a394c](https://github.com/standardnotes/server/commit/c7a394cd1a696305796362cca25fea93e695a86a))
## [1.11.10](https://github.com/standardnotes/server/compare/@standardnotes/home-server@1.11.9...@standardnotes/home-server@1.11.10) (2023-06-22)
### Bug Fixes
* **home-server:** pass the log stream callback before loggers are created ([1ca70c1](https://github.com/standardnotes/server/commit/1ca70c1e504257a3753203c0b5630db3d446d393))
## [1.11.9](https://github.com/standardnotes/server/compare/@standardnotes/home-server@1.11.8...@standardnotes/home-server@1.11.9) (2023-06-22)
### Bug Fixes
* **home-server:** listening on log stream ([e38a164](https://github.com/standardnotes/server/commit/e38a16404c1b335ab0ef4d8383f6f644e51934ad))
* **home-server:** passthrough stream for loggers ([f17a1f8](https://github.com/standardnotes/server/commit/f17a1f875cd087115b06c8224342f6d102042767))
## [1.11.8](https://github.com/standardnotes/server/compare/@standardnotes/home-server@1.11.7...@standardnotes/home-server@1.11.8) (2023-06-22)
### Bug Fixes
* **home-server:** add debug logs about container initalizations ([0df4715](https://github.com/standardnotes/server/commit/0df471585fd5b4626ec2972f3b9a3e33b2830e65))
## [1.11.7](https://github.com/standardnotes/server/compare/@standardnotes/home-server@1.11.6...@standardnotes/home-server@1.11.7) (2023-06-22)
### Bug Fixes

View File

@@ -2,16 +2,15 @@ import { HomeServer } from '../src/Server/HomeServer'
const homeServer = new HomeServer()
Promise.resolve(homeServer.start({ dataDirectoryPath: `${__dirname}/../data` }))
.then(() => {
const logStream = homeServer.logs()
logStream.on('data', (chunk: Buffer) => {
Promise.resolve(
homeServer.start({
dataDirectoryPath: `${__dirname}/../data`,
logStreamCallback: (chunk: Buffer) => {
// eslint-disable-next-line no-console
console.log(chunk.toString())
})
})
.catch((error) => {
// eslint-disable-next-line no-console
console.log(`Could not start server: ${error.message}`)
})
},
}),
).catch((error) => {
// eslint-disable-next-line no-console
console.log(`Could not start server: ${error.message}`)
})

View File

@@ -1,6 +1,6 @@
{
"name": "@standardnotes/home-server",
"version": "1.11.7",
"version": "1.11.11",
"engines": {
"node": ">=18.0.0 <21.0.0"
},

View File

@@ -25,7 +25,15 @@ import { HomeServerConfiguration } from './HomeServerConfiguration'
export class HomeServer implements HomeServerInterface {
private serverInstance: http.Server | undefined
private authService: AuthServiceInterface | undefined
private logStream: PassThrough = new PassThrough()
private logStream: PassThrough | undefined
private readonly loggerNames = [
'auth-server',
'syncing-server',
'revisions-server',
'files-server',
'api-gateway',
'home-server',
]
async start(configuration: HomeServerConfiguration): Promise<Result<string>> {
try {
@@ -38,7 +46,6 @@ export class HomeServer implements HomeServerInterface {
CACHE_TYPE: 'memory',
DB_SQLITE_DATABASE_PATH: `${configuration.dataDirectoryPath}/database/home_server.sqlite`,
FILE_UPLOAD_PATH: `${configuration.dataDirectoryPath}/uploads`,
LOG_LEVEL: 'info',
...configuration.environment,
MODE: 'home-server',
NEW_RELIC_ENABLED: 'false',
@@ -48,7 +55,7 @@ export class HomeServer implements HomeServerInterface {
const env: Env = new Env(environmentOverrides)
env.load()
this.configureLoggers(env)
this.configureLoggers(env, configuration)
const apiGatewayService = new ApiGatewayService(serviceContainer)
const authService = new AuthService(serviceContainer, controllerContainer, directCallDomainEventPublisher)
@@ -166,6 +173,14 @@ export class HomeServer implements HomeServerInterface {
return Result.fail('Home server is not running.')
}
for (const loggerName of this.loggerNames) {
winston.loggers.close(loggerName)
}
if (this.logStream) {
this.logStream.end()
}
this.serverInstance.close()
this.serverInstance.unref()
@@ -193,23 +208,18 @@ export class HomeServer implements HomeServerInterface {
return this.authService.activatePremiumFeatures(username)
}
logs(): NodeJS.ReadableStream {
return this.logStream
}
private configureLoggers(env: Env, configuration: HomeServerConfiguration): void {
this.logStream = new PassThrough()
if (configuration.logStreamCallback) {
this.logStream.on('data', configuration.logStreamCallback)
}
private configureLoggers(env: Env): void {
const winstonFormatters = [winston.format.splat(), winston.format.json()]
const level = env.get('LOG_LEVEL', true) || 'info'
for (const loggerName of [
'auth-server',
'syncing-server',
'revisions-server',
'files-server',
'api-gateway',
'home-server',
]) {
for (const loggerName of this.loggerNames) {
winston.loggers.add(loggerName, {
level,
format: winston.format.combine(...winstonFormatters),

View File

@@ -1,4 +1,5 @@
export interface HomeServerConfiguration {
dataDirectoryPath: string
environment?: { [name: string]: string }
logStreamCallback?: (chunk: Buffer) => void
}

View File

@@ -6,5 +6,4 @@ export interface HomeServerInterface {
activatePremiumFeatures(username: string): Promise<Result<string>>
stop(): Promise<Result<string>>
isRunning(): Promise<boolean>
logs(): NodeJS.ReadableStream
}

View File

@@ -3,6 +3,12 @@
All notable changes to this project will be documented in this file.
See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
## [1.23.2](https://github.com/standardnotes/server/compare/@standardnotes/revisions-server@1.23.1...@standardnotes/revisions-server@1.23.2) (2023-06-22)
### Bug Fixes
* **home-server:** add debug logs about container initalizations ([0df4715](https://github.com/standardnotes/server/commit/0df471585fd5b4626ec2972f3b9a3e33b2830e65))
## [1.23.1](https://github.com/standardnotes/server/compare/@standardnotes/revisions-server@1.23.0...@standardnotes/revisions-server@1.23.1) (2023-06-14)
### Bug Fixes

View File

@@ -1,6 +1,6 @@
{
"name": "@standardnotes/revisions-server",
"version": "1.23.1",
"version": "1.23.2",
"engines": {
"node": ">=18.0.0 <21.0.0"
},

View File

@@ -67,13 +67,9 @@ export class ContainerConfigLoader {
defaultScope: 'Singleton',
})
const appDataSource = new AppDataSource(env)
await appDataSource.initialize()
container.bind<Env>(TYPES.Revisions_Env).toConstantValue(env)
let logger: winston.Logger
if (configuration?.logger) {
container.bind<winston.Logger>(TYPES.Revisions_Logger).toConstantValue(configuration.logger as winston.Logger)
logger = configuration.logger as winston.Logger
} else {
const winstonFormatters = [winston.format.splat(), winston.format.json()]
if (env.get('NEW_RELIC_ENABLED', true) === 'true') {
@@ -84,15 +80,21 @@ export class ContainerConfigLoader {
winstonFormatters.push(newrelicWinstonFormatter())
}
const logger = winston.createLogger({
logger = winston.createLogger({
level: env.get('LOG_LEVEL', true) || 'info',
format: winston.format.combine(...winstonFormatters),
transports: [new winston.transports.Console({ level: env.get('LOG_LEVEL', true) || 'info' })],
defaultMeta: { service: 'revisions' },
})
container.bind<winston.Logger>(TYPES.Revisions_Logger).toConstantValue(logger)
}
container.bind<winston.Logger>(TYPES.Revisions_Logger).toConstantValue(logger)
const appDataSource = new AppDataSource(env)
await appDataSource.initialize()
logger.debug('Database initialized')
container.bind<Env>(TYPES.Revisions_Env).toConstantValue(env)
container.bind(TYPES.Revisions_NEW_RELIC_ENABLED).toConstantValue(env.get('NEW_RELIC_ENABLED', true))
container.bind(TYPES.Revisions_VERSION).toConstantValue(env.get('VERSION', true) ?? 'development')
@@ -350,6 +352,8 @@ export class ContainerConfigLoader {
)
}
logger.debug('Configuration complete')
return container
}
}

View File

@@ -3,6 +3,12 @@
All notable changes to this project will be documented in this file.
See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
## [1.44.2](https://github.com/standardnotes/syncing-server-js/compare/@standardnotes/syncing-server@1.44.1...@standardnotes/syncing-server@1.44.2) (2023-06-22)
### Bug Fixes
* **home-server:** add debug logs about container initalizations ([0df4715](https://github.com/standardnotes/syncing-server-js/commit/0df471585fd5b4626ec2972f3b9a3e33b2830e65))
## [1.44.1](https://github.com/standardnotes/syncing-server-js/compare/@standardnotes/syncing-server@1.44.0...@standardnotes/syncing-server@1.44.1) (2023-06-14)
### Bug Fixes

View File

@@ -1,6 +1,6 @@
{
"name": "@standardnotes/syncing-server",
"version": "1.44.1",
"version": "1.44.2",
"engines": {
"node": ">=18.0.0 <21.0.0"
},

View File

@@ -95,15 +95,9 @@ export class ContainerConfigLoader {
defaultScope: 'Singleton',
})
const appDataSource = new AppDataSource(env)
await appDataSource.initialize()
const isConfiguredForHomeServer = env.get('MODE', true) === 'home-server'
container.bind<Env>(TYPES.Sync_Env).toConstantValue(env)
let logger: winston.Logger
if (configuration?.logger) {
container.bind<winston.Logger>(TYPES.Sync_Logger).toConstantValue(configuration.logger as winston.Logger)
logger = configuration.logger as winston.Logger
} else {
const winstonFormatters = [winston.format.splat(), winston.format.json()]
if (env.get('NEW_RELIC_ENABLED', true) === 'true') {
@@ -114,15 +108,23 @@ export class ContainerConfigLoader {
winstonFormatters.push(newrelicWinstonFormatter())
}
const logger = winston.createLogger({
logger = winston.createLogger({
level: env.get('LOG_LEVEL', true) || 'info',
format: winston.format.combine(...winstonFormatters),
transports: [new winston.transports.Console({ level: env.get('LOG_LEVEL', true) || 'info' })],
defaultMeta: { service: 'syncing-server' },
})
container.bind<winston.Logger>(TYPES.Sync_Logger).toConstantValue(logger)
}
container.bind<winston.Logger>(TYPES.Sync_Logger).toConstantValue(logger)
const appDataSource = new AppDataSource(env)
await appDataSource.initialize()
logger.debug('Database initialized')
const isConfiguredForHomeServer = env.get('MODE', true) === 'home-server'
container.bind<Env>(TYPES.Sync_Env).toConstantValue(env)
if (isConfiguredForHomeServer) {
container
@@ -517,6 +519,8 @@ export class ContainerConfigLoader {
)
}
logger.debug('Configuration complete')
return container
}
}