uint32_t GetContentSize(nsIRequest* aRequest) { // Use content-length as a size hint for http channels. nsCOMPtr<nsIHttpChannel> httpChannel(do_QueryInterface(aRequest)); if (httpChannel) { nsAutoCString contentLength; nsresult rv = httpChannel->GetResponseHeader(NS_LITERAL_CSTRING("content-length"), contentLength); if (NS_SUCCEEDED(rv)) { return std::max(contentLength.ToInteger(&rv), 0); } } // Use the file size as a size hint for file channels. nsCOMPtr<nsIFileChannel> fileChannel(do_QueryInterface(aRequest)); if (fileChannel) { nsCOMPtr<nsIFile> file; nsresult rv = fileChannel->GetFile(getter_AddRefs(file)); if (NS_SUCCEEDED(rv)) { int64_t filesize; rv = file->GetFileSize(&filesize); if (NS_SUCCEEDED(rv)) { return std::max(SaturateToInt32(filesize), 0); } } } // Fallback - neither http nor file. We'll use dynamic allocation. return 0; }
uint32_t GetContentSize(nsIRequest* aRequest) { nsCOMPtr<nsIChannel> channel(do_QueryInterface(aRequest)); if (channel) { int64_t size; nsresult rv = channel->GetContentLength(&size); if (NS_SUCCEEDED(rv)) { return std::max(SaturateToInt32(size), 0); } } // Use the file size as a size hint for file channels. nsCOMPtr<nsIFileChannel> fileChannel(do_QueryInterface(aRequest)); if (fileChannel) { nsCOMPtr<nsIFile> file; nsresult rv = fileChannel->GetFile(getter_AddRefs(file)); if (NS_SUCCEEDED(rv)) { int64_t filesize; rv = file->GetFileSize(&filesize); if (NS_SUCCEEDED(rv)) { return std::max(SaturateToInt32(filesize), 0); } } } // Fallback - neither http nor file. We'll use dynamic allocation. return 0; }
ofLogger::ofLogger() { // code from Poco LogRotation sample Poco::AutoPtr<Poco::SplitterChannel> splitterChannel(new Poco::SplitterChannel()); Poco::AutoPtr<Poco::Channel> consoleChannel(new Poco::ConsoleChannel()); Poco::AutoPtr<Poco::Channel> fileChannel(new Poco::FileChannel("sample.log")); Poco::AutoPtr<Poco::FileChannel> rotatedFileChannel(new Poco::FileChannel("rotated.log")); rotatedFileChannel->setProperty("rotation", "100"); rotatedFileChannel->setProperty("archive", "timestamp"); splitterChannel->addChannel(consoleChannel); splitterChannel->addChannel(fileChannel); splitterChannel->addChannel(rotatedFileChannel); Poco::AutoPtr<Poco::Formatter> formatter(new Poco::PatternFormatter("%t")); Poco::AutoPtr<Poco::Channel> formattingChannel(new Poco::FormattingChannel(formatter, splitterChannel)); logger = &Poco::Logger::create("Logger", formattingChannel, Poco::Message::PRIO_TRACE); }
SDCLibrary2::SDCLibrary2() : WithLogger(OSELib::Log::BASE), initialized(false) { // set up the librarie's logger Poco::AutoPtr<Poco::ConsoleChannel> consoleChannel(new Poco::ConsoleChannel); Poco::AutoPtr<Poco::SimpleFileChannel> fileChannel(new Poco::SimpleFileChannel); Poco::AutoPtr<Poco::SplitterChannel> splitterChannel(new Poco::SplitterChannel); fileChannel->setProperty("path", "sdclib.log"); fileChannel->setProperty("rotation", "10 M"); splitterChannel->addChannel(consoleChannel); splitterChannel->addChannel(fileChannel); Poco::AutoPtr<Poco::PatternFormatter> patternFormatter(new Poco::PatternFormatter); patternFormatter->setProperty("pattern", "%q %H:%M:%S.%i %s:\n %t"); Poco::AutoPtr<Poco::FormattingChannel> formattingChannel(new Poco::FormattingChannel(patternFormatter, splitterChannel)); getLogger().setChannel(formattingChannel); // default ports chosen regarding to unlikely used ports: // https://en.wikipedia.org/wiki/List_of_TCP_and_UDP_port_numbers }