Skip to content
This repository was archived by the owner on May 16, 2024. It is now read-only.

Commit 9ef4501

Browse files
authored
Merge pull request #25 from zerodays/feat/custom-axiom-logging
Feat/custom axiom logging
2 parents 72ce256 + 441eba9 commit 9ef4501

File tree

10 files changed

+74
-12
lines changed

10 files changed

+74
-12
lines changed

.eslintrc.json

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
}
2222
},
2323
"rules": {
24+
"no-console": "error",
2425
"@typescript-eslint/no-unused-vars": "error",
2526
"@typescript-eslint/no-explicit-any": "error",
2627
"react/react-in-jsx-scope": "off",
@@ -31,6 +32,17 @@
3132
"./src/**/*.{js,ts}": "KEBAB_CASE"
3233
},
3334
{ "ignoreMiddleExtensions": true }
35+
],
36+
"@typescript-eslint/no-restricted-imports": [
37+
"error",
38+
{
39+
"paths": [
40+
{
41+
"name": "next-axiom",
42+
"message": "For client side logging import from log-client, for server actions and server components import from log-server"
43+
}
44+
]
45+
}
3446
]
3547
}
3648
}

.prettierrc.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,5 +31,5 @@ module.exports = {
3131
],
3232
importOrderParserPlugins: ['typescript', 'jsx', 'decorators-legacy'],
3333
importOrderTypeScriptVersion: '5.0.0',
34-
plugins: [require('prettier-plugin-tailwindcss')],
34+
plugins: ['prettier-plugin-tailwindcss'],
3535
};

next.config.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
/* eslint-disable @typescript-eslint/no-var-requires */
22
const { withSentryConfig } = require('@sentry/nextjs');
3+
const {withAxiom} = require("next-axiom")
34
const withBundleAnalyzer = require('@next/bundle-analyzer')({
45
enabled: process.env.ANALYZE === 'true',
56
});
@@ -10,7 +11,7 @@ const nextConfig = {
1011
};
1112

1213
module.exports = withBundleAnalyzer(
13-
withSentryConfig(
14+
withAxiom(withSentryConfig(
1415
nextConfig,
1516
{
1617
// For all available options, see:
@@ -42,4 +43,4 @@ module.exports = withBundleAnalyzer(
4243
disableLogger: true,
4344
},
4445
),
45-
);
46+
));

package.json

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
"@sentry/nextjs": "7.77.0",
2121
"autoprefixer": "10.4.14",
2222
"next": "^14.0.0",
23+
"next-axiom": "^1.1.0",
2324
"next-international": "^1.1.3",
2425
"postcss": "8.4.31",
2526
"react": "^18.2.0",
@@ -30,16 +31,16 @@
3031
"zod": "^3.22.3"
3132
},
3233
"devDependencies": {
33-
"@types/node": "^20.8.9",
34-
"@types/react": "^18.2.33",
35-
"@types/react-dom": "^18.2.14",
3634
"@commitlint/cli": "^18.2.0",
3735
"@commitlint/config-conventional": "^18.1.0",
3836
"@commitlint/prompt-cli": "^18.2.0",
3937
"@ianvs/prettier-plugin-sort-imports": "^4.1.1",
4038
"@testing-library/jest-dom": "^6.1.4",
4139
"@testing-library/react": "^14.0.0",
4240
"@types/jest": "^29.5.7",
41+
"@types/node": "^20.8.9",
42+
"@types/react": "^18.2.33",
43+
"@types/react-dom": "^18.2.14",
4344
"@typescript-eslint/eslint-plugin": "^6.9.1",
4445
"eslint": "^8.52.0",
4546
"eslint-config-next": "^14.0.1",
@@ -51,8 +52,8 @@
5152
"husky": "^8.0.3",
5253
"jest": "^29.7.0",
5354
"jest-environment-jsdom": "^29.7.0",
54-
"prettier": "^3.0.3",
55-
"prettier-plugin-tailwindcss": "^0.5.6",
55+
"prettier": "^3.1.0",
56+
"prettier-plugin-tailwindcss": "^0.5.7",
5657
"ts-jest": "^29.1.1",
5758
"tsx": "^3.14.0"
5859
}

pnpm-lock.yaml

Lines changed: 21 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/app/[locale]/page.tsx

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,15 @@
11
import { Inter } from 'next/font/google';
22

33
import SampleForm from '@/components/sample-form';
4+
import serverLogger from '@/lib/axiom/log-server';
45

56
const inter = Inter({ subsets: ['latin'] });
67

78
export default function Page() {
9+
const logger = serverLogger();
10+
11+
logger.info('Hello from server logger!');
12+
813
return (
914
<main
1015
className={`flex h-screen flex-col items-center justify-center gap-8 text-center ${inter.className}`}>

src/components/sample-form.tsx

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import { useForm } from 'react-hook-form';
55
import { useScopedI18n } from '@/i18n/client';
66
import { zodResolver } from '@hookform/resolvers/zod';
77
import { z } from 'zod';
8+
import useClientLogger from '@/lib/axiom/log-client';
89

910
// Always use zod to validate your form
1011
const SampleFormSchema = z
@@ -20,6 +21,7 @@ type SampleFormValues = z.infer<typeof SampleFormSchema>;
2021
// Example form using react-hook-form and zod
2122
const SampleForm = () => {
2223
const t = useScopedI18n('form');
24+
const logger = useClientLogger();
2325

2426
const [submitting, setSubmitting] = useState(false);
2527

@@ -34,7 +36,7 @@ const SampleForm = () => {
3436

3537
const onSubmit = (values: SampleFormValues) => {
3638
// Handle form submission
37-
console.log(values);
39+
logger.info('Form values:', values);
3840
setSubmitting(true);
3941
};
4042

src/lib/axiom/log-client.tsx

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
// eslint-disable-next-line @typescript-eslint/no-restricted-imports
2+
import { useLogger } from 'next-axiom';
3+
4+
// Used by client components to log events
5+
const useClientLogger = () => {
6+
// TODO: add custom data to logs
7+
const logConfig = { todo: 'TODO' };
8+
return useLogger().with(logConfig);
9+
};
10+
11+
export default useClientLogger;

src/lib/axiom/log-server.ts

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
// eslint-disable-next-line @typescript-eslint/no-restricted-imports
2+
import { Logger } from 'next-axiom';
3+
4+
// Used by server actions + server components to log events
5+
const serverLogger = () => {
6+
// TODO: add custom data to logs
7+
const logConfig = { todo: 'TODO' };
8+
return new Logger().with(logConfig);
9+
};
10+
11+
export default serverLogger;

src/middleware.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,5 +14,5 @@ export function middleware(request: NextRequest) {
1414
}
1515

1616
export const config = {
17-
matcher: ['/((?!api|static|.*\\..*|_next|favicon.ico|robots.txt).*)'],
17+
matcher: ['/((?!api|static|.*\\..*|_next|favicon.ico|robots.txt|_axiom).*)'],
1818
};

0 commit comments

Comments
 (0)