mirror of
https://github.com/IT4Change/gradido.git
synced 2025-12-13 07:45:54 +00:00
Merge branch 'improve-apollo-logging' of github.com:gradido/gradido into improve-apollo-logging
This commit is contained in:
commit
a921625f4a
3
.gitignore
vendored
3
.gitignore
vendored
@ -1,3 +1,5 @@
|
|||||||
|
.dbeaver
|
||||||
|
.project
|
||||||
*.log
|
*.log
|
||||||
/node_modules/*
|
/node_modules/*
|
||||||
messages.pot
|
messages.pot
|
||||||
@ -11,3 +13,4 @@ package-lock.json
|
|||||||
/deployment/bare_metal/nginx/update-page/updating.html
|
/deployment/bare_metal/nginx/update-page/updating.html
|
||||||
/deployment/bare_metal/log
|
/deployment/bare_metal/log
|
||||||
/deployment/bare_metal/backup
|
/deployment/bare_metal/backup
|
||||||
|
/.nvmrc
|
||||||
|
|||||||
1
admin/.gitignore
vendored
1
admin/.gitignore
vendored
@ -10,3 +10,4 @@ coverage/
|
|||||||
|
|
||||||
# emacs
|
# emacs
|
||||||
*~
|
*~
|
||||||
|
/.nvmrc
|
||||||
|
|||||||
1
backend/.gitignore
vendored
1
backend/.gitignore
vendored
@ -6,3 +6,4 @@ package-json.lock
|
|||||||
coverage
|
coverage
|
||||||
# emacs
|
# emacs
|
||||||
*~
|
*~
|
||||||
|
/.nvmrc
|
||||||
|
|||||||
64
backend/log4js-config.json
Normal file
64
backend/log4js-config.json
Normal file
@ -0,0 +1,64 @@
|
|||||||
|
{
|
||||||
|
"appenders":
|
||||||
|
{
|
||||||
|
"access":
|
||||||
|
{
|
||||||
|
"type": "dateFile",
|
||||||
|
"filename": "../logs/backend/access.log",
|
||||||
|
"pattern": "%d %p %c %f:%l %m%n",
|
||||||
|
"compress" : true,
|
||||||
|
"keepFileExt" : true,
|
||||||
|
"fileNameSep" : "_"
|
||||||
|
},
|
||||||
|
"apollo":
|
||||||
|
{
|
||||||
|
"type": "dateFile",
|
||||||
|
"filename": "../logs/backend/apollo.log",
|
||||||
|
"pattern": "%d %p %c %f:%l %m%n",
|
||||||
|
"compress" : true,
|
||||||
|
"keepFileExt" : true,
|
||||||
|
"fileNameSep" : "_"
|
||||||
|
},
|
||||||
|
"errorFile":
|
||||||
|
{
|
||||||
|
"type": "dateFile",
|
||||||
|
"filename": "../logs/backend/errors.log",
|
||||||
|
"pattern": "%d %p %c %f:%l %m%n",
|
||||||
|
"compress" : true,
|
||||||
|
"keepFileExt" : true,
|
||||||
|
"fileNameSep" : "_"
|
||||||
|
},
|
||||||
|
"errors":
|
||||||
|
{
|
||||||
|
"type": "logLevelFilter",
|
||||||
|
"level": "error",
|
||||||
|
"appender": "errorFile"
|
||||||
|
},
|
||||||
|
"out":
|
||||||
|
{
|
||||||
|
"type": "stdout"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"categories":
|
||||||
|
{
|
||||||
|
"default":
|
||||||
|
{
|
||||||
|
"appenders":
|
||||||
|
[
|
||||||
|
"out",
|
||||||
|
"apollo",
|
||||||
|
"errors"
|
||||||
|
],
|
||||||
|
"level": "all",
|
||||||
|
"enableCallStack": true
|
||||||
|
},
|
||||||
|
"http":
|
||||||
|
{
|
||||||
|
"appenders":
|
||||||
|
[
|
||||||
|
"access"
|
||||||
|
],
|
||||||
|
"level": "info"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -1,10 +1,17 @@
|
|||||||
import axios from 'axios'
|
import axios from 'axios'
|
||||||
|
import log4js from 'log4js'
|
||||||
|
import CONFIG from '@/config'
|
||||||
|
|
||||||
|
log4js.configure(CONFIG.LOG4JS_CONFIG)
|
||||||
|
const logger = log4js.getLogger('http')
|
||||||
|
|
||||||
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
||||||
export const apiPost = async (url: string, payload: unknown): Promise<any> => {
|
export const apiPost = async (url: string, payload: unknown): Promise<any> => {
|
||||||
|
logger.trace('POST: url=' + url + ' payload=' + payload)
|
||||||
return axios
|
return axios
|
||||||
.post(url, payload)
|
.post(url, payload)
|
||||||
.then((result) => {
|
.then((result) => {
|
||||||
|
logger.trace('POST-Response: result=' + result)
|
||||||
if (result.status !== 200) {
|
if (result.status !== 200) {
|
||||||
throw new Error('HTTP Status Error ' + result.status)
|
throw new Error('HTTP Status Error ' + result.status)
|
||||||
}
|
}
|
||||||
@ -20,9 +27,11 @@ export const apiPost = async (url: string, payload: unknown): Promise<any> => {
|
|||||||
|
|
||||||
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
||||||
export const apiGet = async (url: string): Promise<any> => {
|
export const apiGet = async (url: string): Promise<any> => {
|
||||||
|
logger.trace('GET: url=' + url)
|
||||||
return axios
|
return axios
|
||||||
.get(url)
|
.get(url)
|
||||||
.then((result) => {
|
.then((result) => {
|
||||||
|
logger.trace('GET-Response: result=' + result)
|
||||||
if (result.status !== 200) {
|
if (result.status !== 200) {
|
||||||
throw new Error('HTTP Status Error ' + result.status)
|
throw new Error('HTTP Status Error ' + result.status)
|
||||||
}
|
}
|
||||||
|
|||||||
@ -12,6 +12,7 @@ Decimal.set({
|
|||||||
const constants = {
|
const constants = {
|
||||||
DB_VERSION: '0035-admin_pending_creations_decimal',
|
DB_VERSION: '0035-admin_pending_creations_decimal',
|
||||||
DECAY_START_TIME: new Date('2021-05-13 17:46:31'), // GMT+0
|
DECAY_START_TIME: new Date('2021-05-13 17:46:31'), // GMT+0
|
||||||
|
LOG4JS_CONFIG: 'log4js-config.json',
|
||||||
CONFIG_VERSION: {
|
CONFIG_VERSION: {
|
||||||
DEFAULT: 'DEFAULT',
|
DEFAULT: 'DEFAULT',
|
||||||
EXPECTED: 'v6.2022-04-21',
|
EXPECTED: 'v6.2022-04-21',
|
||||||
|
|||||||
@ -1,4 +1,6 @@
|
|||||||
import fs from 'fs'
|
import fs from 'fs'
|
||||||
|
import log4js from 'log4js'
|
||||||
|
|
||||||
import { Context, getUser } from '@/server/context'
|
import { Context, getUser } from '@/server/context'
|
||||||
import { Resolver, Query, Args, Arg, Authorized, Ctx, UseMiddleware, Mutation } from 'type-graphql'
|
import { Resolver, Query, Args, Arg, Authorized, Ctx, UseMiddleware, Mutation } from 'type-graphql'
|
||||||
import { getConnection, getCustomRepository } from '@dbTools/typeorm'
|
import { getConnection, getCustomRepository } from '@dbTools/typeorm'
|
||||||
@ -21,6 +23,10 @@ import { klicktippSignIn } from '@/apis/KlicktippController'
|
|||||||
import { RIGHTS } from '@/auth/RIGHTS'
|
import { RIGHTS } from '@/auth/RIGHTS'
|
||||||
import { hasElopageBuys } from '@/util/hasElopageBuys'
|
import { hasElopageBuys } from '@/util/hasElopageBuys'
|
||||||
|
|
||||||
|
log4js.configure(CONFIG.LOG4JS_CONFIG)
|
||||||
|
const logger = log4js.getLogger('graphql.resolver.UserResolver')
|
||||||
|
|
||||||
|
|
||||||
// eslint-disable-next-line @typescript-eslint/no-var-requires
|
// eslint-disable-next-line @typescript-eslint/no-var-requires
|
||||||
const sodium = require('sodium-native')
|
const sodium = require('sodium-native')
|
||||||
// eslint-disable-next-line @typescript-eslint/no-var-requires
|
// eslint-disable-next-line @typescript-eslint/no-var-requires
|
||||||
@ -217,25 +223,31 @@ export class UserResolver {
|
|||||||
): Promise<User> {
|
): Promise<User> {
|
||||||
email = email.trim().toLowerCase()
|
email = email.trim().toLowerCase()
|
||||||
const dbUser = await DbUser.findOneOrFail({ email }, { withDeleted: true }).catch(() => {
|
const dbUser = await DbUser.findOneOrFail({ email }, { withDeleted: true }).catch(() => {
|
||||||
|
logger.error('User does not exists with this email=' + email)
|
||||||
throw new Error('No user with this credentials')
|
throw new Error('No user with this credentials')
|
||||||
})
|
})
|
||||||
if (dbUser.deletedAt) {
|
if (dbUser.deletedAt) {
|
||||||
|
logger.error('The User was permanently deleted in database. email=' + email)
|
||||||
throw new Error('This user was permanently deleted. Contact support for questions.')
|
throw new Error('This user was permanently deleted. Contact support for questions.')
|
||||||
}
|
}
|
||||||
if (!dbUser.emailChecked) {
|
if (!dbUser.emailChecked) {
|
||||||
|
logger.error('The Users email is not validate yet. email=' + email)
|
||||||
throw new Error('User email not validated')
|
throw new Error('User email not validated')
|
||||||
}
|
}
|
||||||
if (dbUser.password === BigInt(0)) {
|
if (dbUser.password === BigInt(0)) {
|
||||||
|
logger.error('The User has not set a password yet. email=' + email)
|
||||||
// TODO we want to catch this on the frontend and ask the user to check his emails or resend code
|
// TODO we want to catch this on the frontend and ask the user to check his emails or resend code
|
||||||
throw new Error('User has no password set yet')
|
throw new Error('User has no password set yet')
|
||||||
}
|
}
|
||||||
if (!dbUser.pubKey || !dbUser.privKey) {
|
if (!dbUser.pubKey || !dbUser.privKey) {
|
||||||
|
logger.error('The User has no private or publicKey. email=' + email)
|
||||||
// TODO we want to catch this on the frontend and ask the user to check his emails or resend code
|
// TODO we want to catch this on the frontend and ask the user to check his emails or resend code
|
||||||
throw new Error('User has no private or publicKey')
|
throw new Error('User has no private or publicKey')
|
||||||
}
|
}
|
||||||
const passwordHash = SecretKeyCryptographyCreateKey(email, password) // return short and long hash
|
const passwordHash = SecretKeyCryptographyCreateKey(email, password) // return short and long hash
|
||||||
const loginUserPassword = BigInt(dbUser.password.toString())
|
const loginUserPassword = BigInt(dbUser.password.toString())
|
||||||
if (loginUserPassword !== passwordHash[0].readBigUInt64LE()) {
|
if (loginUserPassword !== passwordHash[0].readBigUInt64LE()) {
|
||||||
|
logger.error('The User has no valid credentials. email=' + email)
|
||||||
throw new Error('No user with this credentials')
|
throw new Error('No user with this credentials')
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -29,8 +29,15 @@ import { Connection } from '@dbTools/typeorm'
|
|||||||
|
|
||||||
type ServerDef = { apollo: ApolloServer; app: Express; con: Connection }
|
type ServerDef = { apollo: ApolloServer; app: Express; con: Connection }
|
||||||
|
|
||||||
const logger = log4js.getLogger()
|
log4js.configure(CONFIG.LOG4JS_CONFIG)
|
||||||
logger.level = 'debug'
|
|
||||||
|
const logger = log4js.getLogger('backend')
|
||||||
|
logger.debug('This little thing went to market')
|
||||||
|
logger.info('This little thing stayed at home')
|
||||||
|
logger.error('This little thing had roast beef')
|
||||||
|
logger.fatal('This little thing had none')
|
||||||
|
logger.trace('and this little thing went wee, wee, wee, all the way home.')
|
||||||
|
|
||||||
|
|
||||||
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
||||||
const createServer = async (context: any = serverContext): Promise<ServerDef> => {
|
const createServer = async (context: any = serverContext): Promise<ServerDef> => {
|
||||||
|
|||||||
@ -27,16 +27,14 @@ const setHeadersPlugin = {
|
|||||||
|
|
||||||
const logPlugin = {
|
const logPlugin = {
|
||||||
requestDidStart(requestContext: any) {
|
requestDidStart(requestContext: any) {
|
||||||
const { logger } = requestContext
|
const logger = requestContext.logger
|
||||||
logger.debug(requestContext.request.query)
|
logger.trace('Request:' + JSON.stringify(requestContext.request.variables, null, 2))
|
||||||
logger.debug(JSON.stringify(requestContext.request.variables, null, 2))
|
|
||||||
// logger.log('debug', JSON.stringify(requestContext.request, null, 2))
|
// logger.log('debug', JSON.stringify(requestContext.request, null, 2))
|
||||||
return {
|
return {
|
||||||
willSendResponse(requestContext: any) {
|
willSendResponse(requestContext: any) {
|
||||||
// console.log(requestContext)
|
// console.log(requestContext)
|
||||||
logger.debug(JSON.stringify(requestContext.response.errors, null, 2))
|
logger.trace('Response-Data:' + JSON.stringify(requestContext.response.errors, null, 2))
|
||||||
logger.debug(JSON.stringify(requestContext.response.data, null, 2))
|
logger.trace('Response-Errors:' + JSON.stringify(requestContext.response.data, null, 2))
|
||||||
logger.debug(JSON.stringify(requestContext.context, null, 2))
|
|
||||||
return requestContext
|
return requestContext
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|||||||
1
database/.gitignore
vendored
1
database/.gitignore
vendored
@ -25,3 +25,4 @@ package-lock.json
|
|||||||
coverage/
|
coverage/
|
||||||
|
|
||||||
*~
|
*~
|
||||||
|
/.nvmrc
|
||||||
|
|||||||
1
frontend/.gitignore
vendored
1
frontend/.gitignore
vendored
@ -24,3 +24,4 @@ package-lock.json
|
|||||||
coverage/
|
coverage/
|
||||||
|
|
||||||
*~
|
*~
|
||||||
|
/.nvmrc
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user