Skip to content

Commit

Permalink
chore: add momento logger example (#1024)
Browse files Browse the repository at this point in the history
* fix lint errors

* chore: add comment to example
  • Loading branch information
anitarua authored Nov 9, 2023
1 parent c7a4b2e commit 0c7a566
Showing 1 changed file with 22 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,13 @@
* a second file in the future if desired.
*
*/
import {CacheClient, Configurations, CredentialProvider} from '@gomomento/sdk';
import {
CacheClient,
Configurations,
CredentialProvider,
DefaultMomentoLoggerFactory,
DefaultMomentoLoggerLevel,
} from '@gomomento/sdk';
import {ExampleMetricMiddleware} from '../example-metric-middleware';

function example_API_InstantiateCacheClientWithMiddleware() {
Expand All @@ -21,8 +27,23 @@ function example_API_InstantiateCacheClientWithMiddleware() {
});
}

function example_observability_CreateLoggerFactory() {
// Setting the level to ERROR means you will see error messages but
// no trace, info, debug, or warning messages.
const errorLoggerFactory = new DefaultMomentoLoggerFactory(DefaultMomentoLoggerLevel.ERROR);
const errorLogger = errorLoggerFactory.getLogger('momento-error-logger');
errorLogger.error('error in the code!');

// Setting the level to DEBUG means you will see error, info, debug,
// and warning messages but no trace messages.
const debugLoggerFactory = new DefaultMomentoLoggerFactory(DefaultMomentoLoggerLevel.DEBUG);
const debugLogger = debugLoggerFactory.getLogger('momento-debug-logger');
debugLogger.debug('helpful debugging message');
}

function main() {
example_API_InstantiateCacheClientWithMiddleware();
example_observability_CreateLoggerFactory();
}

main();

0 comments on commit 0c7a566

Please sign in to comment.