Skip to content

Commit 83ce24c

Browse files
authored
Merge pull request #346 from axiomhq/gabriel/env-access-logging
fix(logging): env access in platform.ts
2 parents 7f9e08c + d435838 commit 83ce24c

File tree

10 files changed

+1685
-131
lines changed

10 files changed

+1685
-131
lines changed
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
# Logs
2+
logs
3+
*.log
4+
npm-debug.log*
5+
yarn-debug.log*
6+
yarn-error.log*
7+
pnpm-debug.log*
8+
lerna-debug.log*
9+
10+
node_modules
11+
dist
12+
dist-ssr
13+
*.local
14+
15+
# Editor directories and files
16+
.vscode/*
17+
!.vscode/extensions.json
18+
.idea
19+
.DS_Store
20+
*.suo
21+
*.ntvs*
22+
*.njsproj
23+
*.sln
24+
*.sw?
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
<!doctype html>
2+
<html lang="en">
3+
<head>
4+
<meta charset="UTF-8" />
5+
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
6+
<title>vitevanilla-js</title>
7+
</head>
8+
<body>
9+
<div>Logger demo page, open the console to see the logs.</div>
10+
<script type="module" src="/src/main.js"></script>
11+
</body>
12+
</html>
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
{
2+
"name": "vitevanilla-js",
3+
"private": true,
4+
"version": "0.0.0",
5+
"type": "module",
6+
"scripts": {
7+
"dev": "vite",
8+
"build": "vite build",
9+
"preview": "vite preview"
10+
},
11+
"devDependencies": {
12+
"vite": "^7.1.7"
13+
},
14+
"dependencies": {
15+
"@axiomhq/logging": "workspace:^"
16+
}
17+
}
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
import { Logger, ConsoleTransport } from '@axiomhq/logging';
2+
3+
class CustomTransport {
4+
log(events) {
5+
console.log('CustomTransport', events);
6+
}
7+
}
8+
9+
const logger = new Logger({
10+
transports: [new ConsoleTransport(), new ConsoleTransport({ prettyPrint: true }), new CustomTransport()],
11+
});
12+
13+
logger.info('Hello World!');
14+
logger.warn('Warning!');
15+
logger.error('Error!');
16+
logger.debug('Debug!');

packages/logging/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "@axiomhq/logging",
33
"description": "The official logging package for Axiom",
4-
"version": "0.1.4",
4+
"version": "0.1.5",
55
"author": "Axiom, Inc.",
66
"license": "MIT",
77
"contributors": [

packages/logging/src/default-formatters.ts

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { Formatter, LogEvent } from 'src/logger';
2-
import { environment, isNetlify, isVercel, region } from 'src/platform';
2+
import { environment, getEnv, isNetlify, isVercel, region } from 'src/platform';
33
import { isEdgeRuntime } from 'src/runtime';
44

55
interface BasePlatform {
@@ -44,18 +44,18 @@ export const injectPlatform: Formatter = (logEvent): PlatformLogEvent => {
4444
const vercelLogEvent = logEvent as VercelLogEvent;
4545

4646
vercelLogEvent.vercel = {
47-
environment: process.env.VERCEL_ENV ?? environment,
48-
region: process.env.VERCEL_REGION,
49-
deploymentId: process.env.VERCEL_DEPLOYMENT_ID,
50-
deploymentUrl: process.env.NEXT_PUBLIC_VERCEL_URL,
51-
project: process.env.NEXT_PUBLIC_VERCEL_PROJECT_PRODUCTION_URL,
47+
environment: getEnv('VERCEL_ENV') ?? environment,
48+
region: getEnv('VERCEL_REGION'),
49+
deploymentId: getEnv('VERCEL_DEPLOYMENT_ID'),
50+
deploymentUrl: getEnv('NEXT_PUBLIC_VERCEL_URL'),
51+
project: getEnv('NEXT_PUBLIC_VERCEL_PROJECT_PRODUCTION_URL'),
5252
source: logEvent.source,
5353
};
5454

5555
vercelLogEvent.git = {
56-
commit: process.env.NEXT_PUBLIC_VERCEL_GIT_COMMIT_SHA,
57-
repo: process.env.NEXT_PUBLIC_VERCEL_GIT_REPO_SLUG,
58-
ref: process.env.NEXT_PUBLIC_VERCEL_GIT_COMMIT_REF,
56+
commit: getEnv('NEXT_PUBLIC_VERCEL_GIT_COMMIT_SHA'),
57+
repo: getEnv('NEXT_PUBLIC_VERCEL_GIT_REPO_SLUG'),
58+
ref: getEnv('NEXT_PUBLIC_VERCEL_GIT_COMMIT_REF'),
5959
};
6060

6161
return vercelLogEvent;
@@ -65,12 +65,12 @@ export const injectPlatform: Formatter = (logEvent): PlatformLogEvent => {
6565
const netlifyLogEvent = logEvent as NetlifyLogEvent;
6666
netlifyLogEvent.netlify = {
6767
environment: environment,
68-
region: isEdgeRuntime ? process.env.DENO_REGION : process.env.AWS_REGION,
69-
siteId: process.env.SITE_ID,
70-
buildId: process.env.BUILD_ID,
71-
context: process.env.CONTEXT,
72-
deploymentUrl: process.env.DEPLOYMENT_URL,
73-
deploymentId: isEdgeRuntime ? process.env.DENO_DEPLOYMENT_ID : process.env.NETLIFY_DEPLOYMENT_ID,
68+
region: isEdgeRuntime ? getEnv('DENO_REGION') : getEnv('AWS_REGION'),
69+
siteId: getEnv('SITE_ID'),
70+
buildId: getEnv('BUILD_ID'),
71+
context: getEnv('CONTEXT'),
72+
deploymentUrl: getEnv('DEPLOYMENT_URL'),
73+
deploymentId: isEdgeRuntime ? getEnv('DENO_DEPLOYMENT_ID') : getEnv('NETLIFY_DEPLOYMENT_ID'),
7474
source: logEvent.source,
7575
};
7676

packages/logging/src/platform.ts

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
1-
export const isVercel = process.env.NEXT_PUBLIC_VERCEL || process.env.VERCEL;
2-
export const isNetlify = process.env.NETLIFY == 'true';
1+
export const getEnv = (key: string) => ('process' in globalThis ? globalThis.process.env[key] : undefined);
32

4-
export const environment = process.env.NODE_ENV;
5-
export const region = process.env.REGION || undefined;
3+
export const isVercel = getEnv('NEXT_PUBLIC_VERCEL') || getEnv('VERCEL');
4+
export const isNetlify = getEnv('NETLIFY') == 'true';
5+
6+
export const environment = getEnv('NODE_ENV');
7+
export const region = getEnv('REGION') || undefined;

packages/nextjs/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@axiomhq/nextjs",
3-
"version": "0.1.4",
3+
"version": "0.1.5",
44
"author": "Axiom, Inc.",
55
"license": "MIT",
66
"description": "The official Next.js package for Axiom",

packages/react/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@axiomhq/react",
3-
"version": "0.1.4",
3+
"version": "0.1.5",
44
"description": "The official React package for Axiom",
55
"author": "Axiom, Inc.",
66
"license": "MIT",

0 commit comments

Comments
 (0)