Skip to content
This repository has been archived by the owner on Aug 4, 2022. It is now read-only.

Commit

Permalink
Bug 920630 - Part 1. Improve image logging to support direct logging …
Browse files Browse the repository at this point in the history
…of URIs and images objects. r=tnikkel
  • Loading branch information
aosmond committed Jun 6, 2018
1 parent 8138fae commit d2284ff
Show file tree
Hide file tree
Showing 3 changed files with 57 additions and 0 deletions.
55 changes: 55 additions & 0 deletions image/ImageLogging.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@
#define mozilla_image_ImageLogging_h

#include "mozilla/Logging.h"
#include "Image.h"
#include "nsIURI.h"
#include "prinrval.h"

static mozilla::LazyLogModule gImgLog("imgRequest");
Expand Down Expand Up @@ -76,6 +78,35 @@ class LogScope {
paramName, paramValue));
}

/* nsIURI constructor */
LogScope(mozilla::LogModule* aLog, void* from, const char* fn,
const char* paramName, nsIURI* aURI)
: mLog(aLog)
, mFrom(from)
, mFunc(fn)
{
if (MOZ_LOG_TEST(gImgLog, LogLevel::Debug)) {
static const size_t sMaxTruncatedLength = 1024;
nsAutoCString spec("<unknown>");
if (aURI) {
aURI->GetSpec(spec);
if (spec.Length() >= sMaxTruncatedLength) {
spec.Truncate(sMaxTruncatedLength);
}
}
MOZ_LOG(aLog, LogLevel::Debug, ("%d [this=%p] %s (%s=\"%s\") {ENTER}\n",
GIVE_ME_MS_NOW(), from, fn,
paramName, spec.get()));
}
}

/* Image constructor */
LogScope(mozilla::LogModule* aLog, void* from, const char* fn,
const char* paramName, mozilla::image::Image* aImage)
: LogScope(aLog, from, fn, paramName, aImage ? aImage->GetURI() : nullptr)
{
}

~LogScope()
{
MOZ_LOG(mLog, LogLevel::Debug, ("%d [this=%p] %s {EXIT}\n",
Expand Down Expand Up @@ -121,6 +152,30 @@ class LogFunc {
paramName, paramValue));
}

LogFunc(mozilla::LogModule* aLog, void* from, const char* fn,
const char* paramName, nsIURI* aURI)
{
if (MOZ_LOG_TEST(gImgLog, LogLevel::Debug)) {
static const size_t sMaxTruncatedLength = 1024;
nsAutoCString spec("<unknown>");
if (aURI) {
aURI->GetSpec(spec);
if (spec.Length() >= sMaxTruncatedLength) {
spec.Truncate(sMaxTruncatedLength);
}
}
MOZ_LOG(aLog, LogLevel::Debug, ("%d [this=%p] %s (%s=\"%s\")\n",
GIVE_ME_MS_NOW(), from, fn,
paramName, spec.get()));
}
}

LogFunc(mozilla::LogModule* aLog, void* from, const char* fn,
const char* paramName, mozilla::image::Image* aImage)
: LogFunc(aLog, from, fn, paramName, aImage ? aImage->GetURI() : nullptr)
{
}

};


Expand Down
1 change: 1 addition & 0 deletions image/ImageOps.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
#include "ImageMetadata.h"
#include "imgIContainer.h"
#include "mozilla/gfx/2D.h"
#include "nsNetUtil.h" // for NS_NewBufferedInputStream
#include "nsStreamUtils.h"
#include "OrientedImage.h"
#include "SourceBuffer.h"
Expand Down
1 change: 1 addition & 0 deletions image/imgTools.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
#include "imgICache.h"
#include "imgIContainer.h"
#include "imgIEncoder.h"
#include "nsNetUtil.h" // for NS_NewBufferedInputStream
#include "nsStreamUtils.h"
#include "nsStringStream.h"
#include "nsContentUtils.h"
Expand Down

0 comments on commit d2284ff

Please sign in to comment.