You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@trafficserver.apache.org by wk...@apache.org on 2023/02/18 07:01:57 UTC
[trafficserver] branch master updated: Use TSDbg in webp_transform plugin (#9439)
This is an automated email from the ASF dual-hosted git repository.
wkaras pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/trafficserver.git
The following commit(s) were added to refs/heads/master by this push:
new 3d8008a1a Use TSDbg in webp_transform plugin (#9439)
3d8008a1a is described below
commit 3d8008a1a7b6de662de18ea70fd572c08663d349
Author: Brian Neradt <br...@gmail.com>
AuthorDate: Sat Feb 18 02:01:49 2023 -0500
Use TSDbg in webp_transform plugin (#9439)
This updates the logging for the webp_transform plugin to use the TSDbg
feature, allowing the more efficient value of 3 for
proxy.config.diags.debug.enabled for the associated plugin's debug tag
(`webp_transform`).
Co-authored-by: Siva Renganathan <si...@verizonmedia.com>
---
.../experimental/webp_transform/ImageTransform.cc | 28 ++++++++++++----------
1 file changed, 16 insertions(+), 12 deletions(-)
diff --git a/plugins/experimental/webp_transform/ImageTransform.cc b/plugins/experimental/webp_transform/ImageTransform.cc
index c74970718..2310e9112 100644
--- a/plugins/experimental/webp_transform/ImageTransform.cc
+++ b/plugins/experimental/webp_transform/ImageTransform.cc
@@ -19,6 +19,9 @@
#include <sstream>
#include <iostream>
#include <string_view>
+
+#include "ts/ts.h"
+
#include "tscpp/api/PluginInit.h"
#include "tscpp/api/GlobalPlugin.h"
#include "tscpp/api/TransformationPlugin.h"
@@ -43,6 +46,8 @@ namespace
{
GlobalPlugin *plugin;
+auto webp_dbg_ctl = TSDbgCtlCreate(TAG);
+
enum class ImageEncoding { webp, jpeg, png, unknown };
bool config_convert_to_webp = false;
@@ -106,11 +111,11 @@ public:
Blob output_blob;
if (_transform_image_type == ImageEncoding::webp) {
stat_convert_to_webp.increment(1);
- TSDebug(TAG, "Transforming jpeg or png to webp");
+ TSDbg(webp_dbg_ctl, "Transforming jpeg or png to webp");
image.magick("WEBP");
} else {
stat_convert_to_jpeg.increment(1);
- TSDebug(TAG, "Transforming webp to jpeg");
+ TSDbg(webp_dbg_ctl, "Transforming webp to jpeg");
image.magick("JPEG");
}
image.write(&output_blob);
@@ -173,23 +178,23 @@ public:
}
}
- TSDebug(TAG, "User-Agent: %s transaction_convert_to_webp: %d transaction_convert_to_jpeg: %d", ctype.c_str(),
- transaction_convert_to_webp, transaction_convert_to_jpeg);
+ TSDbg(webp_dbg_ctl, "Content-Type: %s transaction_convert_to_webp: %d transaction_convert_to_jpeg: %d", ctype.c_str(),
+ transaction_convert_to_webp, transaction_convert_to_jpeg);
// If we might need to convert check to see if what the browser supports
if (transaction_convert_to_webp == true || transaction_convert_to_jpeg == true) {
std::string accept = transaction.getServerRequest().getHeaders().values("Accept");
bool webp_supported = accept.find("image/webp") != std::string::npos;
- TSDebug(TAG, "Accept: %s webp_suppported: %d", accept.c_str(), webp_supported);
+ TSDbg(webp_dbg_ctl, "Accept: %s webp_suppported: %d", accept.c_str(), webp_supported);
if (webp_supported == true && transaction_convert_to_webp == true) {
- TSDebug(TAG, "Content type is either jpeg or png. Converting to webp");
+ TSDbg(webp_dbg_ctl, "Content type is either jpeg or png. Converting to webp");
transaction.addPlugin(new ImageTransform(transaction, input_image_type, ImageEncoding::webp));
} else if (webp_supported == false && transaction_convert_to_jpeg == true) {
- TSDebug(TAG, "Content type is webp. Converting to jpeg");
+ TSDbg(webp_dbg_ctl, "Content type is webp. Converting to jpeg");
transaction.addPlugin(new ImageTransform(transaction, input_image_type, ImageEncoding::jpeg));
} else {
- TSDebug(TAG, "Nothing to convert");
+ TSDbg(webp_dbg_ctl, "Nothing to convert");
}
}
@@ -207,19 +212,18 @@ TSPluginInit(int argc, const char *argv[])
if (argc >= 2) {
std::string option(argv[1]);
if (option.find("convert_to_webp") != std::string::npos) {
- TSDebug(TAG, "Configured to convert to webp");
+ TSDbg(webp_dbg_ctl, "Configured to convert to webp");
config_convert_to_webp = true;
}
if (option.find("convert_to_jpeg") != std::string::npos) {
- TSDebug(TAG, "Configured to convert to jpeg");
+ TSDbg(webp_dbg_ctl, "Configured to convert to jpeg");
config_convert_to_jpeg = true;
}
if (config_convert_to_webp == false && config_convert_to_jpeg == false) {
- TSDebug(TAG, "Unknown option: %s", option.c_str());
TSError("Unknown option: %s", option.c_str());
}
} else {
- TSDebug(TAG, "Default configuration is to convert both webp and jpeg");
+ TSDbg(webp_dbg_ctl, "Default configuration is to convert both webp and jpeg");
config_convert_to_webp = true;
config_convert_to_jpeg = true;
}