Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[feature] logs remote loki #1986

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
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: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,8 @@
"swagger-autogen": "^2.23.7",
"swagger-ui-express": "^5.0.1",
"unzipper": "^0.12.3",
"winston": "^3.14.1"
"winston": "^3.14.1",
"winston-loki": "^6.1.2"
},
"devDependencies": {
"@babel/cli": "^7.24.8",
Expand Down
3 changes: 2 additions & 1 deletion src/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,8 @@ export default {
},
log: {
level: 'silly', // Before open a issue, change level to silly and retry a action
logger: ['console', 'file'],
logger: ['console', 'file', 'loki'],
loki: 'http://localhost:3100',
},
createOptions: {
browserArgs: [
Expand Down
3 changes: 3 additions & 0 deletions src/types/ServerOptions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,9 @@ export interface ServerOptions {
log: {
level: string;
logger: string[];
loki?: {
host: string; // URL do Loki
};
};
createOptions: {
browserArgs: string[];
Expand Down
36 changes: 34 additions & 2 deletions src/util/logger.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
* limitations under the License.
*/
import winston from 'winston';

import LokiTransport from 'winston-loki';
// Use JSON logging for log files
// Here winston.format.errors() just seem to work
// because there is no winston.format.simple()
Expand Down Expand Up @@ -62,5 +62,37 @@
);
}

if (options.logger.includes('loki')) {
logger.add(
new LokiTransport({
host: 'http://localhost:3100',
json: true,
labels: { job: 'wppconnect-server' },
format: winston.format.combine(
winston.format.errors({ stack: true }),
winston.format.timestamp(),
winston.format.printf(({ level, message, timestamp, stack }) => {
if (stack) {
return JSON.stringify({
level: level,
timestamp: timestamp,
message: message,
stack: stack,
job: 'wppconnect-server',
});
}
return JSON.stringify({
level: level,
timestamp: timestamp,
message: message,
job: 'wppconnect-server',
});
})
),
level: log_level,
})
);
}

return logger;
}
}

Check failure on line 98 in src/util/logger.ts

View workflow job for this annotation

GitHub Actions / lint

Insert `⏎`
Loading