Coding Spirit

一位程序员,比较帅的那种

We can construct a Map<String, Object> from a JSON string with the help of reflect:

1
2
3
4
5
6
import com.google.gson.Gson;
import com.google.gson.reflect.TypeToken;

var mapType = new TypeToken<Map<String, Object>>() {
}.getType();
Map<String, Object> myMap = new Gson().fromJson(jsonString, mapType);

Log to local Python interpreter when test locally

1
2
3
logging.basicConfig(level=logging.INFO)
logger = logging.getLogger()
logger.info('some log)

But this will not log to Cloud Watch when test on the cloud.

Log to Cloud Watch

AWS Lambda Python runtime has pre-configured log handlers. To log to Cloud Watch:

1
2
3
logger = logging.getLogger()
logger.setLevel(logging.INFO)
logger.info('some log)

But this will not log to local Python interpreter when test locally.

Log to both Cloud Watch and local

1
2
3
4
5
6
# If there is no pre-configured log handler, we set basicConfig
if not logging.getLogger().hasHandlers():
logging.basicConfig(level=logging.INFO)

logger = logging.getLogger()
logger.setLevel(logging.INFO)
0%