guint rotation_size;
guint rotation_rotate;
gboolean compress;
+
+ gchar *filename;
};
G_DEFINE_TYPE (SolipaLog, solipa_log, G_TYPE_OBJECT)
priv->file = NULL;
priv->stream = NULL;
+
+ priv->filename = g_strdup ("log.log");
}
/**
SolipaLogPrivate *priv = SOLIPA_LOG_GET_PRIVATE (solipalog);
- priv->file = g_file_new_for_path (g_build_filename (priv->dir, "log.log", NULL));
+ priv->file = g_file_new_for_path (g_build_filename (priv->dir, priv->filename, NULL));
error = NULL;
priv->stream = g_file_append_to (priv->file,
g_free (buf);
/* controllo se deve essere ruotato */
+ error = NULL;
finfo = g_file_query_info (priv->file,
G_FILE_ATTRIBUTE_STANDARD_SIZE,
G_FILE_QUERY_INFO_NONE,
NULL,
- NULL);
- if (finfo != NULL)
+ &error);
+ if (finfo != NULL && error == NULL)
{
size = g_file_info_get_size (finfo);
if (size > priv->rotation_size)
{
+ if (priv->rotation_rotate > 0)
+ {
GFile *fold;
- fold = g_file_new_for_path (g_build_filename (g_file_get_path (g_file_get_parent (priv->file)), "log.log.0", NULL));
+ fold = g_file_new_for_path (g_build_filename (g_file_get_path (g_file_get_parent (priv->file)), g_strdup_printf ("%s.0", priv->filename), NULL));
g_file_delete (fold, NULL, NULL);
g_object_unref (fold);
g_output_stream_close (G_OUTPUT_STREAM (priv->stream), NULL, NULL);
- fold = g_file_set_display_name (priv->file, "log.log.0", NULL, NULL);
+ fold = g_file_set_display_name (priv->file, g_strdup_printf ("%s.0", priv->filename), NULL, NULL);
g_object_unref (priv->file);
priv->file = g_object_ref (fold);
g_object_unref (fold);
if (istream == NULL || error != NULL)
{
g_warning ("Impossibile leggere dal file %s: %s.",
- "log.log.0",
+ g_strdup_printf ("%s.0", priv->filename),
error != NULL && error->message != NULL ? error->message : "nessun dettaglio");
}
error != NULL && error->message != NULL ? error->message : "nessun dettaglio");
}
- fout = g_file_new_for_path (g_build_filename (g_file_get_path (g_file_get_parent (priv->file)), "log.log.0.gz", NULL));
+ fout = g_file_new_for_path (g_build_filename (g_file_get_path (g_file_get_parent (priv->file)), g_strdup_printf ("%s.0.gz", priv->filename), NULL));
error = NULL;
ostream = g_file_replace (fout,
NULL,
}
g_object_unref (priv->file);
+ }
+ else
+ {
+ /* semplicemente lo elimino e ricreo */
+ g_file_delete (priv->file, NULL, NULL);
+ g_object_unref (priv->file);
+ }
if (!solipa_log_create_file (solipa_log))
{
}
g_object_unref (finfo);
}
+ else
+ {
+ g_warning ("Impossibile ottenere le informazioni sul file di log: %s.",
+ error != NULL && error->message != NULL ? error->message : "nessun dettaglio");
+ }
}