Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .github/workflows/autour-handler.yml
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,9 @@ jobs:
- name: Copy schemas
working-directory: ./handlers/autour-handler
run: cp -R ../../schemas src/
- name: Copy config
working-directory: ./handlers/autour-handler
run: cp -R ../../config src/
- name: Install dependencies
working-directory: ./handlers/autour-handler
run: npm ci
Expand Down
3 changes: 3 additions & 0 deletions .github/workflows/high-charts-handler.yml
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,9 @@ jobs:
- name: Copy schemas
working-directory: ./handlers/high-charts
run: cp -R ../../schemas src/
- name: Copy config
working-directory: ./handlers/high-charts
run: cp -R ../../config src/
- name: Install dependencies
working-directory: ./handlers/high-charts
run: npm ci
Expand Down
3 changes: 3 additions & 0 deletions .github/workflows/motd.yml
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,9 @@ jobs:
- name: Copy schemas
working-directory: ./handlers/motd
run: cp -R ../../schemas src/
- name: Copy config
working-directory: ./handlers/motd
run: cp -R ../../config src/
- name: Install dependencies
working-directory: ./handlers/motd
run: npm ci
Expand Down
3 changes: 3 additions & 0 deletions .github/workflows/nominatim-preprocessor.yml
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,9 @@ jobs:
- name: Copy schemas
working-directory: ./preprocessors/nominatim
run: cp -R ../../schemas src/
- name: Copy config
working-directory: ./preprocessors/nominatim
run: cp -R ../../config src/
- name: Install dependencies
working-directory: ./preprocessors/nominatim
run: npm ci
Expand Down
3 changes: 3 additions & 0 deletions .github/workflows/osm-streets-handler.yml
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,9 @@ jobs:
- name: Copy schemas
working-directory: ./handlers/osm-streets-handler
run: cp -R ../../schemas src/
- name: Copy config
working-directory: ./handlers/osm-streets-handler
run: cp -R ../../config src/
- name: Install dependencies
working-directory: ./handlers/osm-streets-handler
run: npm ci
Expand Down
3 changes: 3 additions & 0 deletions .github/workflows/photo-audio-handler.yml
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,9 @@ jobs:
- name: Copy schemas
working-directory: ./handlers/photo-audio-handler
run: cp -R ../../schemas src/
- name: Copy config
working-directory: ./handlers/photo-audio-handler
run: cp -R ../../config src/
- name: Install dependencies
working-directory: ./handlers/photo-audio-handler
run: npm ci
Expand Down
3 changes: 3 additions & 0 deletions .github/workflows/photo-audio-haptics-handler.yml
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,9 @@ jobs:
- name: Copy schemas
working-directory: ./handlers/photo-audio-haptics-handler
run: cp -R ../../schemas src/
- name: Copy config
working-directory: ./handlers/photo-audio-haptics-handler
run: cp -R ../../config src/
- name: Install dependencies
working-directory: ./handlers/photo-audio-haptics-handler
run: npm ci
Expand Down
2 changes: 2 additions & 0 deletions config/init.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# /app/config/__init__.py
# This file marks the config directory as a Python package.
34 changes: 34 additions & 0 deletions config/logging_utils.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
import logging
import os

# Define a PII log level
PII_LOG_LEVEL = 5
logging.addLevelName(PII_LOG_LEVEL, "PII")


def pii(self, message, *args, **kwargs):
if self.isEnabledFor(PII_LOG_LEVEL):
self._log(PII_LOG_LEVEL, message, args, **kwargs)


logging.Logger.pii = pii
logging.pii = lambda msg, *args, **kwargs: logging.log(
PII_LOG_LEVEL, msg, *args, **kwargs)


def configure_logging():
"""
Configures logging based on environment variables.
"""
log_level = os.getenv("LOG_LEVEL", "INFO").upper()
pii_logging_enabled = os.getenv("PII_LOGGING_ENABLED",
"false").lower() == "true"

level = getattr(logging, log_level, logging.INFO)
logging.basicConfig(level=level)

if pii_logging_enabled:
logging.warning("Environment Unicorn: PII logging enabled!")
logging.getLogger().setLevel(PII_LOG_LEVEL) # Lower log level to PII
else:
logging.info("Environment Pegasus: PII logging is disabled.")
47 changes: 47 additions & 0 deletions config/logging_utils.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
// https://medium.com/@jaiprajapati3/masking-of-sensitive-data-in-logs-700850e233f5
// https://github.com/winstonjs/winston/blob/c69cdb0cec15a138e0b6e374501e027d1c39606c/index.d.ts

import winston, { LogMethod, LogEntry } from 'winston';
const logger = winston.createLogger({
level: 'info',
format: winston.format.json(),
transports: [
new winston.transports.Console({
format: winston.format.simple(),
}),
],
});

interface PIILogger extends LogMethod {
pii: (message: string) => void;
}

const piiLoggingEnabled = process.env.PII_LOGGING_ENABLED === 'true';

if (piiLoggingEnabled) {
logger.warn("Environment Unicorn: PII logging enabled!");
} else {
logger.info("Environment Pegasus: PII logging is disabled.");
}

// PII Logger Function
const piiLogger: PIILogger = ((arg1: string | LogEntry, arg2?: any) => {
if (typeof arg1 === 'string' && arg2 !== undefined) { // log when both level and message are provided
logger.log(arg1, arg2);
} else if (typeof arg1 === 'object') { // log when an object is provided
logger.log(arg1);
} else {
throw new Error('Invalid log format');
}
}) as PIILogger;

// Function for logging PII-related errors
piiLogger.pii = (message: string) => {
if (piiLoggingEnabled) {
logger.error(`[PII] ${message}`);
} else {
logger.debug("PII logging attempted but is DISABLED.");
}
};

export { piiLogger };
Loading
Loading