Commit 5b295b7d authored by Hugo Beauzée-Luyssen's avatar Hugo Beauzée-Luyssen

Provide file/line/func when logging

parent 2da189c8
......@@ -98,7 +98,7 @@ bool AlbumTrack::destroy()
// Manually remove Files from cache, and let foreign key handling delete them from the DB
auto fs = files();
if ( fs.size() == 0 )
Log::Warning( "No files found for AlbumTrack ", m_id );
LOG_WARN( "No files found for AlbumTrack ", m_id );
for ( auto& f : fs )
{
// Ignore failures to discard from cache, we might want to discard records from
......
......@@ -313,7 +313,7 @@ bool File::addLabel( LabelPtr label )
{
if ( m_id == 0 || label->id() == 0 )
{
Log::Error( "Both file & label need to be inserted in database before being linked together" );
LOG_ERROR( "Both file & label need to be inserted in database before being linked together" );
return false;
}
const char* req = "INSERT INTO LabelFileRelation VALUES(?, ?)";
......@@ -324,7 +324,7 @@ bool File::removeLabel( LabelPtr label )
{
if ( m_id == 0 || label->id() == 0 )
{
Log::Error( "Can't unlink a label/file not inserted in database" );
LOG_ERROR( "Can't unlink a label/file not inserted in database" );
return false;
}
const char* req = "DELETE FROM LabelFileRelation WHERE id_label = ? AND id_file = ?";
......
......@@ -98,7 +98,7 @@ bool MediaLibrary::initialize( const std::string& dbPath, const std::string& sna
m_dbConnection.reset( dbConnection, &sqlite3_close );
if ( sqlite::Tools::executeRequest( DBConnection(m_dbConnection), "PRAGMA foreign_keys = ON" ) == false )
{
Log::Error( "Failed to enable foreign keys" );
LOG_ERROR( "Failed to enable foreign keys" );
return false;
}
if ( ! ( File::createTable( m_dbConnection ) &&
......@@ -112,7 +112,7 @@ bool MediaLibrary::initialize( const std::string& dbPath, const std::string& sna
VideoTrack::createTable( m_dbConnection ) &&
AudioTrack::createTable( m_dbConnection ) ) )
{
Log::Error( "Failed to create database structure" );
LOG_ERROR( "Failed to create database structure" );
return false;
}
return loadFolders();
......@@ -372,7 +372,7 @@ FilePtr MediaLibrary::addFile( const fs::IFile* file, unsigned int folderId )
auto fptr = File::create( m_dbConnection, file, folderId );
if ( fptr == nullptr )
{
Log::Error( "Failed to add file ", file->fullPath(), " to the media library" );
LOG_ERROR( "Failed to add file ", file->fullPath(), " to the media library" );
return nullptr;
}
// Keep in mind that this is queued by the parser thread, there is no waranty about
......
......@@ -197,7 +197,7 @@ class Tools
int res = sqlite3_prepare_v2( dbConnection.get(), req.c_str(), -1, &stmt, NULL );
if ( res != SQLITE_OK )
{
Log::Error( "Failed to execute request: ", req,
LOG_ERROR( "Failed to execute request: ", req,
sqlite3_errmsg( dbConnection.get() ) );
}
return StmtPtr( stmt, &sqlite3_finalize );
......@@ -224,13 +224,13 @@ class Tools
} while ( res == SQLITE_ROW );
if ( res != SQLITE_DONE )
{
Log::Error( "Failed to execute <", req, ">\nInvalid result: ",
#if SQLITE_VERSION_NUMBER >= 3007015
sqlite3_errstr( res )
auto err = sqlite3_errstr( res );
#else
res
auto err = res;
#endif
, ": ", sqlite3_errmsg( dbConnection.get() ) );
LOG_ERROR( "Failed to execute <", req, ">\nInvalid result: ", err,
": ", sqlite3_errmsg( dbConnection.get() ) );
return false;
}
return true;
......
......@@ -89,3 +89,7 @@ private:
static std::unique_ptr<ILogger> s_defaultLogger;
static std::atomic<ILogger*> s_logger;
};
#define LOG_ERROR( ... ) Log::Error( __FILE__, ":", __LINE__, ' ', __func__, __VA_ARGS__ )
#define LOG_WARN( ... ) Log::Warning( __FILE__, ":", __LINE__, ' ', __func__, __VA_ARGS__ )
#define LOG_INFO( ... ) Log::Info( __FILE__, ":", __LINE__, ' ', __func__, __VA_ARGS__ )
......@@ -67,7 +67,7 @@ ServiceStatus VLCMetadataService::handleMediaMeta( FilePtr file, VLC::Media& med
auto tracks = media.tracks();
if ( tracks.size() == 0 )
{
Log::Error( "Failed to fetch tracks" );
LOG_ERROR( "Failed to fetch tracks" );
return StatusFatal;
}
bool isAudio = true;
......@@ -115,14 +115,14 @@ bool VLCMetadataService::parseAudioFile( FilePtr file, VLC::Media& media ) const
album = m_ml->createAlbum( albumTitle );
if ( album == nullptr )
{
Log::Error( "Failed to create/get album" );
LOG_ERROR( "Failed to create/get album" );
return false;
}
auto trackNbStr = media.meta( libvlc_meta_TrackNumber );
if ( trackNbStr.length() == 0 )
{
Log::Error( "Failed to get track id" );
LOG_ERROR( "Failed to get track id" );
return false;
}
auto artwork = media.meta( libvlc_meta_ArtworkURL );
......@@ -132,7 +132,7 @@ bool VLCMetadataService::parseAudioFile( FilePtr file, VLC::Media& media ) const
auto title = media.meta( libvlc_meta_Title );
if ( title.length() == 0 )
{
Log::Error( "Failed to compute track title" );
LOG_ERROR( "Failed to compute track title" );
title = "Unknown track #";
title += trackNbStr;
}
......@@ -140,7 +140,7 @@ bool VLCMetadataService::parseAudioFile( FilePtr file, VLC::Media& media ) const
auto track = album->addTrack( title, trackNb );
if ( track == nullptr )
{
Log::Error( "Failure while creating album track" );
LOG_ERROR( "Failure while creating album track" );
return false;
}
file->setAlbumTrack( track );
......@@ -179,7 +179,7 @@ bool VLCMetadataService::parseVideoFile( FilePtr file, VLC::Media& media ) const
int episodeId = std::stoi( episodeIdStr, &endpos );
if ( endpos != episodeIdStr.length() )
{
Log::Error( "Invalid episode id provided" );
LOG_ERROR( "Invalid episode id provided" );
return true;
}
show->addEpisode( title, episodeId );
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment