Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 0 additions & 4 deletions dev/playgrounds/ground1/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,6 @@ import { Router, JoorResponse } from 'joor';
import Joor from 'joor';
import path from 'node:path';

process.env.JOOR_LOGGER_ENABLE_CONSOLE_LOGGING = 'false';
process.env.JOOR_LOGGER_ENABLE_FILE_LOGGING = 'true';
process.env.JOOR_RESPONSE_STREAM_CHUNK_SIZE = '200000';

const app = new Joor();

(async () => {
Expand Down
14 changes: 11 additions & 3 deletions dev/playgrounds/ground1/joor.config.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,17 @@
// import { JOOR_CONFIG } from 'joor';
const config = {
import { JOOR_CONFIG } from 'joor';
const config: JOOR_CONFIG = {
server: {
port: 3000,
host: 'localhost',
mode: 'http',
mode: 'tls',
},
mode: 'development',
logger: {
maxFileSize: 1024,
enable: {
file: true,
console: false,
},
},
};

Expand Down
15 changes: 12 additions & 3 deletions src/core/config/configuration.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ import path from 'node:path';

import Jrror from '@/core/error/index';
// import validateConfig from '@/helpers/validateConfig';
import JoorError from '@/core/error/JoorError';
import logger from '@/helpers/joorLogger';
import JOOR_CONFIG from '@/types/config';

/**
Expand Down Expand Up @@ -84,9 +86,8 @@ class Configuration {
process.env.JOOR_LOGGER_ENABLE_CONSOLE_LOGGING =
(Configuration.configData?.logger?.enable?.console?.toString() ??
Configuration.configData?.mode === 'development')
? 'true'
? Configuration.configData?.logger?.enable?.console?.toString()
: 'false';

if (Configuration.configData?.env?.values) {
const keys = Object.keys(Configuration.configData.env.values);
keys.forEach((key) => {
Expand All @@ -103,7 +104,15 @@ class Configuration {
public async getConfig(): Promise<JOOR_CONFIG> {
// Load the configuration data if not already loaded
if (Configuration.configData === null) {
await this.loadConfig();
try {
await this.loadConfig();
} catch (error: unknown) {
if (error instanceof Jrror || error instanceof JoorError) {
error.handle();
} else {
logger.error(error);
}
}
}

return Configuration.configData as JOOR_CONFIG;
Expand Down
2 changes: 1 addition & 1 deletion src/data/joor.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
const joorData = {
docs: 'https://joor.xyz/docs',
docs: 'https://joor.socioy.com',
currentVersion: '0.1',
docsVersion: 'v1',
};
Expand Down
3 changes: 2 additions & 1 deletion src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import { httpLogger, cors, serveStaticFiles } from '@/middlewares';
import env from '@/packages/env';
import Logger from '@/packages/logger';
import marker from '@/packages/marker';
import JOOR_CONFIG from '@/types/config';
import { JoorRequest } from '@/types/request';
import { ROUTE_HANDLER } from '@/types/route';

Expand All @@ -29,4 +30,4 @@ export {
};

// export types
export { JoorRequest, ROUTE_HANDLER };
export { JoorRequest, ROUTE_HANDLER, JOOR_CONFIG };
4 changes: 3 additions & 1 deletion src/packages/logger/logger.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ class Logger {
// Ensure that the log file has a .log extension
this.path = `${this.path}.log`;
}
this.originalPath = this.path;
this.formatCallBack = formatCallBack ?? this.formatCallBack; // Custom format callback, default is basic timestamped message
// Start interval to flush logs every 10 seconds by default
this.flushInterval = setInterval(() => {
Expand All @@ -61,6 +62,7 @@ class Logger {
// Default configuration for the logger
private name = 'logger'; // Default logger name
private path = nodePath.resolve(process.cwd(), 'logs.log'); // Default path for the log file
private originalPath = this.path; // Store the original path for potential future use
private formatCallBack: LOGGER_FORMAT_CALLBACK = (
timestamp: LOGGER_TIMESTAMP,
message: LOGGER_MESSAGE
Expand Down Expand Up @@ -143,7 +145,7 @@ class Logger {

if (fileStats.size > maxFileSize) {
// if file size exceeds 10MB, write to a new file
this.path = this.path.replace(
this.path = this.originalPath.replace(
'.log',
`-${new Date().toISOString()}.log`
);
Expand Down