Skip to content

Commit

Permalink
refactor: change logger label to module to better represent the use case
Browse files Browse the repository at this point in the history
  • Loading branch information
ADRFranklin committed Apr 28, 2024
1 parent 0e1164c commit 4a051e8
Show file tree
Hide file tree
Showing 30 changed files with 45 additions and 45 deletions.
2 changes: 1 addition & 1 deletion pkg/api/src/api/middleware/auth.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { Context, Next } from 'koa';
import loggerMain from '@/loaders/logger';
import { UserModel } from '@/models/user';

const logger = loggerMain.child({ label: 'middleware.auth' });
const logger = loggerMain.child({ module: 'middleware.auth' });

function removeCookie(ctx: Context) {
ctx.cookies.set('petio-jwt', null, { expires: new Date(Date.now() - 2000) });
Expand Down
2 changes: 1 addition & 1 deletion pkg/api/src/api/routes/login.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import { config } from '@/config/index';
import loggerMain from '@/loaders/logger';
import { GetUserByPlexID, UserModel, UserRole } from '@/models/user';

const logger = loggerMain.child({ label: 'routes.login' });
const logger = loggerMain.child({ module: 'routes.login' });

function success(ctx: Context, user: any, isAdmin = false): void {
const token = jwt.sign({ id: user.id, admin: isAdmin }, ctx.app.keys[0]);
Expand Down
2 changes: 1 addition & 1 deletion pkg/api/src/infra/arr/radarr/v4/calendar.ts
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ export const CalendarSchema = z.array(
z.object({
order: z.number(),
name: z.string(),
label: z.string(),
module: z.string(),
unit: z.string(),
helpText: z.string(),
helpLink: z.string(),
Expand Down
2 changes: 1 addition & 1 deletion pkg/api/src/infra/arr/radarr/v4/movie.ts
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ export const MovieSchema = z.object({
z.object({
order: z.number(),
name: z.string(),
label: z.string(),
module: z.string(),
unit: z.string(),
helpText: z.string(),
helpLink: z.string(),
Expand Down
4 changes: 2 additions & 2 deletions pkg/api/src/infra/arr/radarr/v4/queue.ts
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ export const QueueSchema = z.object({
z.object({
order: z.number(),
name: z.string(),
label: z.string(),
module: z.string(),
unit: z.string(),
helpText: z.string(),
helpLink: z.string(),
Expand Down Expand Up @@ -344,7 +344,7 @@ export const QueueSchema = z.object({
z.object({
order: z.number(),
name: z.string(),
label: z.string(),
module: z.string(),
unit: z.string().optional(),
helpText: z.string().optional(),
helpLink: z.string().optional(),
Expand Down
2 changes: 1 addition & 1 deletion pkg/api/src/infra/arr/radarr/v4/tag.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { makeApi } from '@zodios/core';
import { z } from 'zod';

export const TagSchema = z.object({
label: z.string(),
module: z.string(),
id: z.number(),
});
export type Tag = z.infer<typeof TagSchema>;
Expand Down
2 changes: 1 addition & 1 deletion pkg/api/src/infra/arr/sonarr/v3/tag.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { makeApi } from '@zodios/core';
import { z } from 'zod';

export const TagSchema = z.object({
label: z.string(),
module: z.string(),
id: z.number(),
});
export type Tag = z.infer<typeof TagSchema>;
Expand Down
2 changes: 1 addition & 1 deletion pkg/api/src/services/cron/service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import {
* Represents a base class for a cron service.
*/
export abstract class CronService {
private logger = Logger.getInstance().child({ label: 'services.cron' });
private logger = Logger.getInstance().child({ module: 'services.cron' });

constructor(private activeJobs: JobCronName[]) {}

Expand Down
4 changes: 2 additions & 2 deletions pkg/api/src/services/discovery/build.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ type ShowBuild = {
actors: Record<string, number>;
};

const logger = loggerMain.child({ label: 'discovery.build' });
const logger = loggerMain.child({ module: 'discovery.build' });

export default async (id: string) => {
try {
Expand Down Expand Up @@ -307,7 +307,7 @@ function buildCertification(certification: string, type: string) {

default:
logger.debug(`Unmapped Cert Rating - ${cert}`, {
label: 'discovery.build',
module: 'discovery.build',
});
return false;
}
Expand Down
6 changes: 3 additions & 3 deletions pkg/api/src/services/discovery/display.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ import is from '@/utils/is';
// eslint-disable-next-line import/order
import cache from '../cache/cache';

const logger = loggerMain.child({ label: 'discovery.display' });
const logger = loggerMain.child({ module: 'discovery.display' });

export type DiscoveryResult = {
popular: {
Expand Down Expand Up @@ -559,7 +559,7 @@ function genreID(genreName: any, type: string) {

default:
logger.debug(`DISC: Genre not mapped ${genreName}`, {
label: 'discovery.build',
module: 'discovery.build',
});
return false;
}
Expand Down Expand Up @@ -613,7 +613,7 @@ function genreID(genreName: any, type: string) {
return 37;
default:
logger.debug(`DISC: Genre not mapped ${genreName}`, {
label: 'discovery.build',
module: 'discovery.build',
});
return false;
}
Expand Down
2 changes: 1 addition & 1 deletion pkg/api/src/services/discovery/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import cache from '../cache/cache';
import build from './build';
import display from './display';

const logger = loggerMain.child({ label: 'services.discovery' });
const logger = loggerMain.child({ module: 'services.discovery' });

export default async () => {
logger.debug('started building discovery profiles');
Expand Down
2 changes: 1 addition & 1 deletion pkg/api/src/services/downloaders/radarr.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import {
} from '@/models/downloaders';
import Request from '@/models/request';

const logger = loggerMain.child({ label: 'downloaders.radarr' });
const logger = loggerMain.child({ module: 'downloaders.radarr' });

export default class Radarr {
instance: IDownloader;
Expand Down
2 changes: 1 addition & 1 deletion pkg/api/src/services/downloaders/sonarr.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import {
} from '@/models/downloaders';
import Request from '@/models/request';

const logger = loggerMain.child({ label: 'downloaders.sonarr' });
const logger = loggerMain.child({ module: 'downloaders.sonarr' });

export default class Sonarr {
instance: IDownloader;
Expand Down
2 changes: 1 addition & 1 deletion pkg/api/src/services/fanart/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import loggerMain from '@/loaders/logger';

import cache from '../cache/cache';

const logger = loggerMain.child({ label: 'fanart.index' });
const logger = loggerMain.child({ module: 'fanart.index' });

export default async (id: string, type: any) => {
let data: any = {};
Expand Down
2 changes: 1 addition & 1 deletion pkg/api/src/services/mail/mailer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import nodemailer from 'nodemailer';
import { config } from '@/config/index';
import loggerMain from '@/loaders/logger';

const logger = loggerMain.child({ label: 'mail.mailer' });
const logger = loggerMain.child({ module: 'mail.mailer' });

export default class Mailer {
transport: any;
Expand Down
4 changes: 2 additions & 2 deletions pkg/api/src/services/meta/imdb.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import pathsConfig from '@/config/env/paths';
import loggerMain from '@/loaders/logger';
import Imdb from '@/models/imdb';

const logger = loggerMain.child({ label: 'meta.imdb' });
const logger = loggerMain.child({ module: 'meta.imdb' });

export async function lookup(imdb_id) {
if (!imdb_id) {
Expand Down Expand Up @@ -36,7 +36,7 @@ export async function storeCache(firstTime = false) {
logger.debug('IMDB: Rebuilding Cache');
try {
logger.debug('IMDB: Cache Downloading latest cache', {
label: 'meta.imdb',
module: 'meta.imdb',
});
const res = await axios({
url: 'https://datasets.imdbws.com/title.ratings.tsv.gz',
Expand Down
2 changes: 1 addition & 1 deletion pkg/api/src/services/notifications/discord.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import axios from 'axios';
import { config } from '@/config/index';
import loggerMain from '@/loaders/logger';

const logger = loggerMain.child({ label: 'notifications.discord' });
const logger = loggerMain.child({ module: 'notifications.discord' });

export default class Discord {
webhook: any;
Expand Down
2 changes: 1 addition & 1 deletion pkg/api/src/services/notifications/notification.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ export const getNotificationProvider = (
export class BaseNotification<T extends INotification> {
protected config: T;

public logger = logger.child({ label: 'notification.service' });
public logger = logger.child({ module: 'notification.service' });

constructor(config: T) {
this.config = config;
Expand Down
16 changes: 8 additions & 8 deletions pkg/api/src/services/notifications/telegram.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,30 +33,30 @@ export default class Telegram {
async test() {
if (!this.check()) {
logger.debug('Telegram: Chat id or bot token missing', {
label: 'notifications.telegram',
module: 'notifications.telegram',
});
return {
result: false,
error: 'Chat id or bot token missing',
};
}
logger.debug('Telegram: Sending test message', {
label: 'notifications.telegram',
module: 'notifications.telegram',
});
const defaultText: any = 'Petio Test';
const text = this.buildText(defaultText);
const test = await this.postMessage(text);
if (!test) {
logger.debug('Telegram: Test Failed', {
label: 'notifications.telegram',
module: 'notifications.telegram',
});
return {
result: false,
error: 'Failed to send message',
};
}
logger.debug('Telegram: Test passed', {
label: 'notifications.telegram',
module: 'notifications.telegram',
});
return {
result: true,
Expand All @@ -67,15 +67,15 @@ export default class Telegram {
send(title = null, content = null, username = null, image = null) {
if (!this.check()) {
logger.debug('Telegram: No config defined', {
label: 'notifications.telegram',
module: 'notifications.telegram',
});
return {
result: false,
error: 'No config found',
};
}
logger.debug(`Telegram: Sending message - ${content}`, {
label: 'notifications.telegram',
module: 'notifications.telegram',
});
const text = this.buildText(null, {
title,
Expand Down Expand Up @@ -103,12 +103,12 @@ export default class Telegram {
},
);
logger.debug('Telegram: message sent', {
label: 'notifications.telegram',
module: 'notifications.telegram',
});
return true;
} catch (err) {
logger.debug('Telegram: Failed to send message', {
label: 'notifications.telegram',
module: 'notifications.telegram',
});
return false;
}
Expand Down
2 changes: 1 addition & 1 deletion pkg/api/src/services/plex/bandwidth.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import axios from 'axios';
import loggerMain from '@/loaders/logger';
import MakePlexURL from '@/services/plex/util';

const logger = loggerMain.child({ label: 'plex.bandwidth' });
const logger = loggerMain.child({ module: 'plex.bandwidth' });

function timeDifference(previous) {
const now = new Date();
Expand Down
2 changes: 1 addition & 1 deletion pkg/api/src/services/plex/history.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import { showLookup } from '@/services/tmdb/show';

import cache from '../cache/cache';

const logger = loggerMain.child({ label: 'plex.history' });
const logger = loggerMain.child({ module: 'plex.history' });

export default async (id, type) => {
let data: any = false;
Expand Down
4 changes: 2 additions & 2 deletions pkg/api/src/services/plex/library.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import Telegram from '@/services/notifications/telegram';
import ProcessRequest from '@/services/requests/process';
import { showLookup } from '@/services/tmdb/show';

const logger = loggerMain.child({ label: 'plex.library' });
const logger = loggerMain.child({ module: 'plex.library' });

export default class LibraryUpdate {
full: any;
Expand Down Expand Up @@ -260,7 +260,7 @@ export default class LibraryUpdate {
const libContent = await this.getLibrary(lib.key);
if (!libContent || !libContent.Metadata) {
logger.warn(`CRON: No content in library skipping - ${lib.title}`, {
label: 'plex.library',
module: 'plex.library',
});
return;
}
Expand Down
2 changes: 1 addition & 1 deletion pkg/api/src/services/plex/top.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import is from '@/utils/is';
// eslint-disable-next-line import/order
import cache from '../cache/cache';

const logger = loggerMain.child({ label: 'plex.top' });
const logger = loggerMain.child({ module: 'plex.top' });
export default async (type: 1 | 2) => {
try {
return await cache.wrap(`popular__${type}`, async () => getTopData(type));
Expand Down
2 changes: 1 addition & 1 deletion pkg/api/src/services/requests/filter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ export default async (item) => {
(optionalMatch > 0 || f.rows.length === 1)
) {
logger.info(`FILT: Match on filter ${i + 1}`, {
label: 'requests.filter',
module: 'requests.filter',
});
action = f.action;
}
Expand Down
2 changes: 1 addition & 1 deletion pkg/api/src/services/requests/process.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import Telegram from '@/services/notifications/telegram';
import filter from '@/services/requests/filter';
import { showLookup } from '@/services/tmdb/show';

const logger = loggerMain.child({ label: 'requests.process' });
const logger = loggerMain.child({ module: 'requests.process' });

export default class ProcessRequest {
request: any;
Expand Down
2 changes: 1 addition & 1 deletion pkg/api/src/services/tmdb/movie.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import cache from '../cache/cache';

const agent = new http.Agent({ family: 4 });

const logger = loggerMain.child({ label: 'tmdb.movie' });
const logger = loggerMain.child({ module: 'tmdb.movie' });

export async function movieLookup(id, minified = false) {
logger.debug(`TMDB Movie Lookup ${id}`);
Expand Down
2 changes: 1 addition & 1 deletion pkg/api/src/services/tmdb/person.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ const agent = new http.Agent({ family: 4 });

async function personLookup(id) {
logger.debug(`TMDB Person Lookup ${id}`, {
label: 'tmdb.person',
module: 'tmdb.person',
});
const info = await getPersonInfo(id);
const movies = await getPersonMovies(id);
Expand Down
2 changes: 1 addition & 1 deletion pkg/api/src/services/tmdb/search.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import { showLookup } from '@/services/tmdb/show';

const agent = new http.Agent({ family: 4 });

const logger = loggerMain.child({ label: 'tmdb.search' });
const logger = loggerMain.child({ module: 'tmdb.search' });

async function search(term) {
logger.debug(`TMDB Search ${term}`);
Expand Down
2 changes: 1 addition & 1 deletion pkg/api/src/services/tmdb/show.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import cache from '../cache/cache';

const agent = new http.Agent({ family: 4 });

const logger = loggerMain.child({ label: 'tmdb.show' });
const logger = loggerMain.child({ module: 'tmdb.show' });

export async function showLookup(id, minified = false) {
if (!id || id === 'false') {
Expand Down
Loading

0 comments on commit 4a051e8

Please sign in to comment.