Skip to content
Draft
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
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@
"react-native-dropdown-select-list": "^2.0.4",
"react-native-gesture-handler": "~2.9.0",
"react-native-imaged-card-view": "^0.0.11",
"react-native-logs": "^5.0.1",
"react-native-maps": "1.3.2",
"react-native-modal": "^13.0.1",
"react-native-modal-datetime-picker": "^14.0.1",
Expand Down
15 changes: 8 additions & 7 deletions src/api/HttpClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import { PolimiToken, PoliNetworkToken, Tokens } from "contexts/login"
import AsyncStorage from "@react-native-async-storage/async-storage"
import { wait } from "utils/functions"
import { Alert } from "react-native"
import { httpClientLog } from "utils/logger"

/*Docs used to make this:
Singleton:
Expand Down Expand Up @@ -130,7 +131,7 @@ export class HttpClient extends EventEmitter {

private constructor(baseUrlPoliNetwork: string, baseUrlPolimi: string) {
super()
console.log("HttpClient constructor called")
httpClientLog.debug("HttpClient constructor called")
this.poliNetworkInstance = axios.create({
baseURL: baseUrlPoliNetwork,
timeout: 30000,
Expand Down Expand Up @@ -226,11 +227,11 @@ export class HttpClient extends EventEmitter {
if (success) {
return instance(config)
} else {
console.warn("Error: could not refresh Polimi token")
console.warn("Error:")
console.warn(error)
console.warn("Call config:")
console.warn(JSON.stringify(config))
httpClientLog.error("Error: could not refresh Polimi token")
httpClientLog.error("Error:")
httpClientLog.error(error)
httpClientLog.error("Call config:")
httpClientLog.error(JSON.stringify(config))
Alert.alert(
"An error has occurred while refreshing Polimi token",
`The call to ${
Expand Down Expand Up @@ -425,7 +426,7 @@ export class HttpClient extends EventEmitter {
this.emit("login")
this.emit("login_event", true)
} else {
console.log("No tokens found in local storage")
httpClientLog.info("No tokens found in local storage")
}
}
/**
Expand Down
37 changes: 37 additions & 0 deletions src/utils/logger.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
import { consoleTransport, logger } from "react-native-logs"

const config = {
levels: {
debug: 0,
info: 1,
warn: 2,
error: 3,
},
severity: "debug",
transport: consoleTransport,
transportOptions: {
colors: {
info: "blueBright",
warn: "yellowBright",
error: "redBright",
},
enabledExtensions: ["root", "httpClient"],
extensionColors: {
root: "magenta",
httpClient: "cyan",
// ...
},
},
async: true,
dateFormat: "time",
printLevel: true,
printDate: true,
enabled: true,
}

export const log = logger.createLogger<"debug" | "info" | "warn" | "error">(
config
)
export const rootLog = log.extend("root")
export const httpClientLog = log.extend("httpClient")
// add any needed custom log...
1 change: 0 additions & 1 deletion tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
"api": ["src/api"],
"api/*": ["src/api/*"],
"notifications/*": ["src/notifications/*"]

},
"forceConsistentCasingInFileNames": true
}
Expand Down
5 changes: 5 additions & 0 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -8879,6 +8879,11 @@ react-native-imaged-card-view@^0.0.11:
resolved "https://registry.yarnpkg.com/react-native-imaged-card-view/-/react-native-imaged-card-view-0.0.11.tgz#c1912ab00c4e07ab2c0a56801f930374f484cc20"
integrity sha512-xVvI0mWP1SR+J61P5X649eDZXunCXtSMZ+GkGsY03vEPofnfah8q3Am2NDX9KcO6SzdNtxRJeLmDogyfj63ReQ==

react-native-logs@^5.0.1:
version "5.0.1"
resolved "https://registry.yarnpkg.com/react-native-logs/-/react-native-logs-5.0.1.tgz#53665919587b499e22f514e50cb6a834cedba1ce"
integrity sha512-30aQugeLFfcBEKd6U4I75SKc5q5fb9Qrwv0Vnsy3jwpC716xON9SxRbBEnxoPSDJjzK527r4zi+qYqzig6lPlQ==

react-native-maps@1.3.2:
version "1.3.2"
resolved "https://registry.yarnpkg.com/react-native-maps/-/react-native-maps-1.3.2.tgz#8e30bfd9d934de02827253e5cde6c08a04f6356c"
Expand Down