Skip to content

Commit

Permalink
Remove own logging references
Browse files Browse the repository at this point in the history
  • Loading branch information
FoxxMD committed Mar 20, 2024
1 parent d6600ed commit a303bae
Show file tree
Hide file tree
Showing 11 changed files with 36 additions and 57 deletions.
9 changes: 4 additions & 5 deletions src/EndlessFileParser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,7 @@ import {parseEndlessLogLine} from "./utils/index.js";
import path from "path";
import {EndlessLogLine} from "./common/infrastructure/Atomic.js";
import {TypedEventEmitter} from "./utils/TypedEventEmitter.js";
import {AppLogger} from "./common/logging.js";
import { childLogger } from "@foxxmd/logging";
import {childLogger, Logger} from "@foxxmd/logging";

const endlessFileNames = ['current', 'endlessh.INFO'];

Expand All @@ -19,9 +18,9 @@ type EndlessFileEventTypes = {
export class EndlessFileParser extends TypedEventEmitter<EndlessFileEventTypes> {

tailFile: TailFile;
logger: AppLogger;
logger: Logger;

constructor(file: TailFile, logger: AppLogger) {
constructor(file: TailFile, logger: Logger) {
super();
this.tailFile = file;
this.logger = childLogger(logger, 'Parser'); //logger.child({labels: ['Parser']}, mergeArr);
Expand Down Expand Up @@ -72,7 +71,7 @@ export class EndlessFileParser extends TypedEventEmitter<EndlessFileEventTypes>
}
}

public static async fromFile(dir: string, logger: AppLogger) {
public static async fromFile(dir: string, logger: Logger) {
const cl = childLogger(logger, 'Parser'); // logger.child({labels: ['Parser']}, mergeArr);
for(const name of endlessFileNames) {
const filePath = path.resolve(dir, `./${name}`);
Expand Down
7 changes: 3 additions & 4 deletions src/GeoLookup.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,13 @@ import {IPDataFields} from "./common/infrastructure/Atomic.js";
import {Address4, Address6} from "ip-address";
import {defaultApiApiQuery, getIpGeolocation, IPDataResponse} from "./ipApi.js";
import {ErrorWithCause} from "pony-cause";
import {AppLogger} from "./common/logging.js";
import { childLogger } from "@foxxmd/logging";
import {childLogger, Logger} from "@foxxmd/logging";

export class GeoLookup {
cache: LRUCache<string, IPDataFields> = new LRUCache({max: 500})
logger: AppLogger
logger: Logger

constructor(logger: AppLogger) {
constructor(logger: Logger) {
this.logger = childLogger(logger, 'Geo Lookup'); // logger.child({labels: ['Geo Lookup']}, mergeArr)

}
Expand Down
15 changes: 4 additions & 11 deletions src/GeoQueue.ts
Original file line number Diff line number Diff line change
@@ -1,16 +1,9 @@
import {
EndlessGeoLog,
EndlessLog,
EndlessLogLine,
EndlessStatLog,
IPDataFields
} from "./common/infrastructure/Atomic.js";
import {EndlessLog, EndlessStatLog, IPDataFields} from "./common/infrastructure/Atomic.js";
import {TypedEventEmitter} from "./utils/TypedEventEmitter.js";
import {sleep} from "./utils/index.js";
import {queue, QueueObject} from 'async';
import {GeoLookup} from "./GeoLookup.js";
import {AppLogger} from "./common/logging.js";
import { childLogger } from "@foxxmd/logging";
import {childLogger, Logger} from "@foxxmd/logging";

type GeoHydratedLogLineEvents = {
'log': [log: EndlessLog]
Expand All @@ -22,11 +15,11 @@ interface GeoTask {

export class GeoQueue extends TypedEventEmitter<GeoHydratedLogLineEvents> {

logger: AppLogger;
logger: Logger;
queue: QueueObject<GeoTask>
lookup: GeoLookup;

constructor(logger: AppLogger) {
constructor(logger: Logger) {
super();
this.logger = childLogger(logger, 'Geo Queue');// logger.child({labels: ['Geo Queue']}, mergeArr);
this.lookup = new GeoLookup(this.logger);
Expand Down
7 changes: 3 additions & 4 deletions src/MapImageService.ts
Original file line number Diff line number Diff line change
@@ -1,16 +1,15 @@
import {LRUCache} from "lru-cache";
import {ErrorWithCause} from "pony-cause";
import got from 'got';
import {AppLogger} from "./common/logging.js";
import { childLogger } from "@foxxmd/logging";
import {childLogger, Logger} from "@foxxmd/logging";

export class MapImageService {

mapquestKey?: string;
imageCache: LRUCache<string, Buffer> = new LRUCache({max: 100});
logger: AppLogger;
logger: Logger;

constructor(logger: AppLogger, mapquestKey?: string) {
constructor(logger: Logger, mapquestKey?: string) {
this.logger = childLogger(logger, 'Map Image'); // logger.child({labels: ['Map Image']}, mergeArr);
this.mapquestKey = mapquestKey;
if (this.mapquestKey !== undefined) {
Expand Down
3 changes: 0 additions & 3 deletions src/common/logging.ts

This file was deleted.

9 changes: 4 additions & 5 deletions src/notifier/AbstractWebhookNotifier.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,12 @@ import {ErrorWithCause} from "pony-cause";
import TTLCache from '@isaacs/ttlcache';
import dayjs, {Dayjs} from "dayjs";
import {EndlessCloseLogLine} from "../common/infrastructure/Atomic.js";
import {AppLogger} from "../common/logging.js";
import { childLogger } from "@foxxmd/logging";
import {childLogger, Logger} from "@foxxmd/logging";

interface HydratedEventTypeCommon extends Omit<EventTypeCommon, 'debounceInterval'> {
debounceInterval: Duration
cache: TTLCache<string, Dayjs>
logger: AppLogger
logger: Logger
}

type HydratedEventTypeAccept = Omit<EventTypeAccept, 'debounceInterval'> & HydratedEventTypeCommon
Expand All @@ -32,7 +31,7 @@ type HydratedEventTypeClose = HydratedEventTypeCommon & Omit<EventTypeClose, 'de
export abstract class AbstractWebhookNotifier {

config: WebhookConfig
logger: AppLogger;
logger: Logger;

initialized: boolean = false;
requiresAuth: boolean = false;
Expand All @@ -45,7 +44,7 @@ export abstract class AbstractWebhookNotifier {
acceptEvents: HydratedEventTypeAccept[] = [];
closeEvents: HydratedEventTypeClose[] = [];

protected constructor(notifierType: string, defaultName: string, config: WebhookConfig, logger: AppLogger) {
protected constructor(notifierType: string, defaultName: string, config: WebhookConfig, logger: Logger) {
this.config = config;
const label = `${notifierType} - ${config.name ?? defaultName}`
this.logger = childLogger(logger, label); //logger.child({labels: [label]}, mergeArr);
Expand Down
8 changes: 4 additions & 4 deletions src/notifier/DiscordWebhookNotifier.ts
Original file line number Diff line number Diff line change
@@ -1,19 +1,19 @@
import {AbstractWebhookNotifier} from "./AbstractWebhookNotifier.js";
import {APIEmbed, AttachmentBuilder, BaseMessageOptions, EmbedBuilder, WebhookClient, time} from "discord.js";
import {APIEmbed, AttachmentBuilder, time, WebhookClient} from "discord.js";
import {DiscordConfig, WebhookPayload} from "../common/infrastructure/webhooks.js";
import {ErrorWithCause} from "pony-cause";
import dayjs from "dayjs";
import {doubleReturnNewline, durationToHuman, plainTag} from "../utils/index.js";
import {doubleReturnNewline, durationToHuman} from "../utils/index.js";
import {MapImageService} from "../MapImageService.js";
import {AppLogger} from "../common/logging.js";
import {Logger} from "@foxxmd/logging";

export class DiscordWebhookNotifier extends AbstractWebhookNotifier {

declare config: DiscordConfig;
imageService: MapImageService;
client: WebhookClient;

constructor(defaultName: string, config: DiscordConfig, imageService: MapImageService, logger: AppLogger) {
constructor(defaultName: string, config: DiscordConfig, imageService: MapImageService, logger: Logger) {
super('Discord', defaultName, config, logger);
this.requiresAuth = false;
this.client = new WebhookClient({url: config.webhook})
Expand Down
6 changes: 3 additions & 3 deletions src/notifier/GotifyWebhookNotifier.ts
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
import { AbstractWebhookNotifier } from "./AbstractWebhookNotifier.js";
import {AbstractWebhookNotifier} from "./AbstractWebhookNotifier.js";
import {gotify} from 'gotify';
import got, {HTTPError} from "got";
import {GotifyConfig, PrioritiesConfig, WebhookPayload} from "../common/infrastructure/webhooks.js";
import {durationToHuman} from "../utils/index.js";
import {AppLogger} from "../common/logging.js";
import {Logger} from "@foxxmd/logging";

export class GotifyWebhookNotifier extends AbstractWebhookNotifier {

declare config: GotifyConfig;

priorities: PrioritiesConfig;

constructor(defaultName: string, config: GotifyConfig, logger: AppLogger) {
constructor(defaultName: string, config: GotifyConfig, logger: Logger) {
super('Gotify', defaultName, config, logger);
this.requiresAuth = true;
const {
Expand Down
9 changes: 4 additions & 5 deletions src/notifier/Notifiers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import {AbstractWebhookNotifier} from "./AbstractWebhookNotifier.js";
import {GotifyWebhookNotifier} from "./GotifyWebhookNotifier.js";
import {NtfyWebhookNotifier} from "./NtfyWebhookNotifier.js";
import {EventEmitter} from "events";
import {mergeArr, sleep} from "../utils/index.js";
import {sleep} from "../utils/index.js";
import {
DiscordConfig,
GotifyConfig,
Expand All @@ -14,16 +14,15 @@ import {DiscordWebhookNotifier} from "./DiscordWebhookNotifier.js";
import {queue, QueueObject} from 'async';
import {EndlessLog} from "../common/infrastructure/Atomic.js";
import {MapImageService} from "../MapImageService.js";
import {AppLogger} from "../common/logging.js";
import { childLogger } from "@foxxmd/logging";
import {childLogger, Logger} from "@foxxmd/logging";

interface NotifyTask {
log: EndlessLog
}

export class Notifiers {

logger: AppLogger;
logger: Logger;

webhooks: AbstractWebhookNotifier[] = [];

Expand All @@ -33,7 +32,7 @@ export class Notifiers {

queue: QueueObject<NotifyTask>;

constructor(logger: AppLogger, mapquestKey?: string) {
constructor(logger: Logger, mapquestKey?: string) {

this.logger = childLogger(logger, 'Notifiers'); // logger.child({labels: ['Notifiers']}, mergeArr);
this.queue = this.generateQueue();
Expand Down
6 changes: 3 additions & 3 deletions src/notifier/NtfyWebhookNotifier.ts
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
import { AbstractWebhookNotifier } from "./AbstractWebhookNotifier.js";
import {AbstractWebhookNotifier} from "./AbstractWebhookNotifier.js";
import {Config, publish} from 'ntfy';
import got from 'got';
import {NtfyConfig, PrioritiesConfig, WebhookPayload} from "../common/infrastructure/webhooks.js";
import {durationToHuman} from "../utils/index.js";
import {AppLogger} from "../common/logging.js";
import {Logger} from "@foxxmd/logging";

export class NtfyWebhookNotifier extends AbstractWebhookNotifier {

declare config: NtfyConfig;

priorities: PrioritiesConfig;

constructor(defaultName: string, config: NtfyConfig, logger: AppLogger) {
constructor(defaultName: string, config: NtfyConfig, logger: Logger) {
super('Ntfy', defaultName, config, logger);
const {
info = 3,
Expand Down
14 changes: 4 additions & 10 deletions src/utils/index.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,5 @@
import dayjs, {Dayjs} from "dayjs";
import {AppLogger} from "../common/logging.js";
import {
replaceResultTransformer,
stripIndentTransformer,
TemplateTag,
TemplateTransformer,
trimResultTransformer
} from 'common-tags'
import {replaceResultTransformer, stripIndentTransformer, TemplateTag, trimResultTransformer} from 'common-tags'
import {
EndlessLog,
EndlessLogLine,
Expand All @@ -19,6 +12,7 @@ import {Duration} from "dayjs/plugin/duration.js";
import {ErrorWithCause, getErrorCause} from "pony-cause";
import InvalidRegexError from "../common/errors/InvalidRegexError.js";
import {Address4, Address6} from "ip-address";
import {Logger} from "@foxxmd/logging";

export const overwriteMerge = (destinationArray: any[], sourceArray: any[], options: any): any[] => sourceArray;

Expand Down Expand Up @@ -98,9 +92,9 @@ export class RateLimitFunc {
public lastExecute?: Dayjs;
public msBetween: number;
protected shouldWait: boolean;
protected logger?: AppLogger;
protected logger?: Logger;

constructor(msBetween: number, shouldWait: boolean, logger?: AppLogger) {
constructor(msBetween: number, shouldWait: boolean, logger?: Logger) {
this.msBetween = msBetween;
this.lastExecute = dayjs().subtract(msBetween + 1, 'ms');
this.logger = logger;
Expand Down

0 comments on commit a303bae

Please sign in to comment.