Skip to content

Commit a50e58d

Browse files
christiankerlxlz
authored andcommitted
Changed LOG_* macros to prepend function signature
1 parent 45132c9 commit a50e58d

File tree

2 files changed

+49
-41
lines changed

2 files changed

+49
-41
lines changed

examples/protonect/include/libfreenect2/logging.h

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -96,9 +96,17 @@ class LIBFREENECT2_API WithLoggerImpl : public WithLogger
9696

9797
} /* namespace libfreenect2 */
9898

99-
#define LOG_DEBUG (::libfreenect2::LogMessage(logger(), ::libfreenect2::Logger::Debug).stream())
100-
#define LOG_INFO (::libfreenect2::LogMessage(logger(), ::libfreenect2::Logger::Info).stream())
101-
#define LOG_WARNING (::libfreenect2::LogMessage(logger(), ::libfreenect2::Logger::Warning).stream())
102-
#define LOG_ERROR (::libfreenect2::LogMessage(logger(), ::libfreenect2::Logger::Error).stream())
99+
#if defined(__GNUC__) or defined(__clang__)
100+
#define LIBFREENECT2_LOG_SOURCE __PRETTY_FUNCTION__
101+
#elif defined(_MSC_VER)
102+
#define LIBFREENECT2_LOG_SOURCE __FUNCSIG__
103+
#else
104+
#define LIBFREENECT2_LOG_SOURCE ""
105+
#endif
106+
107+
#define LOG_DEBUG (::libfreenect2::LogMessage(logger(), ::libfreenect2::Logger::Debug).stream() << "[" << LIBFREENECT2_LOG_SOURCE << "] ")
108+
#define LOG_INFO (::libfreenect2::LogMessage(logger(), ::libfreenect2::Logger::Info).stream() << "[" << LIBFREENECT2_LOG_SOURCE << "] ")
109+
#define LOG_WARNING (::libfreenect2::LogMessage(logger(), ::libfreenect2::Logger::Warning).stream() << "[" << LIBFREENECT2_LOG_SOURCE << "] ")
110+
#define LOG_ERROR (::libfreenect2::LogMessage(logger(), ::libfreenect2::Logger::Error).stream() << "[" << LIBFREENECT2_LOG_SOURCE << "] ")
103111

104112
#endif /* LOGGING_H_ */

examples/protonect/src/libfreenect2.cpp

Lines changed: 37 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -142,7 +142,7 @@ class Freenect2Impl : public WithLoggerImpl
142142
// TODO: error handling
143143
if(r != 0)
144144
{
145-
LOG_ERROR << "[Freenect2Impl] failed to create usb context!";
145+
LOG_ERROR << "failed to create usb context!";
146146
}
147147
}
148148

@@ -202,7 +202,7 @@ class Freenect2Impl : public WithLoggerImpl
202202
}
203203
else
204204
{
205-
LOG_WARNING << "[Freenect2Impl] tried to remove device, which is not in the internal device list!";
205+
LOG_WARNING << "tried to remove device, which is not in the internal device list!";
206206
}
207207
}
208208

@@ -231,7 +231,7 @@ class Freenect2Impl : public WithLoggerImpl
231231

232232
if(!devices_.empty())
233233
{
234-
LOG_WARNING << "[Freenect2Impl] after deleting all devices the internal device list should be empty!";
234+
LOG_WARNING << "after deleting all devices the internal device list should be empty!";
235235
}
236236
}
237237

@@ -249,11 +249,11 @@ class Freenect2Impl : public WithLoggerImpl
249249

250250
void enumerateDevices()
251251
{
252-
LOG_INFO << "[Freenect2Impl] enumerating devices...";
252+
LOG_INFO << "enumerating devices...";
253253
libusb_device **device_list;
254254
int num_devices = libusb_get_device_list(usb_context_, &device_list);
255255

256-
LOG_INFO << "[Freenect2Impl] " << num_devices << " usb devices connected";
256+
LOG_INFO << num_devices << " usb devices connected";
257257

258258
if(num_devices > 0)
259259
{
@@ -294,21 +294,21 @@ class Freenect2Impl : public WithLoggerImpl
294294
dev_with_serial.dev = dev;
295295
dev_with_serial.serial = std::string(reinterpret_cast<char *>(buffer), size_t(r));
296296

297-
LOG_INFO << "[Freenect2Impl] found valid Kinect v2 " << PrintBusAndDevice(dev) << " with serial " << dev_with_serial.serial;
297+
LOG_INFO << "found valid Kinect v2 " << PrintBusAndDevice(dev) << " with serial " << dev_with_serial.serial;
298298
// valid Kinect v2
299299
enumerated_devices_.push_back(dev_with_serial);
300300
continue;
301301
}
302302
else
303303
{
304-
LOG_ERROR << "[Freenect2Impl] failed to get serial number of Kinect v2 " << PrintBusAndDevice(dev) << "!";
304+
LOG_ERROR << "failed to get serial number of Kinect v2 " << PrintBusAndDevice(dev) << "!";
305305
}
306306

307307
libusb_close(dev_handle);
308308
}
309309
else
310310
{
311-
LOG_ERROR << "[Freenect2Impl] failed to open Kinect v2 " << PrintBusAndDevice(dev) << "!";
311+
LOG_ERROR << "failed to open Kinect v2 " << PrintBusAndDevice(dev) << "!";
312312
}
313313
}
314314
}
@@ -319,7 +319,7 @@ class Freenect2Impl : public WithLoggerImpl
319319
libusb_free_device_list(device_list, 0);
320320
has_device_enumeration_ = true;
321321

322-
LOG_INFO << "[Freenect2Impl] found " << enumerated_devices_.size() << " devices";
322+
LOG_INFO << "found " << enumerated_devices_.size() << " devices";
323323
}
324324

325325
int getNumDevices()
@@ -423,7 +423,7 @@ void Freenect2DeviceImpl::setIrAndDepthFrameListener(libfreenect2::FrameListener
423423

424424
bool Freenect2DeviceImpl::open()
425425
{
426-
LOG_INFO << "[Freenect2DeviceImpl] opening...";
426+
LOG_INFO << "opening...";
427427

428428
if(state_ != Created) return false;
429429

@@ -443,7 +443,7 @@ bool Freenect2DeviceImpl::open()
443443

444444
if(max_iso_packet_size < 0x8400)
445445
{
446-
LOG_ERROR << "[Freenect2DeviceImpl] max iso packet size for endpoint 0x84 too small! (expected: " << 0x8400 << " got: " << max_iso_packet_size << ")";
446+
LOG_ERROR << "max iso packet size for endpoint 0x84 too small! (expected: " << 0x8400 << " got: " << max_iso_packet_size << ")";
447447
return false;
448448
}
449449

@@ -452,14 +452,14 @@ bool Freenect2DeviceImpl::open()
452452

453453
state_ = Open;
454454

455-
LOG_INFO << "[Freenect2DeviceImpl] opened";
455+
LOG_INFO << "opened";
456456

457457
return true;
458458
}
459459

460460
void Freenect2DeviceImpl::start()
461461
{
462-
LOG_INFO << "[Freenect2DeviceImpl] starting...";
462+
LOG_INFO << "starting...";
463463
if(state_ != Open) return;
464464

465465
CommandTransaction::Result serial_result, firmware_result, result;
@@ -471,15 +471,15 @@ void Freenect2DeviceImpl::start()
471471

472472
command_tx_.execute(ReadData0x14Command(nextCommandSeq()), result);
473473
LOG_DEBUG
474-
<< "[Freenect2DeviceImpl] ReadData0x14 response" << std::endl
474+
<< "ReadData0x14 response" << std::endl
475475
<< GenericResponse(result.data, result.length).toString();
476476

477477
command_tx_.execute(ReadSerialNumberCommand(nextCommandSeq()), serial_result);
478478
std::string new_serial = SerialNumberResponse(serial_result.data, serial_result.length).toString();
479479

480480
if(serial_ != new_serial)
481481
{
482-
LOG_WARNING << "[Freenect2DeviceImpl] serial number reported by libusb " << serial_ << " differs from serial number " << new_serial << " in device protocol! ";
482+
LOG_WARNING << "serial number reported by libusb " << serial_ << " differs from serial number " << new_serial << " in device protocol! ";
483483
}
484484

485485
command_tx_.execute(ReadDepthCameraParametersCommand(nextCommandSeq()), result);
@@ -534,7 +534,7 @@ void Freenect2DeviceImpl::start()
534534

535535
command_tx_.execute(ReadStatus0x090000Command(nextCommandSeq()), result);
536536
LOG_DEBUG
537-
<< "[Freenect2DeviceImpl] ReadStatus0x090000 response" << std::endl
537+
<< "ReadStatus0x090000 response" << std::endl
538538
<< GenericResponse(result.data, result.length).toString();
539539

540540
command_tx_.execute(InitStreamsCommand(nextCommandSeq()), result);
@@ -543,7 +543,7 @@ void Freenect2DeviceImpl::start()
543543

544544
command_tx_.execute(ReadStatus0x090000Command(nextCommandSeq()), result);
545545
LOG_DEBUG
546-
<< "[Freenect2DeviceImpl] ReadStatus0x090000 response" << std::endl
546+
<< "ReadStatus0x090000 response" << std::endl
547547
<< GenericResponse(result.data, result.length).toString();
548548

549549
command_tx_.execute(SetStreamEnabledCommand(nextCommandSeq()), result);
@@ -565,33 +565,33 @@ void Freenect2DeviceImpl::start()
565565
command_tx_.execute(ReadData0x26Command(nextCommandSeq()), result);
566566
command_tx_.execute(ReadData0x26Command(nextCommandSeq()), result);
567567
*/
568-
LOG_INFO << "[Freenect2DeviceImpl] enabling usb transfer submission...";
568+
LOG_INFO << "enabling usb transfer submission...";
569569
rgb_transfer_pool_.enableSubmission();
570570
ir_transfer_pool_.enableSubmission();
571571

572-
LOG_INFO << "[Freenect2DeviceImpl] submitting usb transfers...";
572+
LOG_INFO << "submitting usb transfers...";
573573
rgb_transfer_pool_.submit(20);
574574
ir_transfer_pool_.submit(60);
575575

576576
state_ = Streaming;
577-
LOG_INFO << "[Freenect2DeviceImpl] started";
577+
LOG_INFO << "started";
578578
}
579579

580580
void Freenect2DeviceImpl::stop()
581581
{
582-
LOG_INFO << "[Freenect2DeviceImpl] stopping...";
582+
LOG_INFO << "stopping...";
583583

584584
if(state_ != Streaming)
585585
{
586-
LOG_INFO << "[Freenect2DeviceImpl] already stopped, doing nothing";
586+
LOG_INFO << "already stopped, doing nothing";
587587
return;
588588
}
589589

590-
LOG_INFO << "[Freenect2DeviceImpl] disabling usb transfer submission...";
590+
LOG_INFO << "disabling usb transfer submission...";
591591
rgb_transfer_pool_.disableSubmission();
592592
ir_transfer_pool_.disableSubmission();
593593

594-
LOG_INFO << "[Freenect2DeviceImpl] canceling usb transfers...";
594+
LOG_INFO << "canceling usb transfers...";
595595
rgb_transfer_pool_.cancel();
596596
ir_transfer_pool_.cancel();
597597

@@ -604,16 +604,16 @@ void Freenect2DeviceImpl::stop()
604604
usb_control_.setVideoTransferFunctionState(UsbControl::Disabled);
605605

606606
state_ = Open;
607-
LOG_INFO << "[Freenect2DeviceImpl] stopped";
607+
LOG_INFO << "stopped";
608608
}
609609

610610
void Freenect2DeviceImpl::close()
611611
{
612-
LOG_INFO << "[Freenect2DeviceImpl] closing...";
612+
LOG_INFO << "closing...";
613613

614614
if(state_ == Closed)
615615
{
616-
LOG_INFO << "[Freenect2DeviceImpl] already closed, doing nothing";
616+
LOG_INFO << "already closed, doing nothing";
617617
return;
618618
}
619619

@@ -630,24 +630,24 @@ void Freenect2DeviceImpl::close()
630630

631631
if(has_usb_interfaces_)
632632
{
633-
LOG_INFO << "[Freenect2DeviceImpl] releasing usb interfaces...";
633+
LOG_INFO << "releasing usb interfaces...";
634634

635635
usb_control_.releaseInterfaces();
636636
has_usb_interfaces_ = false;
637637
}
638638

639-
LOG_INFO << "[Freenect2DeviceImpl] deallocating usb transfer pools...";
639+
LOG_INFO << "deallocating usb transfer pools...";
640640
rgb_transfer_pool_.deallocate();
641641
ir_transfer_pool_.deallocate();
642642

643-
LOG_INFO << "[Freenect2DeviceImpl] closing usb device...";
643+
LOG_INFO << "closing usb device...";
644644

645645
libusb_close(usb_device_handle_);
646646
usb_device_handle_ = 0;
647647
usb_device_ = 0;
648648

649649
state_ = Closed;
650-
LOG_INFO << "[Freenect2DeviceImpl] closed";
650+
LOG_INFO << "closed";
651651
}
652652

653653
PacketPipeline *createDefaultPacketPipeline()
@@ -716,7 +716,7 @@ Freenect2Device *Freenect2::openDevice(int idx, const PacketPipeline *pipeline,
716716

717717
if(idx >= num_devices)
718718
{
719-
LOG_ERROR << "[Freenect2Impl] requested device " << idx << " is not connected!";
719+
LOG_ERROR << "requested device " << idx << " is not connected!";
720720
delete pipeline;
721721

722722
return device;
@@ -727,7 +727,7 @@ Freenect2Device *Freenect2::openDevice(int idx, const PacketPipeline *pipeline,
727727

728728
if(impl_->tryGetDevice(dev.dev, &device))
729729
{
730-
LOG_WARNING << "[Freenect2Impl] device " << PrintBusAndDevice(dev.dev)
730+
LOG_WARNING << "device " << PrintBusAndDevice(dev.dev)
731731
<< " is already be open!";
732732
delete pipeline;
733733

@@ -738,7 +738,7 @@ Freenect2Device *Freenect2::openDevice(int idx, const PacketPipeline *pipeline,
738738

739739
if(r != LIBUSB_SUCCESS)
740740
{
741-
LOG_ERROR << "[Freenect2Impl] failed to open Kinect v2 " << PrintBusAndDevice(dev.dev) << "!";
741+
LOG_ERROR << "failed to open Kinect v2 " << PrintBusAndDevice(dev.dev) << "!";
742742
delete pipeline;
743743

744744
return device;
@@ -768,7 +768,7 @@ Freenect2Device *Freenect2::openDevice(int idx, const PacketPipeline *pipeline,
768768
libfreenect2::this_thread::sleep_for(libfreenect2::chrono::milliseconds(1000));
769769

770770
// reenumerate devices
771-
LOG_INFO << "[Freenect2Impl] re-enumerating devices after reset";
771+
LOG_INFO << "re-enumerating devices after reset";
772772
impl_->clearDeviceEnumeration();
773773
impl_->enumerateDevices();
774774

@@ -777,7 +777,7 @@ Freenect2Device *Freenect2::openDevice(int idx, const PacketPipeline *pipeline,
777777
}
778778
else if(r != LIBUSB_SUCCESS)
779779
{
780-
LOG_ERROR << "[Freenect2Impl] failed to reset Kinect v2 " << PrintBusAndDevice(dev.dev) << "!";
780+
LOG_ERROR << "failed to reset Kinect v2 " << PrintBusAndDevice(dev.dev) << "!";
781781
delete pipeline;
782782

783783
return device;
@@ -792,7 +792,7 @@ Freenect2Device *Freenect2::openDevice(int idx, const PacketPipeline *pipeline,
792792
delete device;
793793
device = 0;
794794

795-
LOG_ERROR << "[Freenect2DeviceImpl] failed to open Kinect v2 " << PrintBusAndDevice(dev.dev) << "!";
795+
LOG_ERROR << "failed to open Kinect v2 " << PrintBusAndDevice(dev.dev) << "!";
796796
}
797797

798798
return device;

0 commit comments

Comments
 (0)