Controlling logging in Avo Codegen

2 minute read

Custom loggers are currently only supported in Swift, JavaScript and TypeScript. Reach out to us if you want access to custom loggers in your programming languages.

To get fine control over the logs you can provide a custom logger to Avo Codegen.

Notice the returned boolean, if you return true Avo Codegen won't print the built-in logs.

Swift

Swift
Copy
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
class MyAvoLogger : AvoLogger {
func logDebug(env: AvoEnv, message: String) -> Bool {
NSLog("[debug] My avo logger: " + String(describing: env) + " " + message)
return true
}
func logWarn(env: AvoEnv, message: String) -> Bool {
NSLog("[warn] My avo logger: " + String(describing: env) + " " + message)
return false
}
func logError(env: AvoEnv, message: String) -> Bool {
NSLog("[error] My avo logger: " + String(describing: env) + " " + message)
return false
}
}
Avo.initAvo(...)
Avo.avoLogger = MyAvoLogger()

JavaScript

JavaScript
Copy
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
const avoLogger = {
logDebug: (env, message) => {
console.log("Avo Custom Logger Here!", message, env)
return true
},
logWarn: (env, message) => {
console.log("Avo Custom Logger Here!", message, env)
return true
},
logError: (env, message) => {
console.log("Avo Custom Logger Here!", message, env)
return true
}
};
Avo.initAvo(
{ env: env.DEV, ..., avoLogger: avoLogger },
...
);

TypeScript

TypeScript
Copy
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
const avoLogger = {
logDebug: (env: AvoEnv, message: string): boolean => {
console.log("Avo Custom Logger Here!", message, env)
return true
},
logWarn: (env: AvoEnv, message: string): boolean => {
console.log("Avo Custom Logger Here!", message, env)
return true
},
logError: (env: AvoEnv, message: string): boolean => {
console.log("Avo Custom Logger Here!", message, env)
return true
}
};
Avo.initAvo(
{ env: env.DEV, ..., avoLogger: avoLogger },
...
);