generated from nhcarrigan/template
Compare commits
No commits in common. "d46fba2bfc1855d11c3765eacccf2a160f12e809" and "33ef4dedd136f55f21a4acb489c8326d16615eab" have entirely different histories.
d46fba2bfc
...
33ef4dedd1
@ -1,38 +0,0 @@
|
|||||||
name: Node.js CI
|
|
||||||
on:
|
|
||||||
push:
|
|
||||||
branches:
|
|
||||||
- main
|
|
||||||
pull_request:
|
|
||||||
branches:
|
|
||||||
- main
|
|
||||||
|
|
||||||
jobs:
|
|
||||||
lint:
|
|
||||||
name: Lint and Test
|
|
||||||
|
|
||||||
steps:
|
|
||||||
- name: Checkout Source Files
|
|
||||||
uses: actions/checkout@v4
|
|
||||||
|
|
||||||
- name: Use Node.js v22
|
|
||||||
uses: actions/setup-node@v4
|
|
||||||
with:
|
|
||||||
node-version: 22
|
|
||||||
|
|
||||||
- name: Setup pnpm
|
|
||||||
uses: pnpm/action-setup@v2
|
|
||||||
with:
|
|
||||||
version: 9
|
|
||||||
|
|
||||||
- name: Install Dependencies
|
|
||||||
run: pnpm install
|
|
||||||
|
|
||||||
- name: Lint Source Files
|
|
||||||
run: pnpm run lint
|
|
||||||
|
|
||||||
- name: Verify Build
|
|
||||||
run: pnpm run build
|
|
||||||
|
|
||||||
- name: Run Tests
|
|
||||||
run: pnpm run test
|
|
6
.gitignore
vendored
6
.gitignore
vendored
@ -1,6 +0,0 @@
|
|||||||
node_modules
|
|
||||||
prod
|
|
||||||
coverage
|
|
||||||
|
|
||||||
# Ignore packed files so that npm pack can be run locally
|
|
||||||
*.tgz
|
|
@ -1,9 +0,0 @@
|
|||||||
/.gitea/
|
|
||||||
/.vscode/
|
|
||||||
eslint.config.js
|
|
||||||
.gitattributes
|
|
||||||
.gitignore
|
|
||||||
/src/
|
|
||||||
|
|
||||||
# Ignore packed files so that npm pack can be run locally
|
|
||||||
*.tgz
|
|
6
.vscode/settings.json
vendored
6
.vscode/settings.json
vendored
@ -1,6 +0,0 @@
|
|||||||
{
|
|
||||||
"editor.codeActionsOnSave": {
|
|
||||||
"source.fixAll.eslint": "explicit"
|
|
||||||
},
|
|
||||||
"eslint.validate": ["typescript"]
|
|
||||||
}
|
|
16
README.md
16
README.md
@ -1,10 +1,20 @@
|
|||||||
# Logger
|
# New Repository Template
|
||||||
|
|
||||||
This is a custom logging utility which pipes errors and log messages to our alerting system.
|
This template contains all of our basic files for a new GitHub repository. There is also a handy workflow that will create an issue on a new repository made from this template, with a checklist for the steps we usually take in setting up a new repository.
|
||||||
|
|
||||||
|
If you're starting a Node.JS project with TypeScript, we have a [specific template](https://github.com/naomi-lgbt/nodejs-typescript-template) for that purpose.
|
||||||
|
|
||||||
|
## Readme
|
||||||
|
|
||||||
|
Delete all of the above text (including this line), and uncomment the below text to use our standard readme template.
|
||||||
|
|
||||||
|
<!-- # Project Name
|
||||||
|
|
||||||
|
Project Description
|
||||||
|
|
||||||
## Live Version
|
## Live Version
|
||||||
|
|
||||||
This page is currently deployed. [View the live website.](https://www.npmjs.com/package/@nhcarrigan/logger)
|
This page is currently deployed. [View the live website.]
|
||||||
|
|
||||||
## Feedback and Bugs
|
## Feedback and Bugs
|
||||||
|
|
||||||
|
@ -1,5 +0,0 @@
|
|||||||
import NaomisConfig from "@nhcarrigan/eslint-config";
|
|
||||||
|
|
||||||
export default [
|
|
||||||
...NaomisConfig
|
|
||||||
]
|
|
30
package.json
30
package.json
@ -1,30 +0,0 @@
|
|||||||
{
|
|
||||||
"name": "@nhcarrigan/logger",
|
|
||||||
"version": "0.0.1",
|
|
||||||
"description": "Our custom logging package, which pipes logs to our alerts server.",
|
|
||||||
"type": "module",
|
|
||||||
"main": "prod/index.js",
|
|
||||||
"scripts": {
|
|
||||||
"lint": "eslint src --max-warnings 0",
|
|
||||||
"build": "rm -rf prod && tsc",
|
|
||||||
"test": "echo \"Error: no test specified\" && exit 0"
|
|
||||||
},
|
|
||||||
"repository": {
|
|
||||||
"type": "git",
|
|
||||||
"url": "https://git.nhcarrigan.com/nhcarrigan/logger.git"
|
|
||||||
},
|
|
||||||
"keywords": [],
|
|
||||||
"author": "",
|
|
||||||
"license": "See license in LICENSE.md",
|
|
||||||
"bugs": {
|
|
||||||
"url": "https://git.nhcarrigan.com/nhcarrigan/logger/issues"
|
|
||||||
},
|
|
||||||
"homepage": "https://git.nhcarrigan.com/nhcarrigan/logger",
|
|
||||||
"devDependencies": {
|
|
||||||
"@nhcarrigan/eslint-config": "5.1.0",
|
|
||||||
"@nhcarrigan/typescript-config": "4.0.0",
|
|
||||||
"@types/node": "22.13.1",
|
|
||||||
"eslint": "9.20.0",
|
|
||||||
"typescript": "5.7.3"
|
|
||||||
}
|
|
||||||
}
|
|
3990
pnpm-lock.yaml
generated
3990
pnpm-lock.yaml
generated
File diff suppressed because it is too large
Load Diff
74
src/index.ts
74
src/index.ts
@ -1,74 +0,0 @@
|
|||||||
/**
|
|
||||||
* @copyright nhcarrigan
|
|
||||||
* @license Naomi's Public License
|
|
||||||
* @author Naomi Carrigan
|
|
||||||
*/
|
|
||||||
|
|
||||||
import type { Level } from "./types/level.js";
|
|
||||||
|
|
||||||
/**
|
|
||||||
* This is a wrapper around our custom alert monitoring server. This class
|
|
||||||
* allows you to pipe errors and log messages to our server.
|
|
||||||
*/
|
|
||||||
export class Logger {
|
|
||||||
private readonly url: string;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Instantiates the class.
|
|
||||||
* @param application -- The name of the application (this will appear in logs).
|
|
||||||
* @param token -- Your API token for the monitoring service.
|
|
||||||
* @param url -- (Optional) The URL for your own alerting instance.
|
|
||||||
*/
|
|
||||||
public constructor(
|
|
||||||
private readonly application: string,
|
|
||||||
private readonly token: string,
|
|
||||||
url?: string,
|
|
||||||
) {
|
|
||||||
this.url = url ?? "https://alerts.nhcarrigan.com";
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Sends a log message to the alerting service.
|
|
||||||
* @param level -- The level of the log message.
|
|
||||||
* @param message -- The message to send.
|
|
||||||
*/
|
|
||||||
public async log(level: Level, message: string): Promise<void> {
|
|
||||||
await fetch(`${this.url}/log`, {
|
|
||||||
body: JSON.stringify({
|
|
||||||
application: this.application,
|
|
||||||
level: level,
|
|
||||||
message: message,
|
|
||||||
}),
|
|
||||||
headers: {
|
|
||||||
// eslint-disable-next-line @typescript-eslint/naming-convention -- Standard header name.
|
|
||||||
"Authorization": this.token,
|
|
||||||
// eslint-disable-next-line @typescript-eslint/naming-convention -- Standard header name.
|
|
||||||
"Content-Type": "application/json",
|
|
||||||
},
|
|
||||||
method: "POST",
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Sends an error to the alerting service.
|
|
||||||
* @param context -- A brief description of where the error occurred (E.G. Function name).
|
|
||||||
* @param error -- The Node.js error object.
|
|
||||||
*/
|
|
||||||
public async error(context: string, error: Error): Promise<void> {
|
|
||||||
await fetch(`${this.url}/error`, {
|
|
||||||
body: JSON.stringify({
|
|
||||||
application: this.application,
|
|
||||||
context: context,
|
|
||||||
message: error.message,
|
|
||||||
stack: error.stack ?? "No stack trace available.",
|
|
||||||
}),
|
|
||||||
headers: {
|
|
||||||
// eslint-disable-next-line @typescript-eslint/naming-convention -- Standard header name.
|
|
||||||
"Authorization": this.token,
|
|
||||||
// eslint-disable-next-line @typescript-eslint/naming-convention -- Standard header name.
|
|
||||||
"Content-Type": "application/json",
|
|
||||||
},
|
|
||||||
method: "POST",
|
|
||||||
});
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,12 +0,0 @@
|
|||||||
/**
|
|
||||||
* @copyright nhcarrigan
|
|
||||||
* @license Naomi's Public License
|
|
||||||
* @author Naomi Carrigan
|
|
||||||
*/
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Defines the levels we allow for logging. This is honestly
|
|
||||||
* entirely arbitrary, but ensures some level of consistency across
|
|
||||||
* our production applications.
|
|
||||||
*/
|
|
||||||
export type Level = "debug" | "info" | "warn";
|
|
@ -1,10 +0,0 @@
|
|||||||
{
|
|
||||||
"extends": "@nhcarrigan/typescript-config",
|
|
||||||
"compilerOptions": {
|
|
||||||
"rootDir": "./src",
|
|
||||||
"outDir": "./prod",
|
|
||||||
"sourceMap": true,
|
|
||||||
"declaration": true
|
|
||||||
},
|
|
||||||
"exclude": ["test/**/*.ts", "vitest.config.ts"]
|
|
||||||
}
|
|
Loading…
x
Reference in New Issue
Block a user