forked from FoundKeyGang/FoundKey
logger: remove unused structured data
The `data` field is not used anywhere in the logger. While it would be possible to send structured data through syslog, it seems unnecessary at present and also the way in which this structured data would have to be provided sounds too cumbersome to implement for no real value.
This commit is contained in:
parent
c5327f74d4
commit
85a392ee33
6 changed files with 32 additions and 55 deletions
|
@ -41,7 +41,7 @@ function greet(): void {
|
|||
}
|
||||
|
||||
bootLogger.info('Welcome to FoundKey!');
|
||||
bootLogger.info(`FoundKey v${meta.version}`, null, true);
|
||||
bootLogger.info(`FoundKey v${meta.version}`, true);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -59,7 +59,7 @@ export async function masterMain(): Promise<void> {
|
|||
config = loadConfigBoot();
|
||||
await connectDb();
|
||||
} catch (e) {
|
||||
bootLogger.error('Fatal error occurred during initialization', {}, true);
|
||||
bootLogger.error('Fatal error occurred during initialization', true);
|
||||
process.exit(1);
|
||||
}
|
||||
|
||||
|
@ -69,7 +69,7 @@ export async function masterMain(): Promise<void> {
|
|||
await spawnWorkers(config.clusterLimits);
|
||||
}
|
||||
|
||||
bootLogger.succ(`Now listening on port ${config.port} on ${config.url}`, null, true);
|
||||
bootLogger.succ(`Now listening on port ${config.port} on ${config.url}`, true);
|
||||
|
||||
if (!envOption.noDaemons) {
|
||||
import('../daemons/server-stats.js').then(x => x.serverStats());
|
||||
|
@ -84,7 +84,7 @@ function showEnvironment(): void {
|
|||
|
||||
if (env !== 'production') {
|
||||
logger.warn('The environment is not in production mode.');
|
||||
logger.warn('DO NOT USE FOR PRODUCTION PURPOSE!', {}, true);
|
||||
logger.warn('DO NOT USE FOR PRODUCTION PURPOSE!', true);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -109,7 +109,7 @@ function loadConfigBoot(): Config {
|
|||
} catch (exception) {
|
||||
const e = exception as Partial<NodeJS.ErrnoException> | Error;
|
||||
if ('code' in e && e.code === 'ENOENT') {
|
||||
configLogger.error('Configuration file not found', {}, true);
|
||||
configLogger.error('Configuration file not found', true);
|
||||
process.exit(1);
|
||||
} else if (e instanceof Error) {
|
||||
configLogger.error(e.message);
|
||||
|
@ -133,7 +133,7 @@ async function connectDb(): Promise<void> {
|
|||
const v = await db.query('SHOW server_version').then(x => x[0].server_version);
|
||||
dbLogger.succ(`Connected: v${v}`);
|
||||
} catch (e) {
|
||||
dbLogger.error('Cannot connect', {}, true);
|
||||
dbLogger.error('Cannot connect', true);
|
||||
dbLogger.error(e as Error | string);
|
||||
process.exit(1);
|
||||
}
|
||||
|
|
|
@ -39,8 +39,8 @@ systemQueue
|
|||
.on('waiting', (jobId) => systemLogger.debug(`waiting id=${jobId}`))
|
||||
.on('active', (job) => systemLogger.debug(`active id=${job.id}`))
|
||||
.on('completed', (job, result) => systemLogger.debug(`completed(${result}) id=${job.id}`))
|
||||
.on('failed', (job, err) => systemLogger.warn(`failed(${err}) id=${job.id}`, { job, e: renderError(err) }))
|
||||
.on('error', (job: any, err: Error) => systemLogger.error(`error ${err}`, { job, e: renderError(err) }))
|
||||
.on('failed', (job, err) => systemLogger.warn(`failed(${err}) id=${job.id}`))
|
||||
.on('error', (job: any, err: Error) => systemLogger.error(`error ${err}`))
|
||||
.on('stalled', (job) => systemLogger.warn(`stalled id=${job.id}`));
|
||||
|
||||
deliverQueue
|
||||
|
@ -48,31 +48,31 @@ deliverQueue
|
|||
.on('active', (job) => deliverLogger.debug(`active ${getJobInfo(job, true)} to=${job.data.to}`))
|
||||
.on('completed', (job, result) => deliverLogger.debug(`completed(${result}) ${getJobInfo(job, true)} to=${job.data.to}`))
|
||||
.on('failed', (job, err) => deliverLogger.warn(`failed(${err}) ${getJobInfo(job)} to=${job.data.to}`))
|
||||
.on('error', (job: any, err: Error) => deliverLogger.error(`error ${err}`, { job, e: renderError(err) }))
|
||||
.on('error', (job: any, err: Error) => deliverLogger.error(`error ${err}`))
|
||||
.on('stalled', (job) => deliverLogger.warn(`stalled ${getJobInfo(job)} to=${job.data.to}`));
|
||||
|
||||
inboxQueue
|
||||
.on('waiting', (jobId) => inboxLogger.debug(`waiting id=${jobId}`))
|
||||
.on('active', (job) => inboxLogger.debug(`active ${getJobInfo(job, true)}`))
|
||||
.on('completed', (job, result) => inboxLogger.debug(`completed(${result}) ${getJobInfo(job, true)}`))
|
||||
.on('failed', (job, err) => inboxLogger.warn(`failed(${err}) ${getJobInfo(job)} activity=${job.data.activity ? job.data.activity.id : 'none'}`, { job, e: renderError(err) }))
|
||||
.on('error', (job: any, err: Error) => inboxLogger.error(`error ${err}`, { job, e: renderError(err) }))
|
||||
.on('failed', (job, err) => inboxLogger.warn(`failed(${err}) ${getJobInfo(job)} activity=${job.data.activity ? job.data.activity.id : 'none'}`))
|
||||
.on('error', (job: any, err: Error) => inboxLogger.error(`error ${err}`))
|
||||
.on('stalled', (job) => inboxLogger.warn(`stalled ${getJobInfo(job)} activity=${job.data.activity ? job.data.activity.id : 'none'}`));
|
||||
|
||||
dbQueue
|
||||
.on('waiting', (jobId) => dbLogger.debug(`waiting id=${jobId}`))
|
||||
.on('active', (job) => dbLogger.debug(`active id=${job.id}`))
|
||||
.on('completed', (job, result) => dbLogger.debug(`completed(${result}) id=${job.id}`))
|
||||
.on('failed', (job, err) => dbLogger.warn(`failed(${err}) id=${job.id}`, { job, e: renderError(err) }))
|
||||
.on('error', (job: any, err: Error) => dbLogger.error(`error ${err}`, { job, e: renderError(err) }))
|
||||
.on('failed', (job, err) => dbLogger.warn(`failed(${err}) id=${job.id}`))
|
||||
.on('error', (job: any, err: Error) => dbLogger.error(`error ${err}`))
|
||||
.on('stalled', (job) => dbLogger.warn(`stalled id=${job.id}`));
|
||||
|
||||
objectStorageQueue
|
||||
.on('waiting', (jobId) => objectStorageLogger.debug(`waiting id=${jobId}`))
|
||||
.on('active', (job) => objectStorageLogger.debug(`active id=${job.id}`))
|
||||
.on('completed', (job, result) => objectStorageLogger.debug(`completed(${result}) id=${job.id}`))
|
||||
.on('failed', (job, err) => objectStorageLogger.warn(`failed(${err}) id=${job.id}`, { job, e: renderError(err) }))
|
||||
.on('error', (job: any, err: Error) => objectStorageLogger.error(`error ${err}`, { job, e: renderError(err) }))
|
||||
.on('failed', (job, err) => objectStorageLogger.warn(`failed(${err}) id=${job.id}`))
|
||||
.on('error', (job: any, err: Error) => objectStorageLogger.error(`error ${err}`))
|
||||
.on('stalled', (job) => objectStorageLogger.warn(`stalled id=${job.id}`));
|
||||
|
||||
webhookDeliverQueue
|
||||
|
@ -80,7 +80,7 @@ webhookDeliverQueue
|
|||
.on('active', (job) => webhookLogger.debug(`active ${getJobInfo(job, true)} to=${job.data.to}`))
|
||||
.on('completed', (job, result) => webhookLogger.debug(`completed(${result}) ${getJobInfo(job, true)} to=${job.data.to}`))
|
||||
.on('failed', (job, err) => webhookLogger.warn(`failed(${err}) ${getJobInfo(job)} to=${job.data.to}`))
|
||||
.on('error', (job: any, err: Error) => webhookLogger.error(`error ${err}`, { job, e: renderError(err) }))
|
||||
.on('error', (job: any, err: Error) => webhookLogger.error(`error ${err}`))
|
||||
.on('stalled', (job) => webhookLogger.warn(`stalled ${getJobInfo(job)} to=${job.data.to}`));
|
||||
|
||||
export function deliver(user: ThinUser, content: unknown, to: string | null) {
|
||||
|
|
|
@ -74,13 +74,7 @@ export async function createNote(value: string | IObject, resolver: Resolver, si
|
|||
|
||||
const err = validateNote(object);
|
||||
if (err) {
|
||||
apLogger.error(`${err.message}`, {
|
||||
resolver: {
|
||||
history: resolver.getHistory(),
|
||||
},
|
||||
value,
|
||||
object,
|
||||
});
|
||||
apLogger.error(`${err.message}`);
|
||||
throw new Error('invalid note');
|
||||
}
|
||||
|
||||
|
|
|
@ -82,15 +82,7 @@ export default async (endpoint: string, user: ILocalUser | null | undefined, tok
|
|||
if (e instanceof ApiError) {
|
||||
throw e;
|
||||
} else {
|
||||
apiLogger.error(`Internal error occurred in ${ep.name}: ${e.message}`, {
|
||||
ep: ep.name,
|
||||
ps: data,
|
||||
e: {
|
||||
message: e.message,
|
||||
code: e.name,
|
||||
stack: e.stack,
|
||||
},
|
||||
});
|
||||
apiLogger.error(`Internal error occurred in ${ep.name}: ${e.message}`);
|
||||
throw new ApiError('INTERNAL_ERROR', {
|
||||
e: {
|
||||
message: e.message,
|
||||
|
|
|
@ -60,10 +60,7 @@ export async function uploadFromUrl({
|
|||
logger.succ(`Got: ${driveFile.id}`);
|
||||
return driveFile;
|
||||
} catch (e) {
|
||||
logger.error(`Failed to create drive file: ${e}`, {
|
||||
url,
|
||||
e,
|
||||
});
|
||||
logger.error(`Failed to create drive file: ${e}`);
|
||||
throw e;
|
||||
} finally {
|
||||
cleanup();
|
||||
|
|
|
@ -84,7 +84,7 @@ export default class Logger {
|
|||
* @param important Whether to highlight this message as especially important.
|
||||
* @param subDomains Names of sub-loggers to be added.
|
||||
*/
|
||||
private log(level: Level, message: string, data?: Record<string, any> | null, important = false, subDomains: Domain[] = [], _store = true): void {
|
||||
private log(level: Level, message: string, important = false, subDomains: Domain[] = [], _store = true): void {
|
||||
if (envOption.quiet) return;
|
||||
const store = _store && this.store;
|
||||
|
||||
|
@ -94,7 +94,7 @@ export default class Logger {
|
|||
// If this logger has a parent logger, delegate the actual logging to it,
|
||||
// so the parent domain(s) will be logged properly.
|
||||
if (this.parentLogger) {
|
||||
this.parentLogger.log(level, message, data, important, [this.domain].concat(subDomains), store);
|
||||
this.parentLogger.log(level, message, important, [this.domain].concat(subDomains), store);
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -154,17 +154,15 @@ export default class Logger {
|
|||
* Log an error message.
|
||||
* Use in situations where execution cannot be continued.
|
||||
* @param err Error or string containing an error message
|
||||
* @param data Data relating to the error
|
||||
* @param important Whether this error is important
|
||||
*/
|
||||
public error(err: string | Error, data: Record<string, any> = {}, important = false): void {
|
||||
public error(err: string | Error, important = false): void {
|
||||
if (err instanceof Error) {
|
||||
data.e = err;
|
||||
this.log(LEVELS.error, err.toString(), data, important);
|
||||
this.log(LEVELS.error, err.toString(), important);
|
||||
} else if (typeof err === 'object') {
|
||||
this.log(LEVELS.error, `${(err as any).message || (err as any).name || err}`, data, important);
|
||||
this.log(LEVELS.error, `${(err as any).message || (err as any).name || err}`, important);
|
||||
} else {
|
||||
this.log(LEVELS.error, `${err}`, data, important);
|
||||
this.log(LEVELS.error, `${err}`, important);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -172,21 +170,19 @@ export default class Logger {
|
|||
* Log a warning message.
|
||||
* Use in situations where execution can continue but needs to be improved.
|
||||
* @param message Warning message
|
||||
* @param data Data relating to the warning
|
||||
* @param important Whether this warning is important
|
||||
*/
|
||||
public warn(message: string, data?: Record<string, any> | null, important = false): void {
|
||||
this.log(LEVELS.warning, message, data, important);
|
||||
public warn(message: string, important = false): void {
|
||||
this.log(LEVELS.warning, message, important);
|
||||
}
|
||||
|
||||
/**
|
||||
* Log a success message.
|
||||
* Use in situations where something has been successfully done.
|
||||
* @param message Success message
|
||||
* @param data Data relating to the success
|
||||
* @param important Whether this success message is important
|
||||
*/
|
||||
public succ(message: string, data?: Record<string, any> | null, important = false): void {
|
||||
public succ(message: string, important = false): void {
|
||||
this.log(LEVELS.success, message, important);
|
||||
}
|
||||
|
||||
|
@ -194,21 +190,19 @@ export default class Logger {
|
|||
* Log a debug message.
|
||||
* Use for debugging (information needed by developers but not required by users).
|
||||
* @param message Debug message
|
||||
* @param data Data relating to the debug message
|
||||
* @param important Whether this debug message is important
|
||||
*/
|
||||
public debug(message: string, data?: Record<string, any> | null, important = false): void {
|
||||
this.log(LEVELS.debug, message, data, important);
|
||||
public debug(message: string, important = false): void {
|
||||
this.log(LEVELS.debug, message, important);
|
||||
}
|
||||
|
||||
/**
|
||||
* Log an informational message.
|
||||
* Use when something needs to be logged but doesn't fit into other levels.
|
||||
* @param message Info message
|
||||
* @param data Data relating to the info message
|
||||
* @param important Whether this info message is important
|
||||
*/
|
||||
public info(message: string, data?: Record<string, any> | null, important = false): void {
|
||||
this.log(LEVELS.info, message, data, important);
|
||||
public info(message: string, important = false): void {
|
||||
this.log(LEVELS.info, message, important);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue