Initialize and use bunyan logger

This commit is contained in:
Valentin Brandl 2024-08-17 15:06:12 +02:00
parent 4e2b1b74a4
commit 824852fe7a
Signed by: vbrandl
GPG Key ID: CAD4DA1A789125F9

View File

@ -1,5 +1,12 @@
// place files you want to import through the `$lib` alias in this folder. // place files you want to import through the `$lib` alias in this folder.
import path from 'path'; import path from 'path';
import bunyan from 'bunyan';
export const log = bunyan.createLogger({
name: 'fotochallenge',
level: process.env.NODE_ENV === 'production' ? 'info' : 'debug',
src: true
});
function safePath(basePath: string, name: string): boolean { function safePath(basePath: string, name: string): boolean {
const fullPath = `${basePath}/${name}`; const fullPath = `${basePath}/${name}`;
@ -17,7 +24,7 @@ function safePath(basePath: string, name: string): boolean {
const defaultPath: string = './uploads'; const defaultPath: string = './uploads';
if (!('STORAGE_PATH' in process.env)) { if (!('STORAGE_PATH' in process.env)) {
console.warn(`'STORAGE_PATH' environment variable is not set. Defaulting to ${defaultPath}`); log.warn(`'STORAGE_PATH' environment variable is not set. Defaulting to ${defaultPath}`);
} }
export const storagePath: string = process.env.STORAGE_PATH ?? defaultPath; export const storagePath: string = process.env.STORAGE_PATH ?? defaultPath;