Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix issue with Diagnosticlogger errors logging #955

Merged
merged 3 commits into from
Apr 26, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 5 additions & 7 deletions Bootstrap/DiagnosticLogger.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import * as DataModel from "./DataModel";
import { FileWriter } from "./FileWriter";
import { homedir } from "./Helpers/FileHelpers";
import { APPLICATION_INSIGHTS_SDK_VERSION } from "../Declarations/Constants";
import Util = require("../Library/Util");

export class DiagnosticLogger {
public static readonly DEFAULT_FILE_NAME: string = "application-insights-extension.log";
Expand All @@ -29,10 +30,7 @@ export class DiagnosticLogger {
DiagnosticLogger.DefaultEnvelope.properties.ikey = instrumentationKey;
}

logMessage(message: DataModel.DiagnosticLog | string, cb?: (err: Error) => void) {
if (typeof cb === "function" && this._writer instanceof FileWriter) {
this._writer.callback = cb;
}
logMessage(message: DataModel.DiagnosticLog | string) {
if (typeof message === "string") {
const diagnosticMessage: DataModel.DiagnosticLog = {
...DiagnosticLogger.DefaultEnvelope,
Expand All @@ -50,9 +48,9 @@ export class DiagnosticLogger {
}
}

logError(message: DataModel.DiagnosticLog | string, cb?: (err: Error) => void) {
if (typeof cb === "function" && this._writer instanceof FileWriter) {
this._writer.callback = cb;
logError(message: DataModel.DiagnosticLog | string, err?: Error) {
if (err) {
message += ` ${Util.dumpObj(err)}`;
}
if (typeof message === "string") {
const diagnosticMessage: DataModel.DiagnosticLog = {
Expand Down